I have an application which is written in managed code and runs sucessfully, however now i disabled the /clr option from visual studio 2008 and made necessary changes to remove the manages code and convert it to native, and successfully compiled the code, however, the function CoInitializeSecurity()
is failing with HResult = 0x800401f0
.
Saying CoInitialize has not been called....
When i say GetLastError()
it returns 0
.
HRESULT hres = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);
if (FAILED(hres))
{
MessageBox(NULL, "COM Init failed...", "Stop", MB_OK);
return FALSE;
}
Thanks in advance,,
The same code works fine if /clr enabled.
The same code works fine if /clr enabled
Sure. It was the CLR that took care of calling CoInitializeEx() before. Picking the apartment type from the [STAThread] attribute on the Main() entrypoint or the value you passed to Thread::SetApartmentState(), if any. Default is MTA.
That's not happening anymore since you now compile without /clr. You therefore must call CoInitializeEx() yourself.
User contributions licensed under CC BY-SA 3.0