110,499
社区成员
发帖
与我相关
我的任务
分享
[DllImport("StaticDll.dll", CharSet = CharSet.Ansi, EntryPoint = "CreateDlgEx", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int CreateDlgEx(int na);
[DllImport("StaticDll.dll", CharSet = CharSet.Ansi, EntryPoint = "AcceptDataEx", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int AcceptDataEx(byte[] sBuf, int nLen, int nType);
[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);
3.最后实例化委托,调用 EnumWindows。
CallBack myCallBack = new CallBack(EnumWindowsApp.Report);
4.完全代码如下:
using System;
using System.Runtime.InteropServices;
public delegate bool CallBack(int hwnd, int lParam);
public class EnumWindowsApp
{
[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);
public static void Main()
{
CallBack myCallBack = new CallBack(EnumWindowsApp.Report);
EnumWindows(myCallBack, 0);
}
public static bool Report(int hwnd, int lParam)
{
Console.Write("Window handle is :");
Console.WriteLine(hwnd);
return true;
}
}
dataArrive = new TXYS_DataArriveHandler_t(this.fDataArriveHandler);
TXYS_RegDataArriveEventHandler(dataArrive);//注册回调函数
public static extern void TXYS_RegDataArriveEventHandler(TXYS_DataArriveHandler_t fHandlerFunc); //注册数据到来
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void TXYS_DataArriveHandler_t(ref byte sBuf, int nLen, int nType);
TXYS_DataArriveHandler_t dataArrive;
public void fDataArriveHandler(ref byte btData1 , int nLen, int nType)
{
byte [] btData=new byte [nLen];
Marshal.Copy(btData1, btData, 0, nLen);
}
这是回调函数声明及定义部分 高手请指点 谢谢