程序.cs
class Program
{
public static void He(string v)
{
Console.WriteLine(v);
Console.WriteLine("End?");
}
public delegate void he(string v);
static void Main(string[] args)
{
Class1 cls = new Class1();
IntPtr p = Marshal.GetFunctionPointerForDelegate(new he(He));
cls.call(p, "String");
}
}
测试类库.h
namespace TestClassLibrary
{
typedef void (Hello)(System::String ^ v);
public ref class Class1
{
public:
void call(IntPtr p,System::String ^v);
};
}
测试类库.cpp
namespace TestClassLibrary
{
void Class1::call(IntPtr p,System::String ^ v)
{
Hello * h = (Hello *)p.ToPointer();
h(v);
}
}
我不知道这段代码有什么问题:(
(测试类库被编译为托管 DLL。)