我一直在用C++编写DLL,该DLL将在C#中使用。 DLL具有一些函数,在其中我调用
hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);
然后进行下一次调用
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_PKT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
我在使用这个dll时,在C++中没有出现任何错误。但是,如果我通过C#应用程序调用DLL中的函数,则会出现错误(80010106) Cannot change thread mode after it is set. 我更改了
hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);
to
hres = CoInitialize(NULL);
更改后,在CoInitializeSecurity之后出现错误:
(80010119) Security must be initialized before any
interfaces are marshalled or unmarshalled. It
cannot be changed once initialized.
如何解决这个问题?