I am trying to use surrogate process, dllhost, to run my COM 64-bit dll in a separate 64-bit dllhost process. I have made the required registry entries for the same.
When I try to create an object of my class using CoCreateInstance or CoGetClassObject and CreateInstance I get an E_FAIL error. The error is observed if I specify CLSCTX_LOCAL_SERVER flag. This call works fine with CLSCTX_INPROC_SERVER flag but of course NOT in a separate process, dllhost.
On using CLSCTX_LOCAL_SERVER, I can see dllhost.exe in my taskbar; this indicates that surrogate related registry entries are correct, but the call to CoCreateInstance/CreateInstance fails with error E_FAIL.
Here is the code snippet:-
hr = CoInitialize (NULL);
if(FAILED(hr))
return hr;
IClassFactory *ptr;
// I can see dllhost in task manager after this call
hr = CoGetClassObject(CLSID_MyID, CLSCTX_LOCAL_SERVER, 0,IID_IClassFactory,(void**)&ptr);
// Works fine with CLSCTX_INPROC_SERVER
//hr = CoGetClassObject(CLSID_MyID, CLSCTX_INPROC_SERVER, 0,IID_IClassFactory,(void**)&ptr);
if(FAILED(hr))
return hr;
ptr->LockServer(TRUE);
hr = ptr->CreateInstance(NULL, IID_IUnknown, (void**) &myPointer);
if(FAILED(hr)) // I get E_FAIL here if CLSCTX_LOCAL_SERVER is on.
return hr;
ptr->LockServer(FALSE);
ptr->Release();