我有一个本机 api 函数,如下所示:
DWORD WINAPI WlanRegisterNotification(
__in HANDLE hClientHandle,
__in DWORD dwNotifSource,
__in BOOL bIgnoreDuplicate,
__in_opt WLAN_NOTIFICATION_CALLBACK funcCallback,
__in_opt PVOID pCallbackContext,
__reserved PVOID pReserved,
__out_opt PDWORD pdwPrevNotifSource
);
我已将其翻译为 C#:
[DllImport("Wlanapi.dll", EntryPoint = "WlanRegisterNotification")]
public static extern uint WlanRegisterNotification(
IntPtr hClientHandle, WLAN_NOTIFICATION_SOURCE dwNotifSource,
bool bIgnoreDuplicate, WLAN_NOTIFICATION_CALLBACK funcCallback,
IntPtr pCallbackContext, IntPtr pReserved,
[Out] out WLAN_NOTIFICATION_SOURCE pdwPrevNotifSource);
回调函数如下所示:
typedef VOID ( WINAPI *WLAN_NOTIFICATION_CALLBACK)(
PWLAN_NOTIFICATION_DATA data,
PVOID context
);
我猜 C# 版本看起来像:
public delegate void WLAN_NOTIFICATION_CALLBACK(
IntPtr pWlanNotificationData, IntPtr pContext)
基本上我有两个问题:
委托是用于需要函数指针的本机方法的正确对象吗?
如果是这样,这会在收到通知时自动调用 c# 中的委托吗?