主界面是 Form1。现在有一个DLL提供了回调函数,这个回调函数:
public delegate Int32 readData(Int32 length);private static NativeMethods1.readData rd = new readData(onReadData);public static Int32 onReadData(Int32 length)
{
// 怎样在这个静态函数里面访问主界面Form1?
return 0;
}
public delegate Int32 readData(Int32 length);private static NativeMethods1.readData rd = new readData(onReadData);public static Int32 onReadData(Int32 length)
{
// 怎样在这个静态函数里面访问主界面Form1?
return 0;
}
public static Form TempForm
{
get;set;
}public static Int32 onReadData(Int32 length)
{
if(TempForm == null) return;
//操作
TempForm = null;
return 0;
}每次调用前对TempForm赋值。
{
// 怎样在这个静态函数里面访问主界面Form1?
return 0;
}
// 这个函数写在主窗体里面。然后在窗体的构造函数或者formload里面,把这个函数传递给dll委托,这样就可以在dll里面调用了。
我想把主窗口实例传递给DLL,然后DLL回调的时候把这个示例一起回调上来,但是该怎么传递呢?应该用intptr 吧,, this没法转换成intptr啊。
你程序中反射找到这个方法调用之,吧自己窗体传递进去。