c# - C++ 函数作为参数

标签 c# c++ dll parameters visual-c#-express-2010

我有一个包含 C++ 代码的 DLL,它在 Visual C# 中完美运行。当我在 C++ DLL 中创建一个 fucton 时,它会出现在 Visual C# 中,我调用它,甚至使用参数。但是,当我在 C++ DLL 中添加一个函数指针作为参数之一时,Visual C# 无法找到它。

C++ 函数:

 int TEST(int *func) // Works fine and shows up in visual C#.
 { 
     return 0;
 } 

int TEST2(int (*func)()) // Works, however doesn't show up in Visual C#
{
     return 0;
}

更新:

当我从 C# 调用 TEST2 时,出现错误:'TEST2' 不受语言支持

最佳答案

函数指针参数应该这样声明:

int TEST2(int (*func)()) { /*...*/ }

关于c# - C++ 函数作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9641431/

相关文章:

c# - Microsoft分析器为什么找不到Microsoft.CodeAnalysis?

c# - 如何检查 dataRow 中的 dateTime 是否为 Null?

c++ - 在 C++ 中将整数更改为 wstring

delphi - ShareMem/与 Delphi DLL 进行字符串交换

c++ - 如何在宿主程序调用 main() 函数之前构造 DLL 模块中的全局对象?

c# - IsSerializable 为标记为 Serializable 的对象返回 "false"

c# - 如何防止搜索引擎缓存提供的自定义处理程序 "text/plain"类型

c++ - 读取文件

c++ - 如何将字符数组复制到字符串 C++

c++ - 在调试或 Release模式下使用 DLL?