I would like to have a way to make a call to a method of a reference class which takes a native argument. Creating a delegate seems the most obvious choice but it doesn't work with such methods.
Please have a look at following snippet
#pragma managed(push, off)
struct Native{};
#pragma managed(pop)
#pragma managed(push, on)
ref struct Managed{
// methods of managed class can take...
void method1(int){} // ...value types as an argument
void method2(System::String^){} // ...reference types as an argument
void method3(Native){} // ...native types as an argument, NICE!
};
int main(array<System::String ^>^ /*args*/) {
Managed^ m = gcnew Managed;
auto del1 = gcnew System::Action<int>(m, &Managed::method1); // ok
auto del2 = gcnew System::Action<System::String^>(m, &Managed::method2); // ok
auto del3 = gcnew System::Action<Native>(m, &Managed::method3); // error C3225: generic type argument for 'T' cannot be 'Native', it must be a value type or a handle to a reference type
}
#pragma managed(pop)