3
我一直在C++上編寫DLL,這將在C#中使用。 DLL有一定的功能,在那裏我稱之爲使用在C#中使用COM的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)設置後無法更改線程模式。我改變
hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);
到
hres = CoInitialize(NULL);
在此之後更改後CoInitializeSecurity出現錯誤:
(80010119) Security must be initialized before any
interfaces are marshalled or unmarshalled. It
cannot be changed once initialized.
如何解決這個問題?
謝謝。請看看[這個相關的問題](http://stackoverflow.com/q/29385515/938668)。我無法確定將這些調用放在託管應用中的位置。 – 2015-04-01 09:29:55