.NET EXE--->Dll---->::CoCreateIstance Fails

I'm calling a method whitin my .exe managed code:

MSgate.initObjects()

then,

intObjects() calls a function inside an unmanaged dll function which i import through:

[DllImport(dllPath, EntryPoint = "initObjects", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]

public static extern void initObjects();

In the unmanaged code, inside that function there is a call to ::CoCreateIstance which fails returning me E_NOINTERFACE error:

::CoCreateInstance (CLSID_MLWriter,NULL,CLSCTX_INPROC_SERVER,IID_IMLWriter,(void**)&g_IMLWriter)

I don't undestand why, the dll exposing COM is correctly registered and when i try to use it from a .exe unmanaged code the CoCreateInstance works. Instead if i try to call it from a dll imported in a .exe managed code through MSgate.initObjects(), then CoCreateIstance fails with E_NOINTERFACE.

Summry

.exe unmanaged -> call to CoCreateIstance (works)

the same code called from a managed exe:

.exe managed -> call initobjects inside unmanaged dll -> which calls CoCreateIstance (fails with E_NOINTERFACE)



Answer this question

.NET EXE--->Dll---->::CoCreateIstance Fails

  • Vadivel

    solved with [STAThread] :\
  • Danca

    It's hard to see a way in which the CLR can mess this up. Two possibilities, but I'm reaching:
    - The CLR calls CoInitializeEx() and looks at whether or not you specified the [STAThread] attribute on your .NET program's entry point.
    - Your ActiveX component uses reg-free COM.



  • .NET EXE--->Dll---->::CoCreateIstance Fails