[英]C++ Functions as parameters
I have a DLL containing C++ code, which works perfectly in Visual C#. 我有一个包含C ++代码的DLL,它在Visual C#中完美运行。 When I create a fucton in the C++ DLL, it shows up in Visual C# and I call it, even with parameters.
当我在C ++ DLL中创建一个fucton时,它会显示在Visual C#中,即使使用参数也可以调用它。 However, when I add a function pointer as one of the parameters in the C++ DLL, it cannot be found by Visual C#.
但是,当我将函数指针添加为C ++ DLL中的参数之一时,Visual C#无法找到它。
C++ Functions: 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;
}
UPDATE: 更新:
When I call TEST2 from C#, I get the error: 'TEST2' is not supported by the language
当我从C#调用TEST2时,我收到错误:
'TEST2' is not supported by the language
函数指针参数应该像这样声明:
int TEST2(int (*func)()) { /*...*/ }
我很确定你需要围绕*func
括号来告诉编译器* func是一个指向函数int (*func)()
的指针,而不是你所拥有的int *(*func)()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.