02-11-2009 11:10 AM
Solved! Go to Solution.
02-11-2009 12:59 PM - edited 02-11-2009 01:00 PM
alejandroandreatta wrote:
I am trying to call a fuction from a SDK.dll library using the Call Library Function Node. The SDK was provided to
me and I do not have the source code, just the .dll and .h files.
The SdkSetPropertyEventHandler function has a callback fuction as one of its parameters. How do I implement the
callback using the CLF node? I am a good LabView programmer but this is my first time using the Call Library
Function Node. I have read all the info I can find on NI's web site and the discussion board but cannot figure
this one out. I am using LabView 8.6.
Basically you do not do that. LabVIEW does not know pointers and certainly not function pointers. What you should do instead is writing a C DLL that implements the callback and also exports a function to be called by LabVIEW that translates between the callback and a LabVIEW user event. Look for PostLVUserEvent() here on the NI site to find examples how to do that.
Rolf Kalbermatter
02-12-2009 11:24 AM
Hello,
All you have to do is point the call library function at your dll and input the correct parameters. The correct inputs would be inCameraRef,inEvnet,inPropertyEventHandler,inContext . There are no outputs the the SdkSetPropertyEventHandler. Try running and looking at this vi to see how the Call Library Function calls functions from a dll. Make sure you find out what calling convention your dll uses. If you don't know off hand you may just want to change it, if your call does not work correctly.
02-12-2009 12:47 PM
Andrew_E. wrote:Hello,
All you have to do is point the call library function at your dll and input the correct parameters. The correct inputs would be inCameraRef,inEvnet,inPropertyEventHandler,inContext . There are no outputs the the SdkSetPropertyEventHandler. Try running and looking at this vi to see how the Call Library Function calls functions from a dll. Make sure you find out what calling convention your dll uses. If you don't know off hand you may just want to change it, if your call does not work correctly.
inPropertyEventHandler is a callback function pointer. Nice trick if you get the Call Library configuration dialog to create the right parameter for that!!!!!!
Rolf Kalbermatter
02-13-2009 09:39 AM
Hi Rolfk,
You are completely right. Does this article describe what you were talking about? I am just trying to get as much information on this thread as possible so the solution is easier to find for the future. Thanks.
02-13-2009 01:24 PM
Andrew_E. wrote:Hi Rolfk,
You are completely right. Does this article describe what you were talking about? I am just trying to get as much information on this thread as possible so the solution is easier to find for the future. Thanks.
Yes, but I find the idea to use .Net to call a LabVIEW VI as C callback function a bit like using a steam roller to iron your pants. Why do it? Well the steam roller has some extra safe guards that make it less likely that you crash your pants in the process but it is not elegant IMHO.
Writing a C DLL that translates between a C callback and a LabVIEW user event using the PostLVUserEvent() interface function from the LabVIEW runtime kernel seems so much eleganter to me. Yes it is a bit of C programming but hey!
Rolf Kalbermatter
02-19-2009 04:39 PM
Rolf and Andrew,
Thank you for the advice. I will look for a C programmer to write the wrapper to the DLL and make it more accessible to LabView.
Alejandro
06-19-2009 12:31 AM
Hi Alejandro
did you succeed?
I've been having a very similar problem; I got to solve part of it.
http://forums.ni.com/ni/board/message?board.id=170&message.id=416425&query.id=1271894#M416425
I ended up writing the callback function in C, and then using Wiebe's subVIs to get the function pointer.
Maybe it helps.
At first I was so confused about function pointers, found a decent tutorial here.
-Javier
03-22-2010 08:00 AM
Rolf,
I've been searching for info on how to use the PostLVUserEvent(), but have only found one page on the NI site that gives a brief explanation
http://zone.ni.com/reference/en-XX/help/371361F-01/lvexcode/postlvuserevent/
I can't it anywhere in my LV directory (LV2009). Can you point me to some information on how to use this call?
George
03-22-2010 08:18 AM