From: Jackson Y. <jac...@ya...> - 2000-09-16 13:39:16
|
The best example of using automation for office is found in a downloadable file from http://support.microsoft.com/support/kb/articles/Q253/2/35.ASP. The examples are in C++ rather than C, but will give you the general concepts of using IDispatch and using variants. I strongly recommend using C++ though, as automation uses COM, and COM in C is even more ugly than COM in C++ is. Sorry to say that I've never used automation with mingw, but good luck on the project. Regards, Jackson Yee --- Thomas Philip Runarsson <tp...@ze...> wrote: > Hi, > > Does anyone know where I can get an example "C" implementation > (source) for ole automation ? Perhaps one which uses excel as > an objects and compiles with mingw? > > Thanks, Tom > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options at: > http://lists.sourceforge.net/mailman/listinfo/mingw-users __________________________________________________ Do You Yahoo!? Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ |
From: Thomas P. R. <tp...@ze...> - 2000-09-16 23:12:44
|
Hi again, Thanks for the hint on the ole automation examples: it was looking good with mingw until ... well: C:\>gcc -o test.exe exercise4.cpp -loleaut32 -lole32 -fvtable-thunks -mwindows C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x140):exercise4.cpp: undefined reference to `IID_IUnknown' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x166):exercise4.cpp: undefined reference to `IID_IDispatch' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x19c):exercise4.cpp: undefined reference to `GUID_NULL' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x1cf):exercise4.cpp: undefined reference to `GUID_NULL' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x20f):exercise4.cpp: undefined reference to `GUID_NULL' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x242):exercise4.cpp: undefined reference to `GUID_NULL' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x27c):exercise4.cpp: undefined reference to `GUID_NULL' C:\WINDOWS\TEMP\ccN4qegb.o(.text+0x2af):exercise4.cpp: more undefined references to `GUID_NULL' follow Cannot find these in the win32 library function by name listing. Any ideas? 'IID_IUnknown' is be found on system in: c:\windows\system\compobj.dll c:\windows\system\mrwo30.dll c:\windows\system\mrwo30d.dll c:\windows\system\mswo30.dll c:\windows\system\mswo30d.dll c:\windows\system\browscap.dll 'IID_IDispatch' is also found on system in: c:\windows\system\ole2disp.dll 'GUID_NULL' is found in: c:\windows\system\compobj.dll c:\windows\system\mrwo30.dll c:\windows\system\mrwo30d.dll c:\windows\system\mswo30.dll c:\windows\system\mswo30d.dll regards, Tom code follows: -------- SNIP ----------- #include <ole2.h> #include <stdio.h> int main(int argc, char* argv[]) { // ******************* Declare Some Variables ******************** // Variables that will be used and re-used in our calls DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0}; VARIANT vResult; OLECHAR FAR* szFunction; BSTR bstrTemp; // IDispatch pointers for Word's objects IDispatch* pDispDocs; //Documents collection IDispatch* pDispSel; //Selection object IDispatch* pDispActiveDoc; //ActiveDocument object // DISPID's DISPID dispid_Docs; //Documents property of Application object DISPID dispid_DocsAdd; //Add method of Documents collection //object DISPID dispid_Sel; //Selection property of Applicaiton object DISPID dispid_TypeText; //TypeText method of Selection object DISPID dispid_TypePara; //TypeParagraph method of Selection object DISPID dispid_ActiveDoc; //ActiveDocument property of Application //obj DISPID dispid_SaveAs; //SaveAs method of the Document object DISPID dispid_Quit; //Quit method of the Application object // ******************** Start Automation *********************** //Initialize the COM libraries ::CoInitialize(NULL); // Create an instance of the Word application and obtain the pointer // to the application's IDispatch interface. CLSID clsid; CLSIDFromProgID(L"Word.Application", &clsid); IUnknown* pUnk; HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk); IDispatch* pDispApp; hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp); // Get IDispatch* for the Documents collection object szFunction = OLESTR("Documents"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Docs); hr = pDispApp->Invoke (dispid_Docs, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult, NULL, NULL); pDispDocs = vResult.pdispVal; // Invoke the Add method on the Documents collection object // to create a new document in Word // Note that the Add method can take up to 3 arguments, all of which // are optional. We are not passing it any so we are using an empty // DISPPARAMS structure szFunction = OLESTR("Add"); hr = pDispDocs->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_DocsAdd); hr = pDispDocs->Invoke(dispid_DocsAdd, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpNoArgs, &vResult, NULL, NULL); // Get IDispatch* for the Selection object szFunction = OLESTR("Selection"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Sel); hr = pDispApp->Invoke (dispid_Sel, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult, NULL, NULL); pDispSel = vResult.pdispVal; // Get the DISPIDs of the TypeText and TypeParagraph methods of the // Selection object. We'll use these DISPIDs multiple times. szFunction = OLESTR("TypeText"); hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_TypeText); szFunction = OLESTR("TypeParagraph"); hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_TypePara); // The TypeText method has and requires only one argument, a string, // so set up the DISPPARAMS accordingly VARIANT vArgsTypeText[1]; DISPPARAMS dpTypeText; bstrTemp = ::SysAllocString(OLESTR("One")); vArgsTypeText [0].vt = VT_BSTR; vArgsTypeText [0].bstrVal = bstrTemp; dpTypeText.cArgs = 1; dpTypeText.cNamedArgs = 0; dpTypeText.rgvarg = vArgsTypeText; //Invoke the first TypeText and TypeParagraph pair hr = pDispSel->Invoke (dispid_TypeText, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpTypeText, NULL, NULL, NULL); hr = pDispSel->Invoke (dispid_TypePara, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpNoArgs, NULL, NULL, NULL); ::SysFreeString(bstrTemp); //Invoke the second TypeText and TypeParagraph pair bstrTemp = ::SysAllocString(OLESTR("Two")); hr = pDispSel->Invoke (dispid_TypeText, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpTypeText, NULL, NULL, NULL); hr = pDispSel->Invoke (dispid_TypePara, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpNoArgs, NULL, NULL, NULL); ::SysFreeString(bstrTemp); //Invoke the third TypeText and TypeParagraph pair bstrTemp = ::SysAllocString(OLESTR("Three")); hr = pDispSel->Invoke (dispid_TypeText, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpTypeText, NULL, NULL, NULL); hr = pDispSel->Invoke (dispid_TypePara, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpNoArgs, NULL, NULL, NULL); ::SysFreeString(bstrTemp); // Get IDispatch* for the ActiveDocument object szFunction = OLESTR("ActiveDocument"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_ActiveDoc); hr = pDispApp->Invoke (dispid_ActiveDoc, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult, NULL, NULL); pDispActiveDoc = vResult.pdispVal; //Set up the DISPPARAMS for the SaveAs method (11 arguments) VARIANT vArgsSaveAs[11]; DISPPARAMS dpSaveAs; dpSaveAs.cArgs = 11; dpSaveAs.cNamedArgs = 0; dpSaveAs.rgvarg = vArgsSaveAs; BSTR bstrEmptyString; bstrEmptyString = ::SysAllocString(OLESTR("")); VARIANT vFalse; vFalse.vt = VT_BOOL; vFalse.boolVal = FALSE; bstrTemp = ::SysAllocString(OLESTR("c:\\doc1.doc")); vArgsSaveAs[10].vt = VT_BSTR; vArgsSaveAs[10].bstrVal = bstrTemp; //Filename vArgsSaveAs[9].vt = VT_I4; vArgsSaveAs[9].lVal = 0; //FileFormat vArgsSaveAs[8] = vFalse; //LockComments vArgsSaveAs[7].vt = VT_BSTR; vArgsSaveAs[7].bstrVal = bstrEmptyString; //Password vArgsSaveAs[6].vt = VT_BOOL; vArgsSaveAs[6].boolVal = TRUE; //AddToRecentFiles vArgsSaveAs[5].vt = VT_BSTR; vArgsSaveAs[5].bstrVal = bstrEmptyString; //WritePassword vArgsSaveAs[4] = vFalse; //ReadOnlyRecommended vArgsSaveAs[3] = vFalse; //EmbedTrueTypeFonts vArgsSaveAs[2] = vFalse; //SaveNativePictureFormat vArgsSaveAs[1] = vFalse; //SaveFormsData vArgsSaveAs[0] = vFalse; //SaveAsOCELetter //Invoke the SaveAs method szFunction = OLESTR("SaveAs"); hr = pDispActiveDoc->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_SaveAs); hr = pDispActiveDoc->Invoke(dispid_SaveAs, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpSaveAs, NULL, NULL, NULL); ::SysFreeString(bstrEmptyString); //Invoke the Quit method szFunction = OLESTR("Quit"); hr = pDispApp->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Quit); hr = pDispApp->Invoke (dispid_Quit, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpNoArgs, NULL, NULL, NULL); //Clean-up ::SysFreeString(bstrTemp); pDispActiveDoc->Release(); pDispSel->Release(); pDispDocs->Release(); pDispApp->Release(); pUnk->Release(); ::CoUninitialize(); return 0; } |
From: Benoit Goudreault-E. <bg...@cr...> - 2000-09-17 00:09:18
|
>>>>> "TPR" == Thomas Philip Runarsson <tp...@ze...> writes: TPR> Hi again, TPR> Thanks for the hint on the ole automation examples: TPR> it was looking good with mingw until ... well: [stuff about IID_* symbols not found deleted] TPR> Cannot find these in the win32 library function by name listing. TPR> Any ideas? Try: gcc -o test.exe exercise4.cpp -loleaut32 -lole32 -luuid -fvtable-thunks -mwindows Does that help? -- Benoit Goudreault-Emond -- Reply to: bg...@cr... CoFounder, KMS Group. Programmer, Silanis Technology (http://www.silanis.com) A proud user of Linux---I'd rather work than nursemaid my computer. My homepage (such as it is): http://www.crosswinds.net/~bge |
From: Juan C. A. B. <jc...@ro...> - 2000-09-17 00:30:33
|
Hi! I just saw in another list the following text: "wchar_t is an implementation-defined type of at least 16-bits. On gcc on most major platforms, for instance, wchar_t is a four-byte quantity". I thought I'd ask. Given that UNICODE in Win32 is a 16-bit character, is that true on the MinGW compiler? Or is it one of the "other" platforms? Salutaciones, JCAB --------------------------------------------------------------------- Juan Carlos "JCAB" Arevalo Baeza | http://www.roningames.com Senior Technology programmer | mailto:jc...@ro... Ronin Entertainment | ICQ: 10913692 (my opinions are only mine) JCAB's Rumblings: http://www.metro.net/jcab/Rumblings/html/index.html |
From: Tor L. <tm...@ik...> - 2000-09-18 16:58:34
|
Juan Carlos Arevalo Baeza writes: > Hi! I just saw in another list the following text: "wchar_t is an > implementation-defined type of at least 16-bits. On gcc on most major > platforms, for instance, wchar_t is a four-byte quantity". > I thought I'd ask. Given that UNICODE in Win32 is a 16-bit character, > is that true on the MinGW compiler? Or is it one of the "other" platforms? That text is a bit misleading. The size of wchar_t isn't so much a compiler issue, it's a C library issue. As gcc on mingw uses the Microsoft C library, wchar_t is 16 bits. --tml |
From: Paul G. <pga...@te...> - 2000-09-18 22:21:39
|
On 18 Sep 2000, at 19:56, the Illustrious Tor Lillqvist wrote: > Juan Carlos Arevalo Baeza writes: > > Hi! I just saw in another list the following text: "wchar_t is > an > implementation-defined type of at least 16-bits. On gcc on > most major > platforms, for instance, wchar_t is a four-byte > quantity". > > > I thought I'd ask. Given that UNICODE in Win32 is a 16-bit > character, > is that true on the MinGW compiler? Or is it one of > the "other" platforms? > > That text is a bit misleading. The size of wchar_t isn't so much > a compiler issue, it's a C library issue. As gcc on mingw uses > the Microsoft C library, wchar_t is 16 bits. So, when sizeof(wchar_t) produces two, it is really and truly 32 bits in size on NT4 machines. Peace, Paul G. > > --tml > > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options at: > http://lists.sourceforge.net/mailman/listinfo/mingw-users > Nothing real can be threatened. Nothing unreal exists. |
From: Jeff S. <jef...@ap...> - 2000-09-17 01:55:23
|
Juan Carlos Arevalo Baeza wrote: > I thought I'd ask. Given that UNICODE in Win32 is a 16-bit character, > is that true on the MinGW compiler? Or is it one of the "other" platforms? What is the output of: printf("%d", sizeof(wchar_t)); Jeff |