Vi reference = function pointer for external DLL?

So I'm porting this simple program from C to LabVIEW. All it does is getting some signals from an haptics hardware (Sensable Phantom Omni). It should be simple, but it has shown several complications. (been stuck for 2 weeks )
I successfully imported the hardware's DLL with all of its functions (using LV 8.2, because 8.5 and 8.6 's wizard sucks).
But there is a function whose argument is a function pointer:
hUpdateHandle = hdScheduleAsynchronous(updateDeviceCallback, 0, HD_MAX_SCHEDULER_PRIORITY);
 I already have the corresponding VI for updateDeviceCallback (which gets a (void *) that does not really use, and returns an int).
hdScheduleAsynchronous is part of the hardware's API (I can't mess with it, nor I know what's inside), and as first argument expects a function pointer.
Can I use the Open VI reference node to get the 'pointer' for my VI and then feed it as an argument for the external DLL? How do I properly cast the VI ref datatype into a function pointer?
Solved!
Go to Solution.
Attachments:
QueryDevice.c ‏9 KB
updateDeviceCallback.vi ‏14 KB

JavierRuiz wrote:
So I'm porting this simple program from C to LabVIEW. All it does is getting some signals from an haptics hardware (Sensable Phantom Omni). It should be simple, but it has shown several complications. (been stuck for 2 weeks )
I successfully imported the hardware's DLL with all of its functions (using LV 8.2, because 8.5 and 8.6 's wizard sucks).
But there is a function whose argument is a function pointer:
hUpdateHandle = hdScheduleAsynchronous(updateDeviceCallback, 0, HD_MAX_SCHEDULER_PRIORITY);
 I already have the corresponding VI for updateDeviceCallback (which gets a (void *) that does not really use, and returns an int).
hdScheduleAsynchronous is part of the hardware's API (I can't mess with it, nor I know what's inside), and as first argument expects a function pointer.
Can I use the Open VI reference node to get the 'pointer' for my VI and then feed it as an argument for the external DLL? How do I properly cast the VI ref datatype into a function pointer?
LabVIEW has no concept that can translate seemlessly to function pointers and there is certainly no sensible way to make the Call Library Node support something like this.
There are possibilities to create a DLL from your callback VI and import the function using Windows API calls to pass it as a function pointer to your other function. But this is involved and quite dirty and most importantenly a total nightmare to maintain, since things go completely awry if your DLL is created in a different LabVIEW version than the LabVIEW version you call it with. This may seem like a piece of cake now but whoever will have to upgrade your software to a new LabVIEW version later will love you to the point that they will feel like sending you as the original programmer a nice little present that blows in your face when opened 
The only feasable way is to write a wrapper DLL in C that translates between something more LabVIEW friendly like a user event and the actual callback function mechanisme.
Rolf Kalbermatter
Message Edited by rolfk on 06-09-2009 10:24 AM
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions

