如何将IUnknown **指针从C ++ COM传递给C# [英] How do I pass an IUnknown** pointer from C++ COM to C#
问题描述
我需要通过COM互操作将IUnknown **指针传递给C#模块。我可以在C#端的接口中添加一个方法来处理这个问题。问题是如何在C#端处理它?
例如,从C ++ COM端我可以通过某个接口访问C#模块,比如m_pMyInterface:
此外,这个IUnknown接口指针实际上是一些来自IUnknown的其他接口,比如IProgInterace。
IUnknown ** pUnknown =< some_value> ;;
m_pMyInterface-> MyMethod(pUnknown);
如何在C#中处理此参数?它应该是一个IntPtr,如果是这样,我如何将其转换回所需的接口(IProgInterface)来调用它的方法?
TIA,
Jy
Hi,
I need to pass an IUnknown** pointer to a C# module through COM interop. I can add a method in an interface to on the C# side to handle this. The question is how do I handle it on the C# side
For example, from the C++ COM side I have access to the C# module through some interface, say m_pMyInterface:
Also, this IUnknown interface pointer is actually some other interface which derives from IUnknown, say IProgInterace.
IUnknown** pUnknown = <some_value>;
m_pMyInterface->MyMethod(pUnknown);
How do I handle this parameter in C#? Should it be an IntPtr, and if so how do I convert it back to the desired interface (IProgInterface) to call its methods?
TIA,
Jy
推荐答案
您是否有任何理由不直接从C#中使用此COM组件代码 - 通过添加对它的引用?
Is there any reason you're not just using this COM component more directly from your C# code - by adding a reference to it?
https://msdn.microsoft.com/en-us/library/ms973800.aspx
戴夫
这篇关于如何将IUnknown **指针从C ++ COM传递给C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!