When I call a the C++ function:
public ref class TEST_CLASS
{
void TEST(void (*func)())
{
(*func)()
}
};
in C#:
TEST_CLASS t = new TEST_CLASS();
t.TEST(f);
I get the error:
‘TEST’ is not supported by the language
What would be causing this error? How can I fix it?
That’s not C++ code, you wrote a C++/CLI class. Note the ref class keyword. You declared the method to take a C function pointer. That’s fine in the C++/CLI language, it lets you mix native and managed code constructs, but not fine to a language like C# or VB.NET. They insist that you use the managed version of a function pointer, a delegate.
There’s already a delegate type in the .NET framework that matches the signature of your C function pointer, MethodInvoker. But let’s assume you want to extend on the signature and add, say, your own arguments and return type:
Picking that name kinda hurt.