ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calling RegisterDeviceNotification function

Hello Everyone, 

I need some help to figure out how to call this function from Labview. 

Details about the prototype are found here

I know how to use the call library function but I can't figure out how to wire one of the parameters that happens to be a struct _DEV_BROADCAST_DEVICEINTERFACE( here)

In C++, what I am trying to do translates into this code :

DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
       
    GUID_CLASS_USB_DEVICE.Data1 = 0xA5DCBF10L;
    GUID_CLASS_USB_DEVICE.Data2 = 0x6530;
    GUID_CLASS_USB_DEVICE.Data3 = 0x11D2;
    GUID_CLASS_USB_DEVICE.Data4[0] = 0x90;  
    GUID_CLASS_USB_DEVICE.Data4[1] = 0x1F;  
    GUID_CLASS_USB_DEVICE.Data4[2] = 0x00;  
    GUID_CLASS_USB_DEVICE.Data4[3] = 0xC0;  
    GUID_CLASS_USB_DEVICE.Data4[4] = 0x4F;  
    GUID_CLASS_USB_DEVICE.Data4[5] = 0xB9;  
    GUID_CLASS_USB_DEVICE.Data4[6] = 0x51;  
    GUID_CLASS_USB_DEVICE.Data4[7] = 0xED;  

    NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
    NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    NotificationFilter.dbcc_classguid = GUID_CLASS_USB_DEVICE;


    RegisterDeviceNotification(hWnd, &NotificationFilter,
        DEVICE_NOTIFY_WINDOW_HANDLE);  

I know how to get the hanlde to the Vi window and pass it as argument to the function. but I can't find a way to create the struct that I have to pass as second argument. 

 

Any help will be greatly appreciated. 

 

Thanks

AJ

 

0 Kudos
Message 1 of 4
(3,957 Views)

I went through many posts of this forum that were related to my questions and tried putting something together to properly call this function.

I tried wiring a cluster that matches the Struct datatype required by the function. My efforts were not successful as the function appears to be reporting NULL. ( according to MSDN, 

If the function fails, the return value is NULL. To get extended error information, call GetLastError.)

 

I get this error when I call the kernel32.dll

GetLastError(void);

ERROR_INVALID_DATA

13 (0xD)

The data is invalid.

 

My code is attached. any help or guidance is really appreciated. 

 

thanks

AJ

 

0 Kudos
Message 2 of 4
(3,935 Views)

I just realized that some may need a prior version lf labview. I attached v 8.6 here

0 Kudos
Message 3 of 4
(3,885 Views)

Hi mam1nej,

Are you able to successfully run the C++ code you wrote and call the kernel32.dll in C++? Also, are you able to run your code using an example code? There is a code called External Code (DLL) Execution.vi that is located under Help >> Find Examples... on your LabVIEW splash screen, and you can find it by searching for the keyword "DLL". 

Also, here's some information on using cluster data types in LabVIEW: http://www.ni.com/getting-started/labview-basics/data-structures#Clusters

Let me know what your results are and if this is helpful!

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 4
(3,834 Views)