LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call function from a dll

Greetings all,

I'm new to calling dll's within Labview and I'm not an experienced C++ person either. I'm trying to use a dll provided by a robot manufacturer. I have all the documentation on the dll. When I input a function name into the configure dialog box for the "call library function" node, I get a Labview error saying the function name is not found in the dll. However, when I place this function name in the dialog box, it automatically pulls in arguments that could have only come from the dll. Futhermore, if I try to change a parameter, it warns me that I am changing information found in the dll. How can it give me that warning if it isn't finding the function within the dll?

An example of the syntax I'm trying to achieve is as follows:

Function Name: RSPInitComm
    *This opens the com port for communication
C++ Syntax should be: HRESULT RSPInitComm (BYTE byPortNumber)

I can't seem to get that to match what is in the Function Prototype box. Is this my problem? Does what is in the Function Prototype box need to exactly match this C++ syntax? If so, how do I get it to match? I haven't been able to find the correct selections to get this line to match.

Any help is appreciated.

Thanks,
Tim
0 Kudos
Message 1 of 6
(3,588 Views)
Lets make sure you are performing the correct actions:
1.  Place a Call Library Function node on your block diagram.
2.  Double click the node to open up the Call Library Function dialog box.
3.  Click the Browse button and navigate to the DLL function.  Select the proper DLL and click Open, or just double click on DLL.
4.  On the Function Name box, click on down arrow.  A list of functions found in the DLL should be displayed.  Choose the function.
5.  On the Calling Conventions box, click on down arrow and select C or WINAPI.  In your case, it should probably be C.
6.  The Parameter box should show return type.  In the Type box, select the data type of the return value.  Since you won't see HRESULT here, you need to find out what data type HRESULT is in the C code.  I would guess it is a numeric so select numeric from the drop down list.
7.  Click the Add a Parameter After button.
8.  In the Parameter box, change the name arg1 to the actual name of your first parameter, which is byPortNumber.
9.  In the Type box, choose Numeric, since a BYTE is a numeric in Labview.
10. In the Data Type box, choose Unsigned 8-bit Integer, since a BYTE is a U8 in Labview.
11. In the Pass box, choose Value.  If the C parameter was a pointer (*BYTE), you would choose Pointer to Value.
12. Verify that the contents of the Function Prototype box contains the correct syntax according to the C declaration.
         C:  HRESULT RSPInitComm (BYTE byPortNumber)   should be in Labview: long RSPInitComm(Unsigned char byPortNumber)
13. Click OK button.
Try it out.
If you get a crash, change the Calling Convention to WINAPI.
 
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 6
(3,583 Views)
In addition to tbob's suggestions, you may want to read over the "Using External Code in LabView" document under Help in LabView in v7. Not sure where it is in v8, it also probably resides somewhere on NI's site.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 3 of 6
(3,570 Views)
Step 4 looks like where I'm having the problem. I only get 4 functions in the pull down. They are DllCanUnloadNow, DllGetClassObject, DllRegisterServer, DllUnregisterServer. I know these names are probably specific to the DLL, but I thought they may give you a clue that can help me. The part that baffles me though is that if I type into the function pulldown a function that I believe should be there, it does pull back information on the parameters associated with that function. So it is in there somewhere, it just won't let me at it. Any clues?
0 Kudos
Message 4 of 6
(3,563 Views)
I believe I have figured out my problem. Turns out I am trying to talk to an Active X server. While browsing through my IntermediateII book, this dawned on me. Looks like I have it under control. Thanks for your help.
0 Kudos
Message 5 of 6
(3,559 Views)
For some reason, Labview is not seeing the function you claim is there.  This has to be a problem with the DLL itself.  Perhaps the function is not properly declared inside the DLL.  I have never seen parameters automatically being retreived when selecting a function.  You usually have to add the parameters and define them manually.  Sounds like your DLL is screwey.  Do you have the DLL source code or can you speak to the DLL programmer?
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 6
(3,559 Views)