How to implement a callback function using LabView's Call Library Function Node?

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.
The SDK.h deacribes the function as:
//  Function:   SdkSetPropertyEventHandler
SdkError SDKAPI SdkSetPropertyEventHandler(
            SdkCameraRef                    inCameraRef,
            SdkPropertyEvent                inEvnet,          
            SdkPropertyEventHandler         inPropertyEventHandler,
            SdkVoid*                        inContext );
//  Description:
//       Registers a callback function for receiving status
//          change notification events for property states on a camera.
//  Parameters:
//       In:    inCameraRef - Designate the camera object.
//              inEvent - Designate one or all events to be supplemented.
//              inPropertyEventHandler - Designate the pointer to the callback
//                      function for receiving property-related camera events.
//              inContext - Designate application information to be passed by
//                      means of the callback function. Any data needed for
//                      your application can be passed.
//      Out:    None
//  Returns:    Any of the sdk errors.
A separate header file called SDKTypes.h contains the following data:
typedef  SdkUInt32  SdkPropertyEvent;
typedef  SdkUInt32  SdkPropertyID;
typedef  void       SdkVoid;
typedef  struct __SdkObject*    SdkBaseRef;
typedef  SdkBaseRef    SdkCameraRef;
 SdkPropertyEventHandler
typedef SdkError ( SDKCALLBACK *SdkPropertyEventHandler )(
                    SdkPropertyEvent        inEvent,
                    SdkPropertyID           inPropertyID,
                    SdkUInt32               inParam,
                    SdkVoid *               inContext );
Thanks for your help.
Alejandro
Solved!
Go to Solution.

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
Message Edited by rolfk on 02-11-2009 08:00 PM
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions

