I'm trying to open an Excel file through Windows Automation to get some data out of it, but it's proving to be a hair-pulling experience. Here's what I have so far:


excelAppProgID                    dw 'E','x','c','e','l','.','A','p','p','l','i','c','a','t','i','o','n',0
sIID_IDispatch                    TEXTEQU <{00020400h, 0000h, 0000h, {0C0h, 00h, 00h, 00h, 00h, 00h, 00h, 46h}}>
IID_IDispatch                    GUID sIID_IDispatch
clsid                            GUID <?>
excelApp                          DWORD ?

...


invoke                    CLSIDFromProgID, ADDR excelAppProgID, ADDR clsid
.IF eax == S_OK
  invoke                  CoCreateInstance, ADDR clsid, NULL, CLSCTX_LOCAL_SERVER, ADDR IID_IDispatch, ADDR excelApp
  .IF eax == S_OK
    ; Success
  .ENDIF
.ENDIF


The call to CoCreateInstance returns 0x800401F0 which isn't one of the return values listed in the MSDN reference. A Google search leads me to believe to that the error is "Failed to connect to server". What I'm not sure of is if IID_IDispatch is declared correctly.  Looking at some examples on this forum, I see people are using that variable, but I can't find where it's declared anywhere. Furthermore, in the examples I've see, people are including files from the /masm32/com/include folder which I don't even have!

How do I correctly define a GUID and, specifically, IID_IDispatch?

Why don't I have the COM folder in my MASM installation and where can I get these include files?

Thanks for any help you can give, Spara.
Posted on 2011-03-24 08:22:10 by Sparafusile
Why don't I have the COM folder in my MASM installation and where can I get these include files?
The files were possibly made by the individual with inspiration from Microsoft Development software.  Common object model files are explained in Microsoft developerís software -- Visual Studio and up I think.  You can find tutorials on line that explain them too.  They are separate from Windows 32 files as are driver development files.

3/26/2011
I have attached the code I think you are looking for.  The error code was relevant to determining that you needed to initialize
and also uninitialize.  Thank you MSDN.  By the way it also shows the process ID of Excel.  But Excel neeeeeeeds to be running to see that number.
Attachments:
Posted on 2011-03-24 12:46:22 by roaknog
The call to CoCreateInstance returns 0x800401F0 which isn't one of the return values listed in the MSDN reference.


HRESULT: 0x800401f0 (2147746288)
Name: CO_E_NOTINITIALIZED
Description: CoInitialize has not been called.
Severity code: Failed
Facility Code: FACILITY_ITF (4)
Error Code: 0x01f0 (496)
Posted on 2011-04-07 01:57:54 by ti_mo_n
Thank you!

Do you have any idea where I can get the include files for the COM interface?
Posted on 2011-04-07 06:38:46 by Sparafusile
I know where you can get the masm32\com\include files from Ernie Murphy.
Posted on 2011-04-07 07:19:17 by roaknog
The COM include files are included in service pack 2 for MASM:

http://xcalibre.scali.eu.org/Computers/Masm32/masm.htm

Thanks again.
Posted on 2011-04-08 13:23:48 by Sparafusile