Question

I'm using external native COM component in my C# .Net application.

This COM dll doesn't have a type library, so I had to write the interop code myself, and having include/idl files I did it like TlbImp does. But the worst thing is that the object creation fail with:

Creating an instance of the COM component with CLSID {40700425-0080-11D2-851F-00C04FC21759} from the IClassFactory failed due to the following error: 80040111

The class is finely created if I use native CoCreateInstance and specify class_id and one of implemented interface iids.

As it turned out the problem lies in that COM object's IClassFactory::CreateInstance doesn't support IID_IUnknown passed as riid parametr, and therefore returns CLASS_E_CLASSNOTAVAILABLE (I identified it with disassembler and debugger). The component is MS SQL VDI.

Is there any way to force .Net RCW to pass different interface id into CreateInstance method rather than IID_IUnknown? Searched net a o a lot, but didn' find a solution for ths.

As a workaround I'm using C++/CLI now to crreate object with requesting proper interface instead if IID_IUnknown. for this purpose now, but would like to have code in C#, because C++/CLI requires me to build different DLL for each platform.

Thanks

Was it helpful?

Solution

I repro. Brr, painful. You could pinvoke CoCreateInstance:

[return: MarshalAs(UnmanagedType.Interface)]
[DllImport("ole32.dll", ExactSpelling=true, PreserveSig=false)]
public static extern object CoCreateInstance(ref Guid clsid, 
    [MarshalAs(UnmanagedType.Interface)] object punkOuter, int context, ref Guid iid);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top