本文介绍了DllGetClassObject返回“没有这样的接口支持”而CoCreateInstance可以找到它成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想使用库sqlceoledb35.dll来处理没有注册的.sdf db文件。我知道这个dll是一个COM dll并在ADO中使用。 但是我无法获得目标接口,它返回错误没有这样的接口支持。 以下是代码: CoInitialize(nullptr); HMODULE hmod = CoLoadLibrary((Lsqlceoledb35.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); 但在此代码片段中, _uuidof(IUnknow)可以返回一个接口成功,但 IID_IDBInitialize 将失败(此IID可以在 CoCreateInstance 中工作, 。 这是另一个代码,可以在同一台机器上使用相同的接口IID正常工作: CoInitialize(nullptr); hr = CoCreateInstance(CLSID_SQLSERVERCE_3_5, 0, CLSCTX_INPROC_SERVER, IID_IDBInitialize ,(void **)& pIDBInitialize); 第一个代码片段可以工作? 那么方法 CoCreateInstance 做更多的工作,这是一个关键吗? 解决方案 CoCreateInstance (对于in-proc服务器)分两个阶段工作:首先,加载DLL和调用 DllGetClassObject 与 CLSID 传递,要求 IClassFactory 。其次,它对这样获得的指针调用 IClassFactory :: CreateInstance ,并传递 IID 。 DllGetClassObject 知道如何创建的对象 - 类工厂 - 不通常本身实现任何 IClassFactory 以外的接口,当然还有 IUnknown 。 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? 解决方案 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. 这篇关于DllGetClassObject返回“没有这样的接口支持”而CoCreateInstance可以找到它成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-13 13:44