From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to access Call Back Functions using *.dll in the Labview?

Hai,

I am Pavan Ram Kumar Somu.

 

I am new to Labview, currently I am working on MVB Interface.

 

I need to access the API functions from *.dll file in Labview, as of now , I am doing this with Call function Library node in Labview but it does not support the following data types like

    1. Pointer Arguments(To which memory it points in Labview)

    2. function pointers Arguments

    3 .pointers in structures and pointer structures in structures and many other data types.

 

Please Answer the below queries also:

 

1. How to pass pointer arguments to API functions in DLL and how to collect pointer  

    return types from API functions in DLL

 

2. How to pass structure arguments to API functions in DLL and how to collect structure

    return types from API functions in DLL

 

3. How to use callback functions(nothing but function pointers) in Labview and how to

    collect callback fuctions return types from API functions in DLL

 

I need your help while passing these datatypes to API functions in DLL from labview.

 

Suggest me if there is any other alternative for implementing this task.

 

 

I am referencing some examples here:

Examples:

I)

Unsigned short int gf_open_device(void *p_device_config, unsigned long int client_life_sign_timeout, unsigned short int *device_error)

 

void *p_device_config: How to access/pass these arguments in LabView and to which memory location it points in LabView.

 

II) #include <windows.h>

     #include <process.h>

   

     HANDLE rcvEvent0, rcvEvent1;

 

/* Function call*/

CanGetReceiveEvent(handle[0], &rcvEvent0);

 

Above is a piece of C code, Now I want to use HANDLE datatype which is windows based, how to use these type in the LABVIEW.

 

With regards

Pavan Ramu Samu
0 Kudos
Message 1 of 7
(3,226 Views)

"Somu" <x@no.email> wrote in message news:1164102011705-443857@exchange.ni.com...
Hai,


I am Pavan Ram Kumar Somu.


&nbsp;


I am new to Labview, currently I am working on MVB Interface.


&nbsp;


I need to access the API functions from *.dll file in Labview, as of now , I am doing this with Call function Library node in Labview but it does not support the following data types like


&nbsp;&nbsp;&nbsp; 1. Pointer Arguments(To which memory it points in Labview)


&nbsp;&nbsp;&nbsp; 2. function pointers Arguments


&nbsp;&nbsp;&nbsp; 3 .pointers in structures and pointer structures in structures and many other data types.


&nbsp;


Please Answer the below queries also:


&nbsp;


1. How to pass pointer arguments to API functions in DLL and how to collect pointer&nbsp;&nbsp;


&nbsp;&nbsp;&nbsp; return types from API functions in DLL


&nbsp;


2. How to pass structure arguments to API functions in DLL and how to collect structure


&nbsp;&nbsp;&nbsp; return types from API functions in DLL


&nbsp;


3. How to use callback functions(nothing but function pointers) in Labview and how to


&nbsp;&nbsp;&nbsp; collect callback fuctions return types from API functions in DLL


&nbsp;


I need your help while passing these datatypes to API functions in DLL from labview.


&nbsp;


Suggest me if there is any other alternative for implementing this task.


&nbsp;


&nbsp;


I am referencing some examples here:


Examples:


I)


Unsigned short int gf_open_device(void *p_device_config, unsigned long int client_life_sign_timeout, unsigned short int *device_error)


&nbsp;


void *p_device_config: How to access/pass these arguments in LabView and to which memory location it points in LabView.


&nbsp;


II) #include &lt;windows.h&gt;


&nbsp;&nbsp;&nbsp;&nbsp; #include &lt;process.h&gt;


&nbsp;&nbsp;&nbsp;


&nbsp;&nbsp;&nbsp;&nbsp; HANDLE rcvEvent0, rcvEvent1;


&nbsp;


/* Function call*/


CanGetReceiveEvent(handle[0], &amp;rcvEvent0);


&nbsp;


Above is a piece of C code, Now I want to use HANDLE datatype which is windows based, how to use these type in the LABVIEW.


&nbsp;


With regardsPavan Ramu Samu



Search the forum (forums.ni.com) for callback, pointer or handle, and you'll find that it is all possible, but not very easy.


