| View previous topic :: View next topic |
| Author |
Message |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Mon Jun 14, 2004 9:56 pm Post subject: Using COM for OOo with different languages |
|
|
Over the last days I gathered some information about how OpenOffice.org can be accessed from various languages. The inital drive came from a question on the Python Win32 mailinglist asking where to find documentation about making use of COM for OOo, not via it's own component model called UNO, but via the Automation Interface.
Although COM (=Component Object Model) is a cross-platform technology, to my knowledge it's only useable with MS Windows, so in order to get the following code examples to work your OS should be Windows (I didn't test the different Windows versions yet, but in principle at least all versions from Win98SE on should work).
More information about COM can be found on http://www.msdn.com where the whole concept COM - COM is a low-level binary API - is described.
ActiveX and OLE (=Object Linking and Embedding) are parts of the Automation technology for Windows, although OLE is the original (was developed before COM), COM itself is rather seen as the platform with OLE inheriting from it and ActiveX controls referring to the third part of OLE controls (.ocx). As you can see there is no big difference between the three of them, and as it gets more and more complicated trying to make small differences clear, I will let it be as it is and just say: COM, OLE and ActiveX are pretty much the same.
Please note that there are several improved versions, when someone today refers to COM on Windows 2000 or XP then he actually talks about COM+ and if OLE is named its successor OLE 2 is most often meant, for example the official name for the bridge you use is the OLE2 bridge.
Though you'll probably hear ActiveX more often in relation to Internet sites.
That's because ActiveX controls can support the OLE embedding interfaces, and thus can be included in web pages. You can find a working example in the SDK under OLE Examples.
More information about Automation in OpenOffice.org under..
http://api.openoffice.org/docs/DevelopersGuide/ProfUNO/ProfUNO.htm#1+4+4+Automation+Bridge and http://udk.openoffice.org/common/man/tutorial/office_automation.html
COM's general purpose is to provide cross-software communication, which means any registered COM application can be accessed from 'outside' with possibly any common programming language. registered server clsids can be found in the windows registry, along with the ids for ActiveX controls.
In the overall picture COM/ActiveX/OLE support the more general description IPC ("Inter Process Communication") within one machine or over a network, which in elder days of Windows was also achieved under the DDE technology.
COM technology is in the progress of getting melted with Microsoft's .NET, that means COM will not die by any means, .NET simply wraps its secure and managed code around it. In .NET terminology dealing with COM and Win32API is considered as dealing with unmanaged code.
The following list of code snippets shows how to make use of these windows technologies from many different programming languages.
Note that there are two ways of using a COM object.
Way 1 is with early-binding which is much faster:
You import the specific .tlb .olb or .dll and can thus make use of the functions in it without the need of the slower so called late-binding way.
This second way is the one I will be using, cause for early-binding you need specific tools, that are not standard in every language.
As the Developer's Guide states there is no way to use early-binding for the OOo COM object, furtheron the IDispatch::GetTypeInfo call will return no type information at all.
The reason why I thought such a list might be useful is to give people that know a certain programming language (that might or might not be supported by OOo's UNO) a quick startup on how OpenOffice can be used programmatically from 'outside'.
If you look at the examples you'll see that they share very much in common, that's due to the fact that once you have the Progid = "com.sun.star.ServiceManager(.1)", which is the root for any OpenOffice use, the calls are all very much the same, methods and properties are just as if you would write macros with Starbasic, cause one is bound to use/query UNO interfaces to see action taking place. Type-mapping and marshaling is done by UNO and OOo's Automation interface communicating with each other, in fact both use the same object types.
Also note that this list is far from complete yet and although I tested most of these examples I cannot guarantee that every example might work for you.
If something doesn't work or you get an exception somewhere please let me know and besides that if you have anything to add or you even have got an example in a language not yet listed (and there are quite some!), then feel totally free to add them, people will probably be happy when finding direct matches.
This list will hopefully be increased, at least by me when I find some more time for it again.
Structure:
A OpenOffice.org as Server
A1: Visual Basic
A2: C (verified both with Visual Studio and gcc)
A3: C++ (only short version given, see SDK for full example)
A4: C# (.NET Framework needed)
A5: Python (win32 package by Mark Hammond required)
A6: ActiveState Perl
A7: Ruby
A8: TCL
A9: Delphi
A10: PHP
.. more languages might follow
B OpenOffice.org as Client
B1: StarBasic (Microsoft Word is required for this example)
B2: StarBasic (Microsoft Internet Explorer is required for this example)
.. more languages might follow
A1 Visual Basic:
| Code: |
Dim objServiceManager As Object
Dim objDesktop As Object
Dim args()
Set objServiceManager= CreateObject("com.sun.star.ServiceManager")
Set Stardesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")
Set doc = Stardesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
Set text = doc.getText()
text.setString("Hello World")
REM You can get the full example in the SDK (under OLE examples)
REM Read the Automation Bridge part of the Developer's Guide for writing code with WSH or JScript, both are very similiar to VBScript
|
~~~~~~~~~
~~~~~~~~~
A2 C:
| Code: |
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <ole2.h>
HRESULT AutoWrap(int aType, VARIANT *Res, IDispatch *pDisp, LPOLESTR ptName, int cArgs, ...);
void GetDesktop(IDispatch *pOOoApp, VARIANT *result);
/* Get CLSID for our server... */
CLSID clsid;
HRESULT hr;
int main(int argc, char* argv[])
{
IDispatch *pobjServiceManager;
IDispatch *pStardesktop;
IDispatch *pDoc;
IDispatch *pText;
VARIANT resultDesktop;
VARIANT resultDoc;
VARIANT parm[4];
VARIANT resultText;
VARIANT sStr;
/* Initialize COM for this thread... */
CoInitialize(NULL);
hr = CLSIDFromProgID(L"com.sun.star.ServiceManager", &clsid);
if(FAILED(hr))
{
MessageBox(NULL, "CLSIDFromProgID() failed", "Error", 0x10010);
return -1;
}
/********************************************/
/* Start server and get IDispatch... */
hr = CoCreateInstance(&clsid, NULL, CLSCTX_LOCAL_SERVER, &IID_IDispatch, (void **)&pobjServiceManager);
if(FAILED(hr))
{
MessageBox(NULL, "OpenOffice not registered properly", "Error", 0x10010);
return -2;
}
/********************************************/
/* Get Desktop and its assoc. IDispatch... */
VariantInit(&resultDesktop);
GetDesktop(pobjServiceManager, &resultDesktop);
pStardesktop = resultDesktop.pdispVal;
/********************************************/
/* Attempt to open new document... */
VariantInit(&resultDoc);
VariantInit(&parm[0]);
parm[0].vt = VT_BSTR;
parm[0].bstrVal = SysAllocString(L"private:factory/swriter");
VariantInit(&parm[1]);
parm[1].vt = VT_BSTR;
parm[1].bstrVal = SysAllocString(L"_blank");
VariantInit(&parm[2]);
parm[2].vt = VT_I4;
parm[2].lVal = 0;
VariantInit(&parm[3]);
parm[3].vt = VT_ARRAY | VT_VARIANT;
parm[3].parray = parm[3].parray = NULL; /* looks ugly :( */
AutoWrap(DISPATCH_METHOD, &resultDoc, pStardesktop, L"loadComponentFromURL", 4, parm[3], parm[2], parm[1], parm[0]);
pDoc = resultDoc.pdispVal;
/********************************************/
/* get Text Interface.... */
VariantInit(&resultText);
AutoWrap(DISPATCH_METHOD, &resultText, pDoc, L"getText", 0);
pText = resultText.pdispVal;
/*******************************************/
/* write into the text-document.... */
VariantInit(&sStr);
sStr.vt = VT_BSTR;
sStr.bstrVal = SysAllocString(L"Hello World");
AutoWrap(DISPATCH_METHOD, NULL, pText, L"setString", 1, sStr);
/* Uninitialize COM for this thread... */
CoUninitialize();
return 0;
}
/*
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~
*/
HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp, LPOLESTR ptName, int cArgs, ...)
{
/* Variables used... */
va_list marker;
DISPPARAMS dp = { NULL, NULL, 0, 0 };
DISPID dispidNamed = DISPID_PROPERTYPUT;
DISPID dispID;
HRESULT hr;
char buf[200];
char szName[200];
/* Allocate memory for arguments, should be on the safe-side with mul 100 */
VARIANT *pArgs = (VARIANT *)malloc(sizeof(VARIANT) * 100);
int i = 0;
va_start(marker, cArgs);
if(!pDisp)
{
MessageBox(NULL, "NULL IDispatch passed to AutoWrap()", "Error", 0x10010);
_exit(0);
}
/* Convert down to ANSI */
WideCharToMultiByte(CP_ACP, 0, ptName, -1, szName, 256, NULL, NULL);
/* Get DISPID for name passed... */
pDisp->lpVtbl->GetIDsOfNames(pDisp, &IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID);
/* Extract arguments... */
for(i=0; i<cArgs; i++)
{
pArgs[i] = va_arg(marker, VARIANT);
}
/* Build DISPPARAMS */
dp.cArgs = cArgs;
dp.rgvarg = pArgs;
/* Handle special-case for property-puts! */
if(autoType & DISPATCH_PROPERTYPUT)
{
dp.cNamedArgs = 1;
dp.rgdispidNamedArgs = &dispidNamed;
}
/* Make the call! */
hr = pDisp->lpVtbl->Invoke(pDisp, dispID, &IID_NULL, LOCALE_SYSTEM_DEFAULT, autoType, &dp, pvResult, NULL, NULL);
if(FAILED(hr))
{
sprintf(buf, "IDispatch::Invoke(\"%s\"=%08lx) failed w/err 0x%08lx", szName, dispID, hr);
MessageBox(NULL, buf, "AutoWrap()", 0x10010);
_exit(0);
return hr;
}
/* End variable-argument section... */
va_end(marker);
free(pArgs);
return hr;
}
/*
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~
*/
void GetDesktop(IDispatch *pOOo, VARIANT *result)
{
VARIANT param1;
VariantInit(¶m1);
param1.vt = VT_BSTR;
param1.bstrVal = SysAllocString( L"com.sun.star.frame.Desktop");
AutoWrap(DISPATCH_METHOD, result, pOOo, L"createInstance", 1, param1);
}
|
~~~~~~~~~
~~~~~~~~~
A3 C++:
| Code: |
IDispatch* pdispFactory= NULL;
CLSID clsFactory= {0x82154420,0x0FBF,0x11d4,{0x83, 0x13,0x00,0x50,0x04,0x52,0x6A,0xB4}};
hr = CoCreateInstance( clsFactory, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&pdispFactory);
//...
//For a complete example please look into the OOo SDK 1.1.1 or see http://www.oooforum.org/forum/viewtopic.php?p=41408
|
~~~~~~~~~
~~~~~~~~~
A4 C#:
| Code: |
using System;
using System.Reflection;
class OpenOffice // OpenOffice.org application
{
public static int Main()
{
Type t_OOo;
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager");
Object objServiceManager;
objServiceManager = System.Activator.CreateInstance(t_OOo);
// arguments for IDispatch-call
Object[] parameters = new Object[1];
parameters[0] = "com.sun.star.frame.Desktop";
// arguments for document
Object[] args = new Object[4];
args[0] = "private:factory/swriter";
args[1] = "_blank";
args[2] = 0;
args[3] = new Object[] { };
// no arguments for XText interface
Object[] noargs = new Object[] { };
// argument for inserting the actual string
Object[] strarg = new Object[1];
strarg[0] = "Hello World";
Object Stardesktop;
Object doc;
Object text;
try
{
Stardesktop = (Object)t_OOo.InvokeMember("createInstance",
BindingFlags.InvokeMethod, null,
objServiceManager, parameters);
doc = Stardesktop.GetType().InvokeMember("loadComponentFromUrl",
BindingFlags.InvokeMethod, null,
Stardesktop, args);
if (doc == null)
{
return 1; // error!!
}
text = doc.GetType().InvokeMember("getText", BindingFlags.InvokeMethod,
null, doc, noargs);
text.GetType().InvokeMember("setString", BindingFlags.InvokeMethod,
null, text, strarg);
}
catch(Exception e)
{
Console.WriteLine(e);
return 1;
}
return 0;
}
}
|
A5 Python:
| Code: |
from win32com.client.dynamic import Dispatch
objServiceManager = Dispatch('com.sun.star.ServiceManager')
Stardesktop = objServiceManager.CreateInstance('com.sun.star.frame.Desktop')
doc = Stardesktop.loadComponentfromURL('private:factory/swriter', '_blank', 0, [])
text = doc.getText()
text.setString("Hello World")
|
~~~~~~~~~
~~~~~~~~~
A6 ActiveState Perl:
| Code: |
use OLE;
$args = [];
$objServiceManager = CreateObject OLE "com.sun.star.ServiceManager" || die "CreateObject: $!";
$Stardesktop = $objServiceManager->createInstance("com.sun.star.frame.Desktop");
$doc = $Stardesktop->loadComponentfromUrl("private:factory/swriter", "_blank", 0, $args );
$text = $doc->getText();
$text->setString("Hello World");
|
~~~~~~~~~
~~~~~~~~~
A7 Ruby:
| Code: |
require 'win32ole'
objServiceManager = WIN32OLE.new('com.sun.star.ServiceManager')
Stardesktop = objServiceManager.createInstance('com.sun.star.frame.Desktop')
doc = Stardesktop.loadComponentfromUrl('private:factory/swriter', '_blank', 0, [])
text = doc.getText()
text.setString('Hello World')
|
~~~~~~~~~
~~~~~~~~~
A8 TCL:
| Code: |
package require tcom
array set args {}
set objServiceManager [::tcom::ref createobject com.sun.star.ServiceManager]
set Stardesktop [$objServiceManager createInstance com.sun.star.frame.Desktop]
set doc [$Stardesktop loadComponentfromUrl private:factory/swriter _blank 0 [parray args]]
set xtext [$doc getText]
$xtext setString {Hello World}
|
~~~~~~~~~
~~~~~~~~~
A9 Delphi:
| Code: |
unit SampleCode;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj, Variants;
type
TsampleCode = class
function CreateTextDocument(): Variant;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
function TsampleCode.CreateTextDocument(): Variant;
var
objServiceManager: Variant;
Stardesktop: Variant;
doc: Variant;
text: Variant;
begin
objServiceManager := CreateOleObject('com.sun.star.ServiceManager');
Stardesktop := objServiceManager.createInstance('com.sun.star.frame.Desktop');
doc := Stardesktop.LoadComponentFromURL('private:factory/swriter', '_blank', 0, VarArrayCreate([0, - 1], varVariant));
text := doc.getText;
text.setString('Hello World');
CreateTextDocument := Document;
end.
|
~~~~~~~~~
~~~~~~~~~
A10 PHP:
| Code: |
$oArgs = array();
$objServiceManager = new COM( "com.sun.star.ServiceManager" );
$Stardesktop = $objServiceManager->createInstance( "com.sun.star.frame.Desktop" );
$doc = $Stardesktop->loadComponentFromURL("private:factory/swriter", "_blank", 0, $oArgs );
$text = $doc->getText()
$text->setString("Hello World")
|
_______________
_______________
B1 Starbasic:
| Code: |
Sub loading_MSWord( )
Dim oleService As Object
Dim oword As Object
Dim odoc As Object
oleService = createUnoService("com.sun.star.bridge.OleObjectFactory")
oword = oleService.createInstance("Word.Application")
oword.Visible = True
odoc = oword.Documents.Add
odoc.Range.Text = "Hello World!"
End Sub
|
B2 StarBasic:
| Code: |
Sub using_IE( )
Dim oleService
Dim IE
oleService = createUnoService("com.sun.star.bridge.OleObjectFactory")
IE = oleService.createInstance("InternetExplorer.Application.1")
IE.Visible = 1
IE.Navigate("http://www.openoffice.org")
End Sub
|
When having some time for it, I will also take a look at DCOM (=Distributed Component Object Model) and how to launch OpenOffice on other machines in a network.
It might also be interesting to see if these things can be done with the equivalent of Windows' powerful COM on Linux: dcop.
One thing for sure: It will not be easy for the open Linux/Unix community to build such a powerful and fast-working technology as COM is for MS Windows, the dcop can yet by no measure be compared to COM which has gone through a lot of stages over the years.
Christian _________________ - Knowledge is Power -
Last edited by Cybb20 on Sun Aug 07, 2005 11:52 am; edited 32 times in total |
|
| Back to top |
|
 |