Similar Messages

  • Exporting symbols in a .exe for external DLLs

    Hello, 
    I am facing a strange problem.
    Basically, I have my application that loads a DLL (I developped).
    My DLL exports functions I can call from my application : OK
    I would also like to call functions of my application from my DLL : it does not work.
    To do that, in my DLL, I call :
    HMODULE hModule = GetModuleHandle("application.exe");
    FARPROC hFunc = GetProcAddress(hModule, "appFunction"); // (defined by : void __declspec(dllexport)  appFunction(void) in my application
    hModule is non-zero but hFunc is NULL. When I use a tool to see exported symbols by application.exe, there is none.
    So my question is : Can I export symbols from a .exe with LabWindows 8.5 ?
    thanks in advance
    Solved!
    Go to Solution.

    Thank you for your answer,
    I had already tried with :
    HMODULE hModule = LoadLibrary("application.exe");  
    and
    HMODULE hModule = LoadLibraryEx("application.exe", NULL, 0);  
    it gives the same result.
    To be more precise here is the source code of dll.dll :
    #include <Windows.h>
    #include <stdio.h>
    typedef void(*APPLI_PRINTF7)(void);
    __declspec(dllexport) void dllFunction(void)
    HMODULE hModule = LoadLibrary("application.exe");
    FARPROC pFunc = GetProcAddress(hModule, "appli_printf7");
    if(pFunc)
    ((APPLI_PRINTF7)pFunc)();
    else
    printf("error = %d\n", GetLastError());
    return;
     and here is the code of application.exe
    #include <Windows.h>
    #include <stdio.h>
    typedef void(*DLL_FUNC)(void);
    __declspec(dllexport) void appli_printf7(void)
    printf("7");
    return;
    int main(void)
    HMODULE hModule = LoadLibrary("dll.dll");
    FARPROC pFunc = GetProcAddress(hModule, "dllFunction");
    ((DLL_FUNC)pFunc)();
    return 0;
    I compiled dll.dll once and for all with LabWindows (8.5), and I compiled exactly the same code for application.exe with LabWindows (8.5) and Visual Studio 2013.
    It works with Visual Studio (the dll finds appli_printf7 and 7 is printed on the screen), but doesnt with LabWindows (the dll does not find appli_printf7 and prompt the error 127 (The specified procedure could not be found.)).
    I used Dependency Walker (and dllexp to confirm) to find out that appli_printf7 is actually NOT exported with LabWindows, and is exported with Visual Studio.
    Therefore, it is normal that the dll can't find the symbol if it is not exported.
    My questions are :
    - Why is that so ???
    - Is there a setting to set in order to make LabWindows export symbols marked by __declspec(dllexport) for .exe projects ?
    - Is this a problem fixed with a newer version of LabWindows ?
    - My dll is actually a plugin to my application. If I can't load symbols from my application, how can I provide an API for my dll in order to make generic functions available to it ? Is there a workaround for it ?
    Edit : I tried with LabWindows 2012, same problem..
    Thanks in advance 

  • How to configure OWA in multiple AD sites when using one entry point for external OWA clients ?

    Using Exchange 2013 (e2013), SP1.
    Three locations.  (Let's say  Location-A, -B, and C.)
    Each Location is an AD site, and physically "remote" from the others.
    Each location will have one e2013 server,  each server running both CAS and Mailbox function.
    The main location ( LOC-A) is where all external OWA and EAS will "enter" from the Internet, via a firewall.
    The E2013 server there will "connect" (?) to the e2013 server for "this mailbox",...at any of the 3 locations.
    What "special" configuration do we need on the 2 remote/other e2013 servers for OWA virtual directory (or similar).
    It looked like it was working "out of the box".
    Some users work OK, with no special changes to anything.
    But some users have OWA in a "never ending wait" (browser appears to spin forever), 
    and that might be due to a different Language at the other locations.
    I guess Exchange knows how to "internally route" the OWA traffic from the LOC-A CAS to the LOC-B CAS.
    (In Exchange 2007 we called this "Exchange CAS proxy" as I recall, but not sure that term is correct in e2013.)
    Thanks.
    ==

    Hi,
    L-A
    L-B
    L-C
    User-A
    User-B
    User-C
    Mailbox-A
    Mailbox-B
    Mailbox-C
    CAS-A
    CAS-B
    CAS-C
    Exchange-A
    Exchange-B
    Exchange-C
    User-A logon OWA in L-B.
    Based on my knowledge, if User-A logon OWA in L-B, CAS-B would accept the request first.
    Then it detect the User-A's mailbox located in L-A. CAS-B will proxy this request to CAS-A.
    I find a great blog for your reference:
    Client Connectivity in an Exchange 2013 Coexistence Environment
    http://blogs.technet.com/b/exchange/archive/2014/03/12/client-connectivity-in-an-exchange-2013-coexistence-environment.aspx
    Thanks
    Mavis Huang
    TechNet Community Support

  • Why is my deployed application not executing functions from an external .dll?

    My application executes python scripts via function calls made to the python C/API, python24.dll.  It works fine in the development environment, but my deployed application does not seem to find the .dll since the the application crashes at what seems to be the first attempt to access the python shared library.
    I believe I've included all the necessary support files.  LV automatically included python24.dll into the installer.  And I've tried to make all the paths to script files and other support files point to where the app.exe is located...some debugging windows have shown the paths to be correct in the deployed app.  The call library function nodes are configured to find the python .dll in the win\system32 folder.
    I feel like I'm missing some step in the build process since it works in the development environment, but perhaps there is some other trick using CLFN's that I don't understand.
    I using LV7.
    Thanks.

    Hello CraigerB,
    It seems like you are doing everything the right way. Click on the following link for a related discussion forum post.
    Here is what you can try:
    1. Place the dll in the C:\WINDOWS\system32 on your development machine.
    2. Make sure your Call Library Function Node VI is pointing to C:\WINDOWS\system32\python24.dll
    3. Build your executable
    4. LabVIEW will not make a copy of your python24.dll because it will treat it differently
    5. Manually copy the python24.dll to the target PC's C:\WINDOWS\system32\
    6. Make sure you have all supporting files for your python24.dll to insure the dll itself is working.
    7. If you are using relative paths to call your dll, switch to hard paths, or take a look at this KB for relevent information.
    Hope this helps!
    Kalin T.
    National Instruments

  • Commit Function Module for External System ?

    Hi Gurus,
    I am using RFC - RFC_UPDATE_TAXES_DOC to post documents into External System.
    After I post those documents how to execute Commit fucntion in the external system.
    My Try:
    Will I be able to commit using BAPI_TRANSACTION_COMMIT -
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' DESTINATION gc_external_system.
    Many Thanks,
    Madan

    Yes.
    It should work, b'coz BAPI_TRANSACTION_COMMIT is itself a RFC func module.
    Regards,
    Subramnaian

  • Can't set up share point for external drive on Xserve

    I have an iomega 2TB drive connected to an Xserve. I can not seem to access the ext. drive from a client machine. I've been able to do this in the past, now it doesn't show up as one of the mountable drives when I connect to server.
    I CAN see it if I remote in to the sever. On the server desktop, the ext. drive is mounted. I can access it there, see folders inside and everything. However, if I look in the Server app, from a client machine, the ext. drive shows up in the list of volumes, but the disk space bar is all gray (no green, yellow or red) as if it's not readable. I know this is kinda hard to describe, but the bottom line is that I can't access my ext. drive that is attached to the Xserve.

    Alex has hit all the right notes in his response and the one that I'd agree with would be the planning.  It's not uncommon to hear stories of firms putting SharePoint in, before they get around to thinking what to do with it.  It is a collaborative
    product that can provide answers to defined problems.
    On the SharePoint workspace issue, my personal thought would be give it a miss.  It doesn't have a 2013 version and it'll be pointless giving this to your user base, only to have to remove it depending on what your settled SP plans might be.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Wrapper for invoking external DLL-function

    I want to run a Host-Command (e.g. rwrun60 report=xyz.rdf batch=yes) invoked by a trigger that fires when a new record is inserted.
    I wrote a DLL which has an exported function that accepts a commandline (with parameters) and invokes the command via ShellExecute.
    The problem is, that when i invoke the PL/SQL-wrapper, the DLL-function is properly run, but the program i want to run is only visible in the taskmanager(NT) and does nothing.
    So what i need is a correct wrapper for the function:
    DLL-function: OExecSysCmd(cmdLine *char)
    Wrapper:
    PROCEDURE OExecSysCmd(p_SysCmd in char)
    IS EXTERNAL
    NAME "OExecSysCmd"
    LIBRARY demolib;
    Thanks in advance
    Dannys

    Hi Russ,
    with "invoke an external dll" I mean that I have to wite a log file to register my fdk client events and to do this I have to use an external dll wich exposes some functions to write to a common log file. I have imported the external dll in my client project and at the beginning of client code I have included the dll header file:
    #include "LogDll.h"
    Then I've tried to invoke a LogDll function (not within F_ApiInitialize (), but in a custom dialog box event):
    int retval=LogDllFunction();
    The code compiles, but if I start FM, I receive the message error. If I comment the line above, FM and my client start normally.
    Thanks,
    Stefano

  • CVI crashes when calling function from external DLL

    I'm calling a CVI library from Test Stand 4.1.  In that CVI library I load an external DLL (using LoadLibrary) and create a few function pointers (using GetProcAddress).  The DLL loads successfully, and I get addresses for all of the imported functions.  
    However, when I one of the functions is called CVI crashes (Test Stand says it lost the ActiveX connection to CVI) when executing in an external CVI instance.  If executed in the Test Stand process I get a system level exception.
    If I step through the code in CVI, it hangs after trying to step into or over the call to the function pointer from the external DLL.
    I am able to call the functions in a small test project I created in CVI, however when integrating it into an existing test library and calling it through Test Stand it fails.
    Any ideas on how to go about debugging this issue?

    Have you tried calling into the dll that CVI calls directly from TestStand?  I am curious to know if this also crashes.
    I am also curious to know if there are any path references in the dll that is called by the CVI program.  If so are they relative, or absolute paths?
    I ask because one of the possibilities is that relative paths are being used to specify a path from the location of the code that is called, and they are not working because the current working directory is being specified by TestStand, and the paths are not relative to the working directory given by TestStand.
    Jensen
    National Instruments
    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

  • FRM-40734 when calling external DLL Function from Forms 6

    Even though some answers were given to my previous help request ("Again: Forms 6 and user-defined data types") I wasn't able to solve the problem of passing a parameter of an user-defined type to an external DLL function residing in the SECURSIGN.DLL library (the closest solution was to declare that "composite" parameter using the ROWTYPE clause referencing a custom-made table created just for the sake of defining that perticular datatype).
    So I concentrated on SECURSIGN.DLL functions using more trivial data types, like a function requiring just four character strings as parameters.
    I generated the necessary PL/SQL support using the FFI.
    I discovered that also the simplest calls to external functions fail at runtime with the generic error FRM-40734.
    I located the error: it happens just at the moment of calling the function from within the FFI-generated package body. Before that, the DLL is loaded with no problem, the function is correctly registered, and a function handle is regularly returned.
    As long as I can regularly issue the very same call with the very same parameters from Visual Basic, I can't understand what's going wrong (ALL the needed DLL are in the same directory as the FMB/FMX forms).
    I will greatly appreciate any help that You may be able to provide.

    I have noticed just now that a dump file having a name like ifrun60_dump_299, is generated by FORMS every time I issue the aborted call to the foreign function.
    Inside the form dump file, apart from useless info like Registers and so on, the message:
    "Could not find Module32First"
    By a FILE/FIND/CONTAINING TEXT I searched all the DLLs, and I noticed that Module32First is a routine that can be found within each of the following DLLs:
    Cl32
    d2kwut32
    d2kwut60
    I tried to load those DLLs along with SECURSIGN.DLL by modifying the PROCEDURE LoadLibrary into the FFI-generated PLL code, and I have apparently no problem in loading all the DLLs that I wish, but the error persists, and that dump file is constantly generated, always looking for the "Module32First" routine.
    How can I avoid all that mess and the FRM-40734 error??

  • Different performanc​e for handling DLL function

    Hi, all
    I have some question about handling DLL function.
    There is two test cases for the DLL handling for experiment.
    Platform is as following:
    Windows 98, LabWindows/CVI 5.5 (compatiable with Virsual C++), DLL library (built by C++ Builder 960 kbytes).
    Case 1:
    Use the LoadLibrary to load the DLL library (DLL_handle) and use the function (provided by DLL) to handle the COM port (COM_handle). And there have a hardware key for security check. For each command (provided by DLL) take 0.25 second to finish one command to handle the RS232.
    Case 2:
    Use LoadLibrary to load the DLL library (DLL_handle) and use the function (provided by DLL) to handle the COM port (COM_handle). And there
    have a hardware key for security check. There have three threads working (use CreateThread to create with 1MB stack size), and pass the DLL_handle and COM_handle to the static libarty to do the desired job (took 1 second to finish the job for one command). In the static library, there use the DLL_handle to get the pointer of the selected function and use COM_handle to handle the RS232.
    I don't know the reasons between these two cases.
    If you have any suggestion or solution about it , please tell me detail.
    Thanks,
    Lambert Lin
    My email address is [email protected]

    Sir,
    We do not have an exact idea of what your application is doing. However, it looks like the difference between the two cases is the use of multithreading in the second. It is possible that the delay is from the CPU having to "switch" between threads, and having to load and execute calls to the DLL once in the thread. I think you should look carefully into the structure of your applications multithreading to see if there are areas which could be causing delays in the execution of the DLL's functions.

  • I am trying to enter a split point for a file going on a dual layer disc. There are chapter markers in the file but the automtic function doesn't see them. Can I insert a point for the layer split in DVD Studio Pro 3 or 4? It doesn't appear that the autom

    I am trying to enter a split point for a file going on a dual layer disc. There are chapter markers in the file but auto function does not see them. Went back and put a small split in the timeline in fcp and exported to mpeg 2 again and auto function does not see that either? Manual msays to manualy enter split poind in DVDSP but can't find any way to enter that split point in DVDSP? How can I manualy enter a split point in DVDSP 3 or 4?
    Elizabeth/Roger Cook Films

    This is definitely not the behavior I see.  When I left click it adds a marker,
    When I right click, I see the following
    Do you have any OS hacks installed on your computer or have you changed the mouse behavior in system preferences:  mouse?  If not, I'd suggest you run digital rebellions preference manager and reset your dvdsp preferences. 
    https://discussions.apple.com/docs/DOC-2491

  • Shipping point is missing from automatic delivery for external operation

    Hi All,
    I have tried to do one operation vy external processing. All the configuration and master data done. But during the goods receipt for the material from vendor after processing (t code MIGO) system is providing message as "Shipping point is missing from automatic delivery".
    1. In the control key, automatic GR is not there, so from where automatic delivery is coming?
    2. I have maintained the shipping point for the plant as plant in SPRO>LOG Exe> Shipping> Shipping point and goods receiving point determination> Assign good receiving point for In bound deliveries.
    Please provide the solution.
    Thanks
    Krishna

    Dear friend,
    As far as i know:
    1. check out the shipping point assignment to plant : t-code OVXC ;  just in case make sure your shippong point is correct - goto spro->enterprise strucutre->definition->logistics execution->def.,copy,del,check shipping point
    2. make sure your SC (shipping condition) and loading group are correct in the "Shipping point determination";
    also make sure you did GR points assignment correctly (the next item in IMG)
    good luck!

  • PXI 6733 smallest voltage for external reference?

    Hi, I need to know, what is the smallest voltage possible for external reference?
    I couldnt find this information anywhere, I just found, the internal reference is 20Vpp and the device is 16 bit, so the LSB is 312uV.
    If I connect the EXT_REF with smaller voltage, let say 5V, the reference becomes 10Vpp and the LSB becomes 156uV.
    What is the smallest voltage that I can use, in other words, what is the smallest LSB I can get with this device?
    regards,
    yan.

    In prinziple you can decrease the external reference as you wish. But be aware of the error margin you create.
    You can see in the following graph that the measurement error consists of three parts, which have different reaction to the range:
    It all ends up to the following equation:
    You can see that the gain error (the first part) is only half the equation to finding the actual accuracy of the generation. So, assuming that we have zero temperature drift, if we can greatly reduce our gain error by providing a highly accurate reference signal, then we are still left with the offset error that is independent of the reference signal.
    You will also add additional error margin by using the external source, which ofcause has to be calibrated separetly, and adds an additional voltage drift. I therefor would recommend not to use reference voltages below 0.5V.

  • Set reference point for coordinates

    How to set the reference point for a rectangle in coordiate system using javascript? I want to set this value before setting the geometricBounds property
    Thanks.

    Hi,
    Try this:
    app.activeWindow.transformReferencePoint = AnchorPoint.BOTTOM_RIGHT_ANCHOR;
    Options:
    AnchorPoint.BOTTOM_CENTER_ANCHOR
    AnchorPoint.BOTTOM_LEFT_ANCHOR
    AnchorPoint.BOTTOM_RIGHT_ANCHOR
    AnchorPoint.CENTER_ANCHOR
    AnchorPoint.LEFT_CENTER_ANCHOR
    AnchorPoint.RIGHT_CENTER_ANCHOR
    AnchorPoint.TOP_CENTER_ANCHOR
    AnchorPoint.TOP_LEFT_ANCHOR
    AnchorPoint.TOP_RIGHT_ANCHOR
    Hope that helps.
    Marijan (tomaxxi)
    http://tomaxxi.com

Maybe you are looking for

  • I Want to make an app.. but i dont know how to write code or use Xcode... where I can begin?

    Hey!      I just graduate from high school.. im gonna study Computer Enginnering. Im working for my family and they need an app that works like iBook. We have the eBooks and then they want me to do an app where they can sell the eBooks and read them.

  • Can someone help me with my plug-in problem?

    I have Elements 7 and recently added a slew of photo filter plug-ins that I had an another computer.  When I added these filters, the drop down box that displays the filters from the top menu options, now only displays the filters alphabetically from

  • I cannot see images on ebay and other sites

    I am trying to look at ebay, but none of the pictures are loading. I have adblock and noscript running. Also qvc doesnt load pics.

  • Append quote to a number.

    Hi Experts!, Please tell me what is the syntax to append a quote i.e.  ' What I remember was something like below. But it is giving error. so may be wrong syntax. data: number type  num6. concatenate '\''  number '\'' into number. example- number = 1

  • Any way to resolve the loss of preview when saving from cc to cs6

    I have a massive job that was done in cloud, that now needs to be changed in cs6, it is a catalogue, so loads of pics, any way to make the previews visible without manually relinking every pic?