e.g.: http://forums.ni.com/ni/board/message?board.id=170&message.id=88974&requireLogin=False


Regards,


Wiebe.



0 Kudos
Message 2 of 7
(3,209 Views)
Hai
 
Please tell me how to proceed for this function in Labview using dll..
Exact problem is we need to pass a variable of type function pointer as an argument to the API function in dll file.
 
GF_RESULT FunctionDef gf_set_device_status_callback (GF_DEVICE_STATUS_CALLBACK device_status_callback)
{
GF_RESULT   result = GF_OK;
   /* set global variable */
   cgf_device_status_callback = device_status_callback;
   return (result);
}
 
Note:
GF_RESULT is nothing but unsigned short
 
GF_DEVICE_STATUS_CALLBACK is a function pointer----
typedef void (*GF_DEVICE_STATUS_CALLBACK)
(
   GF_DEVICE_STATUS  device_status
);
Regards
Pavan
0 Kudos
Message 3 of 7
(3,167 Views)

"Somu" <x@no.email> wrote in message news:1165322407066-449789@exchange.ni.com...
Hai
&nbsp;
Please tell me how to proceed for this function in Labview using dll..
Exact problem is we need to pass a variable of type function pointer as an argument to the&nbsp;API function in dll file.
&nbsp;
GF_RESULT FunctionDef gf_set_device_status_callback (GF_DEVICE_STATUS_CALLBACK device_status_callback){ GF_RESULT&nbsp;&nbsp; result = GF_OK;
&nbsp;&nbsp; /* set global variable */&nbsp;&nbsp; cgf_device_status_callback = device_status_callback;
&nbsp;&nbsp; return (result);
}
&nbsp;
Note:
GF_RESULT is nothing but unsigned short
&nbsp;
GF_DEVICE_STATUS_CALLBACK is a function pointer----
typedef void (*GF_DEVICE_STATUS_CALLBACK)( &nbsp;&nbsp; GF_DEVICE_STATUS&nbsp; device_status);
Regards
Pavan


Hi,


The easiest way is to build a dll (with the application builder). In it, there is a vi that has the expected protocol of the function. Now you need to get a pointer to the function with the windows API's LoadLibrary (path to the dll, passed as string) and GetProcAddress (with the function name). This will get you a pointer to the function. Use FreeLibrary to release the dll.


Regards,


Wiebe.



0 Kudos
Message 4 of 7
(3,161 Views)
Wiebe@CARYA , can you tell me you email , i have something to ask you .My email :felix2002@tom.com,thank you ?
 
the problem:
Using VC++, I have gotten the handle of a *.exe(built by Labview), but I cannot get the button handle. I want to get the button handle and post the message to control the button. How can I do that? When I use the SPY++, the *.exe(built by Labview) have not any child windows which is very different from the *.exe(built by VC++). In SPY++, what is the LVDChild class? How can I send the message to control the button on *.exe(built by Labview)???
0 Kudos
Message 5 of 7
(3,099 Views)

"hummingbird" <x@no.email> wrote in message news:1165912808393-452739@exchange.ni.com...
<a href="mailto:Wiebe@CARYA" target="_blank">Wiebe@CARYA</a> , can you tell me you email , i have something to ask you .My email :felix2002@tom.com,thank you ?
&nbsp;
the problem:
Using VC++, I have gotten the handle of a *.exe(built by Labview), but I cannot get the button handle. I want to get the button handle and post the message to control the button. How can I do that? When I use the SPY++, the *.exe(built by Labview) have not any child windows which is very different from the *.exe(built by VC++). In SPY++, what is the LVDChild class? How can I send the message to control the button on *.exe(built by Labview)???


Just add .nl to get my email.


LabVIEW doesn't use windows controls (so it can be platform independent). So you can't send messages to a button to click a button. You could send mouse click events to the window.


The proper way to do it would be to open an application reference (with ActiveX) to the LabVIEW exe, and get a vi reference, and use vi server to raise a value signalling event. That is all new to me though.


Regards,


Wiebe.


0 Kudos
Message 6 of 7
(3,094 Views)
Another cool solution using .Net can be found here
 
Thanks
Karsten
Message 7 of 7
(3,046 Views)