JZA OOo Advocate


Joined: 01 Feb 2003 Posts: 431 Location: Mexico
|
Posted: Mon Jun 14, 2004 11:22 pm Post subject: |
|
|
Interesting article, there was a question on how to use this as a method to track and debug naturalization problems that OOo might have. If COM produce an illegal procedure with OOo, how can we debugg it?
Also aside from COM, could this be re-implemented with (Nu)SOAP (via XML-RPC), CORBA-bonobo, or even something like Kparts. Since Linux-world the object models are not clearly definded as with windows, however it would be an interest experiment.
COM also has many flaws and could get easily corrupted by misshandling of exceptions. _________________ OpenOffice.org ES
Project Leader
http://es.openoffice.org |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Tue Jun 15, 2004 6:47 am Post subject: |
|
|
Very nice article.
Since a COM-UNO bridge can be created, it may be possible to create bridges between UNO and other technologies, particularly with GNOME. On the other hand, I would rather see more open source projects use UNO, which I think works very well, has multiple language bindings, on multiple platforms, and even a COM-UNO bridge, and later a .NET bridge.
When using Python on Linux, you can script KDE (DCOP). It should, in theory, be possible to set up a Python on Linux that can script both KDE and OOo from within the same script. This combined with the numerous libraries for Python, would make it possible to achieve a very high degree of automation using Python. Maybe a DCOP-UNO bridge can be constructed? I simply don't know. But the possibilities are exciting. (You've no doubt heard some people suggest that open source will never achieve the kind of integration that Windows has. Although I'm not trying to start a plasma war here.)
About KParts, given the fact that OOo documents can be displayed in Java using the Office Bean, it should in theory be possible for someone knowledgeable to perhaps create a KPart which completely embeds OOo. Thus, you could have an OOo document mixed into a Konqueror window. (Not the same thing as the previous paragraph.)
I have also provided some examples using Visual FoxPro, via COM, here in the Code Snippets section.
http://www.oooforum.org/forum/viewtopic.php?p=28389#28389
http://www.oooforum.org/forum/viewtopic.php?t=3934
http://www.oooforum.org/forum/viewtopic.php?p=33878#33878
There have been some PHP examples for PHP on Windows using COM...
http://www.oooforum.org/forum/viewtopic.php?t=3474
http://www.oooforum.org/forum/viewtopic.php?t=3502
http://www.oooforum.org/forum/viewtopic.php?t=3530
A couple references to LotusScript Domino
http://www.oooforum.org/forum/viewtopic.php?t=5975
http://www.oooforum.org/forum/viewtopic.php?t=6799
It is also possible to access COM servers from within OOo. (That is, the reverse direction from what this article discusses.)
Access external COM/OLE server from OOo Basic
http://www.oooforum.org/forum/viewtopic.php?t=5918
http://www.oooforum.org/forum/viewtopic.php?t=6381
Lastly, I want to cross link between this thread, and another one that I started....
Open and Create documents, various prog. languages
http://www.oooforum.org/forum/viewtopic.php?t=5252
Again, very nice article. Thanks Christian. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Tue Jun 15, 2004 7:36 am Post subject: |
|
|
Thank you Danny for this cross-referering post.
I didn't see that some pieces of how to use COM were already existent on this forum.
I added a PHP example ( A8 ) today, it might be nice if someone could try if it works, cause I remember that somebody complained about making use of COM with PHP for OpenOffice on the dev-api mailinglist. _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Wed Jun 16, 2004 10:57 pm Post subject: |
|
|
Added: A small example of how to open up the InternetExplorer with Starbasic and browse to http://www.openoffice.org. _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Sat Jun 19, 2004 1:10 am Post subject: |
|
|
Having searched a long time for a C example, I finally found it (and where? on this forum!!). So there it is at A2 in the list  _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Fri Jun 25, 2004 6:58 am Post subject: |
|
|
Just for everybody's information. In the thread: http://www.oooforum.org/forum/viewtopic.php?t=10173 I wrongly made the assumption that it is not possible to invoke UNO dispatches.
Just to show everybody, that it is possible, I post a simple example in Python to toggle the MenuBar's visibility:
| Code: |
from win32com.client.dynamic import Dispatch
Server = Dispatch('com.sun.star.ServiceManager')
Stardesktop = Server.createInstance('com.sun.star.frame.Desktop')
odoc = Stardesktop.loadComponentFromUrl('private:factory/swriter', '_blank', 0, [])
oframe = odoc.getCurrentController().getFrame()
dispatcher = Server.createInstance('com.sun.star.frame.DispatchHelper')
dispatcher.executeDispatch(oframe, '.uno:MenuBarVisible', '', 0, []) |
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Thu Jul 01, 2004 11:32 am Post subject: |
|
|
FYI:
As I heard there are currently working processes running for creating UNO bridges for TCL and Ruby.
Just wanted to share with everyone.
It's a nice thing to see, that UNO will get bigger and bigger and thus gets more power and thus will probably get more popular around the globe. _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
pasha_golub General User


