NO

Author Topic: CoCreateInstance error  (Read 10896 times)

ZumBubba

  • Guest
CoCreateInstance error
« on: November 02, 2010, 05:33:08 PM »
Hi all!
Be so kind to help me with using of CoCreateInstance. I need to use msxml parser, but when I compile my application I get an error message: error #2140: Type error in argument 4 to 'CoCreateInstance'; expected 'const UUID * const ' but found 'UUID'.

My code is:

#include <objbase.h>
#include <msxml2.h>
...
HRESULT hr ;
CLSID clsid;
IXMLDOMDocument* pIFace;

hr = CoInitializeEx(NULL, COINIT_MULTITHREADED );
hr = CLSIDFromProgID(L"MSXML2.DOMDocument", &clsid);
hr = CoCreateInstance(&clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IXMLDOMDocument, (void **) &pIFace);   <-- error on this line
...
CoUninitialize();

I found many examples, but all of them do the same.
My application is on Windows CE 5.
Excuse me for my english, it is not my native language :-(

JohnF

  • Guest
Re: CoCreateInstance error
« Reply #1 on: November 02, 2010, 05:59:37 PM »
This IID_IXMLDOMDocument

should be

&IID_IXMLDOMDocument

John

ZumBubba

  • Guest
Re: CoCreateInstance error
« Reply #2 on: November 03, 2010, 09:18:08 AM »
Thank You, John.

I thought exactly that and got a message: POLINK: error: Unresolved external symbol 'IID_IXMLDOMDocument'.

Well, add msxml2.lib on Linker page of Project options - nothing changes, error message remains the same.
msxml2.lib file, deploying with Pelles C, I found in C:\Program Files\PellesC\Lib\Win folder. There was a suspicion that its file is not for winCE, but make a copy to C:\Program Files\PellesC\Lib - nothing changes, error message remains.

Looked a msxml2.lib file - found _IID_IXMLDOMDocument string inside: is it a point of input?
Well, change EXTERN_C const IID IID_IXMLDOMDocument declaration in C:\Program Files\PellesC\Include\WinCE\msxml2.h to EXTERN_C const IID _IID_IXMLDOMDocument;
Now got a message: POLINK: warning: Invalid machine type in object 'iid_ixmldomdocument.obj'.

A code is:

#include <objbase.h>
#include <msxml2.h>
...
HRESULT hr ;
CLSID clsid;
IXMLDOMDocument* pIFace;

hr = CoInitializeEx(NULL, COINIT_MULTITHREADED );
hr = CLSIDFromProgID(L"MSXML2.DOMDocument", &clsid);
hr = CoCreateInstance(&clsid, NULL, CLSCTX_LOCAL_SERVER, &_IID_IXMLDOMDocument, (void **) &pIFace);
...
CoUninitialize();

Application starts on target devise, but CoCreateInstance returns E_NOINTERFACE as a result (hr value).

Is it because msxml2.lib, deploying with Pelles C, is NOT for ARM and/or NOT for winCE 5?
If it is that, where can I get necessary msxml2.lib file?

Really nobody worked with msxml parser on ARM+winCE devices?

P.S. Please, please help me (The Beatles :-)

JohnF

  • Guest
Re: CoCreateInstance error
« Reply #3 on: November 03, 2010, 10:21:50 AM »
I can only test on Windows and it compiles here.

IID_IXMLDOMDocument is in msxml2.lib but I don't know if
it is valid on your platform. You will need &IID_IXMLDOMDocument
though.

Maybe someone who uses your platform can help.

John


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: CoCreateInstance error
« Reply #4 on: November 03, 2010, 01:24:48 PM »
Have you tested uuid.lib already ???

Code: [Select]
#include <objbase.h>
#include <msxml2.h>

#pragma lib "ole32"
#pragma lib "uuid"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszCmdLine, int nCmdShow)
{

HRESULT hr;
CLSID clsid;
IXMLDOMDocument *pIFace;

if ((hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)) == S_OK) {
if ((hr = CLSIDFromProgID(L"MSXML2.DOMDocument", &clsid)) == S_OK) {
if ((hr = CoCreateInstance(&clsid, NULL, CLSCTX_ALL, &IID_IXMLDOMDocument, (void **)&pIFace)) == S_OK) {
if (pIFace) {
pIFace->lpVtbl->Release(pIFace);
MessageBox(0, L"Found", 0, MB_OK);
}
} else MessageBox(0, L"Not found", 0, MB_OK);
}
}
CoUninitialize();

return 0;
}

« Last Edit: November 03, 2010, 02:18:42 PM by timovjl »
May the source be with you

ZumBubba

  • Guest
Re: CoCreateInstance error
« Reply #5 on: November 03, 2010, 06:41:56 PM »
Thank You John for your help

I undestand timovjl's anger, using uuid is the right way.
Even with uuid CoCreateInstance returns E_NOINTERFACE. But only with CLSCTX_LOCAL_SERVER flag!
With CLSCTX_ALL programm works fine. Rather with CLSCTX_INPROC_SERVER flag.

timovjl - thanks, many thanks!

I found very usefull article http://blogs.msdn.com/b/larryosterman/archive/2004/10/12/241420.aspx about CLSCTX_xxx flags in CoCreateInstance.