I have some C # program that loads a C ++ DLL, in one of the functions of which an attempt is made to create a COM object. This function returns an interface value.
extern "C" _declspec(dllexport) ISin * __stdcall GetInterface() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (FAILED(hr)) { std::cout << "CoInitialize -> FAILED"; return 0; } ISin * pISin = 0; hr = CoCreateInstance(CLSID_CoSin, 0, CLSCTX_INPROC_SERVER, IID_ISin, (LPVOID*)&pISin); if (FAILED(hr)) { std::cout << "CoCreateInstance -> FAILED"; // <-- Выводит в основной программе std::cout << hr; // -2147221164 return 0; } if (pISin == 0) { std::cout << "pISin is null"; } CoUninitialize(); return pISin; } Could not correctly invoke the function CoCreateInstance: FAILED (hr) returns true and that's it.
I know that there is a CoCreateInstanceEx function, but I don’t know how to use it and whether it will help here at all. Also, perhaps a problem in choosing CLSCTX.
Your suggestions?
hr? Are you sure the context should beCLSCTX_INPROC_SERVER? In addition,CoUninitializemust be called strictly after deleting the created object. - VTT