Joined: 29 Jun 2004 Posts: 24 Location: Ukraine
|
Posted: Tue Jul 06, 2004 11:47 pm Post subject: |
|
|
Thanks for example. But in all examples that I saw (Delphi-COM), I never see the part where the soffice proccess is terminated.
Smth like this:
| Code: |
unit SampleCode;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj, Variants;
type
TsampleCode = class
function CreateTextDocument(): Variant;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
function TsampleCode.CreateTextDocument(): Variant;
var
objServiceManager: Variant;
Stardesktop: Variant;
doc: Variant;
text: Variant;
begin
objServiceManager := CreateOleObject('com.sun.star.ServiceManager');
Stardesktop := objServiceManager.createInstance('com.sun.star.frame.Desktop');
doc := Stardesktop.LoadComponentFromURL('private:factory/swriter', '_blank', 0, VarArrayCreate([0, - 1], varVariant));
text := doc.getText()
text.setString('Hello World')
<b> Doc.Close(true);</b>
end;
end |
But even if I do Doc.Close, proccess soffice.exe stays in memory. What shall I do to terminate this proccess.
Thanks _________________ Nullus est in vitae sensus, ipsa vera est sensus! |
|
| Back to top |
|
 |
pasha_golub General User


Joined: 29 Jun 2004 Posts: 24 Location: Ukraine
|
Posted: Tue Jul 06, 2004 11:50 pm Post subject: |
|
|
Thanks for example. But in all examples that I saw (Delphi-COM), I never see the part where the soffice proccess is terminated.
Smth like this:
| Code: |
unit SampleCode;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj, Variants;
type
TsampleCode = class
function CreateTextDocument(): Variant;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
function TsampleCode.CreateTextDocument(): Variant;
var
objServiceManager: Variant;
Stardesktop: Variant;
doc: Variant;
text: Variant;
begin
objServiceManager := CreateOleObject('com.sun.star.ServiceManager');
Stardesktop := objServiceManager.createInstance('com.sun.star.frame.Desktop');
doc := Stardesktop.LoadComponentFromURL('private:factory/swriter', '_blank', 0, VarArrayCreate([0, - 1], varVariant));
text := doc.getText()
text.setString('Hello World')
[b]Doc.Close(true);[/b]
end;
end |
But even if I do Doc.Close, proccess soffice.exe stays in memory. What shall I do to terminate this proccess.
Even if I do objServiceManager := unAssigned I can't terminate proccess
Thanks _________________ Nullus est in vitae sensus, ipsa vera est sensus! |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Wed Jul 07, 2004 5:52 am Post subject: |
|
|
Try:
| Code: | | Stardesktop.terminate() |
_________________ - Knowledge is Power - |
|
| Back to top |
|
 |
pasha_golub General User


Joined: 29 Jun 2004 Posts: 24 Location: Ukraine
|
Posted: Wed Jul 07, 2004 6:04 am Post subject: |
|
|
| Cybb20 wrote: | Try:
| Code: | | Stardesktop.terminate() |
|
First of all, StarDesktop.Terminate without empty brackets.
I have allready tried this, but it dos'nt work. I see OS error window with text: ""The application performed an illegal operation and must be shut down..."" _________________ Nullus est in vitae sensus, ipsa vera est sensus! |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Wed Jul 07, 2004 6:13 am Post subject: |
|
|
It's with empty brackets, as far as I know.
What OS have you got? _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
pasha_golub General User


Joined: 29 Jun 2004 Posts: 24 Location: Ukraine
|
Posted: Wed Jul 07, 2004 6:31 am Post subject: |
|
|
| Cybb20 wrote: | It's with empty brackets, as far as I know.
What OS have you got? |
I have Win98 SE & Delphi 6. And I have error when I use empty brackets. _________________ Nullus est in vitae sensus, ipsa vera est sensus! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|