来自C ++类的C#调用方法

时间:2011-08-17 22:18:06

标签: c# c++ interop

我正在尝试使用c-sharp与基于Windows的api集成,我遇到了这个问题。

api向我发送一个指向结构的指针,该结构包含一堆虚拟方法

struct CApiInterface
{
   virtual int __stdcall Version(void);
   ...
}

我的问题是,如何在C#中调用此方法?我想做点什么:

CApiInterface _api;

public void Start(CApiInterface* api)
{
_api = api;
}

...

public void SomeOtherMethod()
{
_api.version();
}

如果可能的话,我想尽可能不使用CLI / C ++。

1 个答案:

答案 0 :(得分:2)

查看this question以查找执行相同操作的其他人的示例。它似乎围绕着使用标有UmanagedFunctionPointerAttribute的代理。