gpt4 book ai didi

从 C++ 类调用 C# 方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:57:52 26 4
gpt4 key购买 nike

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

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

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

我的问题是,如何在 C# 中调用 this 的方法?我想做类似的事情:

CApiInterface _api;

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

...

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

如果可能的话,我想远离 CLI/C++,如果可以的话。

最佳答案

查看 this question以其他人做同样的事情为例。它似乎围绕使用标有 UmanagedFunctionPointerAttribute 的委托(delegate)展开。

关于从 C++ 类调用 C# 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7100225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com