Similar Messages

  • Have anyone used Labview to call MSP430_Memory function in the MSP430.dll?

    Hi,
    I am trying to read data from Infromation Memory of a MSP430 MCU. I am using MPS-FET430UIF to communicate with the MCU and having trouble to get data using the function MSP430_Memory. Have anyone done this before? I greatly appreciate any help from this forum.

    Good Afternoon,
    I just have a couple of quick questions for you:
    How are you going about calling the dll in LabVIEW?
    Are you using the call library function node?
    Could you post your code so we can take a look at it and get a better idea how you are going about it?
    I hope you have a great rest of the day!
    -Cody C

  • Help to make opencv's dll and LabVIEW's Call Library function node understanding each others

    Hi, i have a little problem trying to use a C++ opencv's dll in labview. I wrote a really simple and stupid dll just to try to understand how it works the call library function node. Here the header code:
    #ifdef GENERICDLL_EXPORTS
    #define GENERICDLL_API __declspec(dllexport)
    #else
    #define GENERICDLL_API __declspec(dllimport)
    #endif
    #include "stdafx.h"
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>
    // Questa classe è esportata da Generic DLL.dll
    class GENERICDLL_API CGenericDLL {
    public:
    int Summ(int a, int b);
    int Sott(int a, int b);
    int opencv(int a);
    // TODO: aggiungere qui i metodi.
     and here the .cpp:
    // Generic DLL.cpp: definisce le funzioni esportate per l'applicazione DLL.
    #include "stdafx.h"
    #include "Generic DLL.h"
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>
    using namespace cv;
    using namespace std;
    // Esempio di variabile esportata
    GENERICDLL_API int nGenericDLL=0;
    // Funzioni esportate.
    GENERICDLL_API int Summ(int a, int b)
    return a+b;
    GENERICDLL_API int Sott(int a, int b)
    return a - b;
    GENERICDLL_API int opencv(int a)
    const string ind = "C:\\Users\\sviluppo\\Desktop\\Tuli.bmp";
    const string ind_2 = "C:\\Users\\sviluppo\\Desktop\\Tuli_Gray.bmp";
    //Mat image;
    return 5;
    i can call all the three simple functions in labview with this easy code. No problem at all. If i uncomment the line "Mat image;" the call library function node doesn't work and i receive the error:
    "The library specified for this node cannot be found or cannot be loaded. Right-click the Call Library Function node and select Configure, then choose the correct library name or path."
    I think that is a problem of dependencies between opencv libraries but i dont know how to manage this. Any ideas?
    Thank you for yours time,
    Francesco.

    Hello Francesco,
    I'm having exactly the same problem as you. I created a DLL that I can easily access from LabView. If I add one line and include "imgproc.hpp" (the only one I need), then LV gives me the same error you had. I read the thread Loura linked to, but I don't see how people actually take care of the dependecies (Klemen's examples did not work for me for the same reason, even though I recompiled the .cpp). Could you explain in detail what you did to make it work?
    Thanks

  • Labview Dll call library function Causing Labview to unload

    I am trying to use the Call Library function in Labview 7.1 to call an Init function for a Zathic Can4USB device. When I run the vi, it complete log LabView out of the computer. Can anyone tell me why the function totally unloads LV without displaying an error?
    Thanks

    Either the function has a serious bug or you are calling it with
    invalid parameters or wrongly setup parameters. The problem happening
    here is that your DLL passes somehow invlid parameters to a system
    device driver and that driver causes a protection fault. For device
    driver execeptions which happen in the privileged kernel, Windows does
    not try to attempt to message a user in such cases (other than the
    threaded blue screen of dead which when you get it really means a full
    restart) but unloads the current application as fast as possible.
    Check the documentation for this function and try to see where you call
    it srong or contact the developer of this DLL for assitence.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Using variants in Call Library Function Node parameters

    Can I use Call Library Function Node to send variant data?
    Attached is a VI. Here's the C code:
    int MM_FUNC mmDaqDll_407DB
        ( IN char *pcUdlPath
        , IN char *pcTableName
        , IN void *pvData
        int nStat = 1;
        //System:bject *varData = ((System:bject *)vData);
        MessageBox(NULL, pcUdlPath, pcTableName, 0);
        return nStat;
    } // mmDaqDll_407DB()
    I get the void pointer. I was hoping for a solution that did not use void*.
    What is the best way to pass void data to a DLL?
    Attachments:
    DaqDllMon407DB.vi ‏18 KB

    Hi Mefitzpatrick,
    Here is a similar forum that addresses this issue:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=48886&requireLogin=False
    They mention using the Adapt to Type property of the function node inputs, have you tried this?
    Let me know if this doesn't answer your question.
    Sappster

  • How to return array of unsigned integer pointer from call library function node & store the data in array in labview

    I want to return array of unsigned integer from call library node.
    If anybody knows please help me
    Thanks & Regards,
    Harish. G.

    Did you take a look at the example that ships with LabVIEW that shows how to do all sorts of data passing to DLLs. I believe your situation is one of the examples listed. You can find the example VI in the "<LabVIEW install directory>\examples\dll\data passing" directory.

  • Calling DLL using "Call library function"

    I am trying to combine labview with my previous fortran functions using Intel Visual Fortran 12.1 and labview 2012 by below steps.
     1. Compile Fortran functions as DLL file.
     2. Call Fortran function from LabView via "Call library function"
    In step 2, DLL file without linker option "/DLL delayimp.lib" cannot be loaded. That is "delay load" is needed for DLL file.
    Are there any limitation or constraint in Call library function?

    Hi Vishnu,
    There's no problem using the Malloc function in C and call it as a DLL in LabVIEW.
    But LabVIEW has a different memory management than C.
    It is probably not recommended to allocate array memory in C for labVIEW arrays
    You can use initialize array in LabVIEW instead.
    Good luck
    Van L
    NI Applications Engineer

  • Using an external DLL with "Call Library Function"

    Hi!
    I am trying to use an external DLL which is used from Visualbasic & Delphi:
    http://www.keb.de/common/tools/KEBCOMDriver.zip
    the protKEB.dll accesses the serial port to control an KEB frequency
    inverter.
    Unfortunatly there is no prototype header file for the DLL (no help on that
    from KEB).
    I only have a VisualBasic example program which works with the DLL.
    (Unfortunatly I am no Visual basic expert)
    To initialize the com port I have to use the function: setprotproperties &
    getprotproperties
    they are declared as:
    'Setting the protocol properties
    'ctrl is a pointer to a data structure of type tProtProperty
    Declare Sub setprotproperties Lib "protkeb.DLL" (ctrl As Any)
    'Reading the protocol properties
    'ctrl is a pointer to a data structure of type tProtProperty
    'the desired protocol is entered in ctrl.prottype before calling
    Declare Sub getprotproperties Lib "protkeb.DLL" (ctrl As Any)
    and tProtProperty is:
    Public Type tProtProperty
    ProtType As Long 'Type of Protocol (tProt)
    TimeOut As Long 'ALL protocols
    Baudrate As Long 'ANSI, HSP5
    Comport As Long 'ANSI, HSP5
    Flag As Long 'ANSI, HSP5: 01 = Sendslow
    / IP: 01 = UDP
    Port As Long 'IPort number
    Txtlen As Byte 'IP : length of following
    text or 0
    txt As String * 100 'IP : IP-Address or name
    (maximum length)
    End Type
    I already tried to use a cluster with tProtProperty entries as an Input for
    the function
    setprotproperty in a call library function with:
    Parameter Type : Adapt to type
    Data Format: Pointer to Handle
    but I always get an "exception within external code....."
    What am I doing wrong?
    How does a cluster & a "call library function node" look like that works?
    Any help is really appreciated!
    thanks
    tom
    ,-Thomas Kerberger Physikalisch-Technische Bundesanstalt-.
    | Abbestr.2-12 D-10587 Berlin fon: +49-30-3481338 |
    | mailto:[email protected] fax: +49-30-3481386 |
    `--------Labor 7.33 Messung thermischer Energie---------'

    Thomas,
    LabVIEW cannot call a DLL that has structures directly, you will need to create either a wrapper DLL or CIN that will take in all of the data individually construct the structure, and send it to the DLL function.
    For more information on what a cluster looks like in native code, I would suggest creating a simple cluster, creating a Call Library Function Node on the block diagram with a cluster input. Then right-click on the Call Library Function Node and choose "Create .c file". This will generate the data structure for the cluster and give you a better feel for it. I would then suggest going to the Using External Code in LabVIEW manual that can be found in the LabVIEW Bookshelf (Start»Programs»National Instruments»LabVIEW 6»LabVIEW Manuals or »LabV
    IEW 6.1»Search the LaBVIEW Bookshelf).
    There is also the following: Developer Zone: Passing a Variety of Data Types from DLL to LabVIEW.
    Randy Hoskin
    Applications Engineer
    National Instruments
    http://www.ni.com/ask

  • How can I debug the Call Library Function at run-time

    I've written a VI using the CLF to call a DLL which was compiled off-site by another engineer using MSVC. Even though the VI runs without flagging any errors, the VI is not doing what I expect. Is there any way of finding out if the DLL is been called correctly? The first function that is called doesn't return any value, but I think that it should. Does this mean that the DLL is not being called correctly? Note also that the DLL works fine with a JAVA GUI.

    Make sure that you are specifying the proper function prototype in the call library function. If you are slightly off the call will not work properly. Ask the offsite engineer to provide you with this data. Another tip is to build the dll with the option to show front panel when called. You can actually popup the dll like you would a subvi. If you design it with test indicators showing on the front panel that is a great way to determine if it is working. Hope this helps.
    BJD1613
    Lead Test Tools Development Engineer
    Philips Respironics
    Certified LV Architect / Instructor

  • Call Library Function (DLL) Node Configuration

    This issue was discussed few times on this forum (see for example http://forums.ni.com/ni/board/message?board.id=170&message.id=182911 ),  but I still have a problem.
    My question is -  how to define the call to DLL without to specify its full path in order to be able to change the directory path without to change all calls to DLL functions within VI.
    So, I did:
    1. I put my DLL and my VI in the same directory.
    2. I defined this directory in VI search path. This directory also defined as enviroment variable.
    3. I use only one call to DLL in this specific VI (just as example in order to simplify the problem).
    4. I define only DLL name without the path in CLF Node.
    But, every time when I close CLF Node configution window, the program search for the DLL, find it and put full DLL path inside.
    I will be very thankful if anyone can help me to overcome this problem.
    Best regards,
    Boris

    Hello Boris,
    To sum up the previous posts, when you specify the DLL when configuring the Call Library Function
    node, internally LabVIEW stores in the VI either 1) the name of the
    DLL, or 2) a relative path from the VI to the DLL (including the name
    of the DLL). What's displayed in the dialog (in 'Library Name or Path'
    field) is either 1) the name of the DLL, or 2) an absolute path that is
    formed by appending the DLL's relative path to the VI's absolute path.
    In
    case 1, LabVIEW uses the Windows system search paths to load the DLL.
    That is, it looks for the DLL in \windows\system32 folder, then if not
    found there, it uses the folders specified in the PATH environment
    variable, etc.
    In case 2, LabVIEW tries to load the DLL from the
    computed absolute path (VIs current path combined with the relative
    path to the DLL that LabVIEW stored internally). And if not found
    there, LabVIEW uses the VI Search Path (that can be set from Tools »
    Options in the category of Paths).
    So even though LabVIEW automatically puts an absolute path to the DLL
    in the Call Library Function Node, as long as you will specify the
    correct folder for the DLL in the VI Search Path, you should be Ok. However, if you want to
    have a fixed location for the DLL, then it is best to keep it in the
    \windows\system32 folder, and specify just the name of the DLL when
    configuring the Load Library Function node (this way LabVIEW will not
    automatically turn it into an absolute path).
    Also, these knowledge base articles might be helpful:
    Why Does My VI Prompt for My DLL Every Time I Open It?
    LabVIEW Searching for a DLL Used in the Call Library Function Node
    My Stand-Alone Executable Cannot Find My DLL, Even Though I Have Specified the Path for the DLL
    Hope this helps and good luck with your application!
    Shakhina P.
    NIC

  • Call library function node - function not found

    When creating a DLL I get a the Labview error "Call Library Function Node "LabviewReceiverDLL.dll:readDataJ1939Data' Function not found. Everything looks correct to me and this used to work, though I've changed computers since then.
    This is the beginning of my C++ code just to show my function name. I've also attached the Call Library Function Window to show my setup.
    Thank you in advance for your help.
    #include"StdAfx.h"
    #include<iostream>
    /* Call Library source file */
    extern"C"__declspec(dllexport)unsignedint readDataJ1939Data(unsignedint, unsignedint, unsignedchar, unsignedchar* canData, unsignedchar* path);
    unsigned int readDataJ1939Data(unsignedint ulTimeStamp, unsignedint ulIdentifier, unsignedchar uiDataCount, unsigned char* canData, constchar* path)
    Solved!
    Go to Solution.
    Attachments:
    Call Library Function.png ‏192 KB

    You mention that you have changed computers and that it used to work before.
    Could it be that there is another (older) copy of the DLL on this computer, and LabVIEW is loading the wrong one?
    The simplest way to check is to close your VI and delete the one you are expecting it to use.  Then open the VI again; if LabVIEW doesn't ask you where the DLL is, it is loading it from somewhere else.
    Batya

  • Call Library Function "Function prototype" incorrect

    Why does the same DLL file produce difference function prototypes?
    I inserted the call library function node in my VI directly. However it has the incorrect function prototype. 
    This call library function node I copied from the “Goodness of Fit.vi”.  This has the correct function prototype.
    Solved!
    Go to Solution.

    The DLL file DOES NOT produce prototypes at all. That is up to you! Look at the parameters tab for both of your examples, you will see that for the second one, someone has already filled in the prototype information. When making a new DLL call, you will need to know the correct prototype to apply, this is usually obtained from the .h (header) file.
    Charles Chickering
    Architecture is art with rules.
    ...and the rules are more like guidelines

  • How to use Call library function node for a function in dll with VOID data type

    Hi All,
    I would like to ask for your kind help,
    I am facing an issue with the call library node.
    I have a C++ function(stdcall), which has void as data type
    error code XXXX(hwnd, lID, getValue, *void data1, *void data2)
    the data1 and data2 types are always changing depending upoin the value of "getValue".
    Primarily i can use call library node multiple times and adapt each node according to the data types of data1 and data2, and extract the values and use in the code. Here is no issue. Real question is:
    My question:
    How can i just use one time call library node and make a case depending upon the "getvalue", which will control the data type of data1 and data2. Here i really looking for solutions.
    My trials:
    i used varaints as input to the call libray node for data1 and data2, and selected Parameters in call libraby node as " Adapt to type". here labview just crashed.
    i really appreciate your feedbackand suggestions.
    Thanks
    Kutbuddin
    Solved!
    Go to Solution.
    Attachments:
    Clipboard02.jpg ‏103 KB

    A variant is a very specific LabVIEW datatype (really a C++ type object internally) and trying to pass that to a function, which excepts a flat memory pointer there, for sure will crash very quickly.
    As to endianess, yes Unflatten will be able to adjust for endianess, which in this case however is most likely exectly NOT what you want. So make sure that the you select native type for the endianess input on Unflatten from String. LabVIEW internally works with whatever is the native endianess, as will most likely your C++ DLL. The platform independent big endian format does only come into play when you receive data streams over some streaming interface like a network connection. Here it is desirable to use an endian format that is independent from the actual platform that generates and consumes the data stream. LabVIEWs default endianes is big endian here.
    But as long as you pass data directly to native components like DLLs there is no difference in endianess between what LabVIEW uses and what those components use.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • LabVIEW PDA reports COREDLL.DLL error when using Call Library Function Node

    I'm trying to build a LV PDA app that calls an external DLL file built using embedded visual C. When configuring the Call Library Function node I select the stub DLL, configure the I/O parameters and select OK. When the configuration dialog closes I get the following error:
    LabVIEW: LabVIEW.exe - Unable to Locate Component
    This application has failed to start because COREDLL.DLL was not found. Re-installing the application may fix this problem.
    I do not get this error when using the configuration dialog in the example VIs.
    Any suggestions as to the cause and/or the solution?
    Thanks,
    Ryan

    Hello -
    When you create a PDA VI that calls a DLL, you must include the .c or .lib file that corresponds to the DLL. Take a look at these documents:
    LabVIEW PDA Module Build Errors with VIs that Call DLLs
    Why Do I Receive Errors When Calling a C++ DLL from a Call Library Node Using the LabVIEW PDA Module...
    How To Call External Code in LabVIEW PDA for Palm OS
    H
    ow To Call External Code in LabVIEW PDA for Pocket PC
    Hope this helps!
    S Vences
    Applications Engineer
    National Instruments

  • Calling DLL function using LabVIEW 7.1?

    Here's the scinario:
    I have LabVIEW 7.1 and i'm trying to call a DLL function using 'CALL LIBRARY FUNCTION NODE'.
    I have used this in the past with no problem. But right now, when I use this node and link it to the
    library and function name, i get 'ERROR loading Dllname.dll' message.
    NOTE that the DLL is generated using VStudio2003 or VStudio.NET. Could this be a problem??
    Also, i noticed that there are some JUNK characters before & after the function name that show
    up in function prototype:
    long ?EcpvsSign@@YAHHPBEH0HPAE1@Z(long Signer, CStr NonRMsg, long NonRMsgLen,
    CStr RMsg, long RMsgLen, CStr SigR, CStr SigS);

    tbd wrote:
    Hi rkpat,
          You might check-out this thread on building WIN32 DLLs - expecially the bit re: "mangles names" under the paragraph titled "C Language Source File".  My recollection is that 'extern "C"' directive in the header file for the DLL solved the name-mangling problem, but it's been a few years!
    Cheers!
    Message Edited by tbd on 03-01-2007 11:19 PM
    tbd is right. You have to first disable name mangling as it creates all kind of troubles. Other issues might be that your Visual Studio 2003 or .Net edition links in dynamic runtime libraries that are not standard available on every Windows PC so that you need to redistribute the according runtime library installer together with your app for the DLL to be even loadable.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

Maybe you are looking for

  • Manual Correction to Raw material/ Inventory a/c

    Guys, When we did  our  initial stock load at the time of implementing sap ECC6.0 .That load went into dummy profit center and  now thousnads of entries with material assignment sitting in dummy.and offset is in initial stock upload a/c , Now we want

  • Add new item in core menu of blog - SharePoint 2013

    Hello All I want to insert new item in core-menu of blog using visual studio just below to "Edit". I want to achieve this using visual studio, not by Javascript. please find below image which will provide you detail idea.

  • Can I speak to a real person?

    Your system invited me to update firefox. I did so. It has now lost my bookmarks. I followed the restore instructions but end with an error message "unable to process the backup file"

  • New Scenario.

    Hai all MM gurus, The client is procuring Excisable  Bulk raw materials on contract basis from Vendor & also have a contract with transporter also to carry the material. 1.The stock should be updated with receipt weight - weighbridge weight. 2.He wan

  • Restoring facebook account on my ipad

    i cannot delete the facebook account on my ipad because i dont know the password. how can i restore my own facebook account to my ipad?