<< Click to Display Table of Contents >> Navigation: NmxDLL Reference Guide > API (programming interface) > Notifications > NMX_RegisterCallback_1 |
This function is used to register a notification callback function at the DLL.
Definition
NMX_STATUS NMX_RegisterCallback_1(
NMX_PHANDLE pHandle,
unsigned long ulNotification,
NMX_NOTIFICATION_CALLBACK* pCbFunction,
void* pvContext);
Parameter
pHandle
ulNotification
Notification type, e.g. NMXNOTIFY_NEW_STATIC32.
pCbFunction
Pointer to callback function.
pvContext
A caller provided context pointer which is passed unchanged to the callback function.
Typical function call (C example)
RegisterCallback_1(pHandle, NMXNOTIFY_NEW_STATIC32, &Callback_NewStatic32, (void*)&ulCallbackContext);
Comments
If pCbFunction is NULL, a registered callback will be cleared.
Callback function
This function is the prototype for a callback notification.
Definition
void NMX_CALLCONV NMX_NOTIFICATION_CALLBACK(IN void* pvContext);
Parameter
pvContext
This parameter is the same which was passed to the function NMX_RegisterCallback_1. The application can store a context information in this pointer.
.Net DLL specific implementation
NMX_MSTATUS RegisterCallback_1(
System::IntPtr pHandle,
NMX_NOTIFICATION eNotification,
OnNotification^ NotificationDelegate);
NMX_NOTIFICATION is an enum type, which is defined in the .Net - DLL. The available notifications are identical to the standard notifications, except that they don't have a fixed binary representation.
In .Net, delegates are used instead of function pointers. The .Net - DLL calls this delegates in case of a notification.
In C#, an example for a delegate function is:
public void OnNewStaticData(IntPtr pHandle)
{
}
The handle of the calling DLL-instance is provided as a function parameter. If you have only one instance (= 1 connection to a device), don't care about it. This is the most common case.
In case you have multiple instances, the handle can be used to distinquish between multiple connections.
An example for registering the delegate is:
cNmx.RegisterCallback_1(pDevice, NMX_NOTIFICATION.NEW_STATIC32, OnNewStaticData);
Note: Since the delegate is directly forwarded to the unmanaged DLL, the .Net wrapper fixes the delagte pointer in the garbage collector (gc.Alloc).
Comments
This function is called in a different thread context. The application must handle the synchronisation.