我有一个C#COM接口定义为
[ComVisible(true)]
[Guid("EB6602D5-8458-4733-8F0A-05A88FEEB42F")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMyInterface
{
[DispId(1)]
void Initialize(string szPath, uint uiAddress,
[MarshalAs(UnmanagedType.Interface)]
object pEventsImpl, //Interface pointer for my COM Svr Callback
[MarshalAs(UnmanagedType.Interface)]
out object ppCommunication); //Interface for Client to Access Server
}
此COM接口生成的tlb是
interface IMyInterface : IUnknown {
HRESULT _stdcall Initialize(
[in] BSTR szPath,
[in] unsigned long uiAddress,
[in] IUnknown* pEventsImpl,
[out] IUnknown** ppCommunication);
}
在C ++客户端代码中,我将C#COM称为
hr = pInterface->Initialize( strPath, iAddress, m_Events, &pUnk);
然而我收到以下例外
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
First-chance exception at 0x7c812aeb in MyClient.exe: 0xE0434352: 0xe0434352. Microsoft C++ exception: _com_error at memory location 0x0012f0ac..
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in MyClient.exe
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in MyClient.exe
我做错了吗?什么是System.FormatException?
[已更新] Addtinal信息** 我试图使用/ clr(公共语言运行时支持)选项编译C ++代码,它似乎工作。但是,我想知道是否有可能不使用公共语言运行时支持编译我的C ++代码,因为我有一些限制,因为我使用现有的C ++客户端,我不想使用不同的配置重新编译
感谢