Automation OpenOffice with C language

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
PabloF
Posts: 1
Joined: Sun Apr 12, 2015 8:09 pm

Automation OpenOffice with C language

Post by PabloF »

Hi there,

Please anyone explain to me how does this idea of interfaces, modules, service, struct is realized with OLE dispatch.
I managed to make connection to OpenOffice, create a sheet, fill it out, everything using Autowrap function, that dispatches functions from UNO API.
for example:

Code: Select all

	CoInitialize (NULL);	// Initialize COM for this thread...
	bUsed = TRUE;
	CLSID clsid;	// Get CLSID for our server... 
	HRESULT hr = CLSIDFromProgID (L"com.sun.star.ServiceManager", &clsid);
	if (FAILED (hr)) {	::MessageBox (NULL, "CLSIDFromProgID() failed", "Error", 0x10010); return FALSE; } 
	// Start server and get IDispatch... 
	hr = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void**) &pOOApp);
	if (FAILED(hr))  {::MessageBox (NULL, "OpenOffice not registered properly", "Error", 0x10010);return FALSE;	}
	// Get Desktop and its assoc. IDispatch... 
	VARIANT result;
	VARIANT param1;
	VariantInit(&result);
	VariantInit (&param1);
	param1.vt = VT_BSTR;		// it's a UNICODE string 
	param1.bstrVal = ::SysAllocString (L"com.sun.star.frame.Desktop");
	AutoWrap (DISPATCH_METHOD, &result, pOOApp, L"createInstance", 1, param1);
	
	pdispDesktop = result.pdispVal; // IDispatch*  
	pdispDesktop->AddRef (); 
This is Basic would be one or two lines of code.
Unfortunately in C it's a real pain.

I need to merge cells in a sheet.
I managed to create a Cell object, change it's color, and that's it.

I know I have to use XMergeable, I found it in the API documentation, but I have no clue how to create an instance of it.
I tried to create an instance of XMergeable from different IDispatch objects, representing a sheet, a document, an application.
Nothing, I cannot create it.
As a matter of fact, documentation states what objects are there, and what is connected to what, but I still cannot figure out connections, how can I get the object of given class.

Please give me something, that will allow me to understand it.
On this forum I have found only 3 posts about using UNO API in C, is this really ancient history ?

Regards
Pablo
Last edited by floris v on Sun Apr 12, 2015 9:52 pm, edited 1 time in total.
Reason: Removed icon used for threads with link to bug report
OpenOffice 4.1.1 Windows all types
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Automation OpenOffice with C language

Post by Villeroy »

Virtually nobody automates Openoffice with C and this is a user forum.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply