LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to deal with the callback when I invoke a C++ dll using CLF?


"paulbin" <x@no.email> wrote in message news:1174669809514-496598@exchange.ni.com...
The prototype is like this:
&nbsp;
WORD SetCallback(WORD comHandle, (*callback)(int, int) Callbackfunction), the callbackfunction should be work when the COM1 port has a DTR change, I guess SetCallback monitor this change, maybe, in fact, I must write a Callbackfunction by VI, the custom do not have a Callbackfunction to deal with DTR change event. So, SetCallback is in dll but Callback function is some VI code.
&nbsp;
This method is one of a group function in a dll, there are two functions can not work in all of them.
&nbsp;
The first is SetCallback due to I can not integrate the SetCallback in dll and Callback in VI.
&nbsp;
Another question is another function's prototype is WORD SetTestType(WORD comHandle, bool type1, bool type2, bool type3),&nbsp;&nbsp; I tried to use a boolean control and a Boolean to (0,1) node in labVIEW to pass parameters to CLF, I config the bool input value as U8(according to C++ bool type) and U32(according to WIN32 BOOL type), it dose not help, when I execute the VI, LabVIEW will be disappeare, it seems to be closed, I must start it again.
&nbsp;
Could someone has similar experience on this points?



The easiest way to do this is to build a dll with LabVIEW that interacts with your LabVIEW code, e.g. with a user event, or a buffer.


Export the read/write function to access the buffer.
Export the callback VI according the prototype.
Compile the dll.
In LabVIEW get a pointer to the LabVIEW dll function with the windows APIs LoadLibraryA, and GetProcAddressA.


There is a bug in LabVIEW. LabVIEW hangs when you run a dll function created in LabVIEW within the first 2 ms after the application started. So if you compile your code to an exe, and the exe runs the labview dll immediately, it will hang.


Regards,


Wiebe.




Message 11 of 13
(1,009 Views)

Hi all,

 I realise this is an old posting, but I wanted to share a solution that someone has found and posted on another website :

http://msmvps.com/blogs/vandooren/archive/2006/11/16/executing-labview-vis-through-c-style-function-...

The proof as they is in the pudding so give it a try and see what happens.

Much thanks to vanDooren for this. Much Much thanks

Sacha Emery
ATE Systems Engineer
National Instruments (UK and Ireland)

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 12 of 13
(865 Views)

[Edit] Ooops - missed the link on the first page of this - the "Here" link. (Sorry tbd)

The demo code for this article is available under the MIT license as usual. (Just to cover posting the code here aswell)

Sacha Emery
ATE Systems Engineer
National Instruments (UK and Ireland)


// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 13 of 13
(863 Views)