C# COM互操作和System.InvalidCastException异常

C# COM互操作和System.InvalidCastException异常,c#,c++,com,interop,C#,C++,Com,Interop,我不熟悉用C编写COM对象。我遇到了一个需要帮助的问题 我有一个用C++编写的COM接口,叫做iTest.我使用tlbimp.exe为DLL创建了一个互操作,该DLL中存在该接口,并在我的测试系统上注册了它。我编写了一个使用这个ITest接口的C测试应用程序,它运行良好 我还在用C编写另一个COM接口。这个接口有一个方法,它接受一个ITest类型的参数。我有一个C++程序,需要使用这个托管COM对象并调用此方法。当我运行C++程序时,我看到下面的SypRealDistaExpExcExp:< /

我不熟悉用C编写COM对象。我遇到了一个需要帮助的问题

我有一个用C++编写的COM接口,叫做iTest.我使用tlbimp.exe为DLL创建了一个互操作,该DLL中存在该接口,并在我的测试系统上注册了它。我编写了一个使用这个ITest接口的C测试应用程序,它运行良好

我还在用C编写另一个COM接口。这个接口有一个方法,它接受一个ITest类型的参数。我有一个C++程序,需要使用这个托管COM对象并调用此方法。当我运行C++程序时,我看到下面的SypRealDistaExpExcExp:< /P> InvalidCastException: 0:000> !pe Exception object: 03281b3c Exception type: System.InvalidCastException Message: Unable to cast COM object of type 'System.__ComObject' to interface type '.ITest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '<Some GUID>' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). InnerException: <none> StackTrace (generated): <none> StackTraceString: <none> HResult: 80004002 使用此COM接口的C++代码:

ITest * pTest = NULL; … pTest gets assigned a valid pointer … hr = MyMethod(pTest);
有人能告诉我正确的方向并帮我调试这个问题吗?

您需要调试IUnknown::QueryInterface的实现。 ITest * pTest = NULL; … pTest gets assigned a valid pointer … hr = MyMethod(pTest);