DllGetClassObject return “No such interface supported” while CoCreateInstance can find it successful

别等时光非礼了梦想. 提交于 2019-12-11 20:07:11

问题


I want to use the library "sqlceoledb35.dll" to process .sdf db file without register. I know this dll is a COM dll and used in ADO.
But I can't get the target interface, it returns error "No such interface supported".
Here is the code:

    CoInitialize(nullptr); 
    HMODULE hmod = CoLoadLibrary((L"sqlceoledb35.dll"), true);
    DllGetClassObject_t pDllGetClassObject =(DllGetClassObject_t)GetProcAddress(hmod,        "DllGetClassObject");
    HRESULT hr=NOERROR;
    IDBInitialize *pIDBInitialize1=NULL;
    IDBInitialize *pIDBInitialize2=NULL;
    hr = pDllGetClassObject(CLSID_SQLSERVERCE_3_5, __uuidof(IUnknown), (void**)&pIDBInitialize1);
    hr = pDllGetClassObject(CLSID_SQLSERVERCE_3_5, IID_IDBInitialize, (void**)&pIDBInitialize2);

But in this code snippet, _uuidof(IUnknow)can return a interface success, but IID_IDBInitialize will fail(this IID can work in CoCreateInstance, you will see later.

This is another code which can work correctly in the same machine with the same interface IID:

    CoInitialize(nullptr); 
    hr = CoCreateInstance(  CLSID_SQLSERVERCE_3_5, 
                        0, 
                        CLSCTX_INPROC_SERVER, 
                        IID_IDBInitialize, 
                        (void**)&pIDBInitialize);

So anyone can help, So that the 1st code snippet can work?
So did the method CoCreateInstance do more work which is a key?


回答1:


CoCreateInstance (for in-proc servers) works in two stages. First, it loads the DLL and calls DllGetClassObject with the CLSID you pass, asking for IClassFactory interface. Second, it calls IClassFactory::CreateInstance on the pointer thus obtained, with the IID you pass.

The object that DllGetClassObject knows how to create - the class factory - does not normally itself implement any interfaces other than IClassFactory and, of course, IUnknown.



来源:https://stackoverflow.com/questions/18737799/dllgetclassobject-return-no-such-interface-supported-while-cocreateinstance-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!