LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error 1517 when executing the VIs for DLL

I want to be able to use a certain function from C++ DLL, and I followed the TOOLS>>IMPORT>>SHARED LIBRARY(.dll) wizard. l use the head file and dll from company. This is for a motion controller. When I run VIs, they always show the error 1097 and the VIs can not work on the motion controller both in the simulation and in the real operation. I use the sac.dll and sacenums.h file. As you can see in the picture, the return value is very strange and the pAxisId should be "0" instead of "128"

run 1st time .png

Download All
0 Kudos
Message 1 of 6
(5,621 Views)

Two things to check:

 

1. Make sure you have the correct calling convention selected

 

Calling convention—Specifies the calling convention for the function. The default is C.

  • stdcall (WINAPI)—Controls whether the object uses the __stdcall calling convention.
  • C—Controls whether the object uses the __cdecl calling convention.

 

calling.png

 

2. Try lowering the error checking.  Try "default" or even "disabled" to see if it fixes the issue:

 

Error Checking—Use the Error Checking tab to specify the error checking level for the Call Library Function Node.

  • Error Checking Level—Contains the following options:
    • Maximum—Enables the maximum level of error checking for the Call Library Function Node. In addition to the error checking capabilities of the Default level, the Maximum level causes the Call Library Function Node returns a warning if the function being called in the shared library or DLL writes beyond the space allocated for the specified string or array parameter.
      Note  Selecting the Maximum control on the Error Checking tab reduces the execution speed and increases the memory usage of the Call Library Function Node. Therefore, you should select the Maximum control only when debugging your configuration of the Call Library Function Node.
    • Default—Enables the default level of error checking for the Call Library Function Node. The default level of error checking allows LabVIEW to recover from unhandled exceptions that occur during execution of the called shared library or DLL. This error checking level also causes the Call Library Function Node to return an error if the Calling convention you select on the Function tab does not match the calling convention of the function you are calling in the shared library or DLL.
    • Disabled—Disables error checking for the Call Library Function Node. Disabling error checking for the Call Library Function Node improves the execution speed of the Call Library Function Node. However, certain errors can cause an irregular shutdown of LabVIEW. Before disabling error checking, be sure that the function the Call Library Function Node references does not raise any unhandled exceptions.

 error.png

 

*Source: http://zone.ni.com/reference/en-XX/help/371361K-01/lvdialog/call_lib_function_db/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 2 of 6
(5,609 Views)

Thank you for your reply.

I try the method. When I select stdcall, the error not come back but the return value and the pAxisId are not correct

2.png

 

And when I choose disable the error, the LabVIEW crash.

 

1.png

 

So I wonder if there is somting wrong with .dll or .h file?

0 Kudos
Message 3 of 6
(5,595 Views)

First, the attached sacenums.h file is of very little help in respect to the actual API. It only seems to contain helper functions to deal with various enums the API uses.

More interesting would be the sacapi.h file.

 

From the exported name decoration it would seem that the functions should be called with stdcall calling convention, but while the naming is a strong hint it is not strictly conclusive.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 6
(5,586 Views)

Thank you for your advise. Now I use stdcall convention and error does not appear. But the strange thing is the "function return" and the value of "pAxisI out" are not correct. As you can see in the picture, the "pAxisId out" should be "0", not "128". And also the "function return" is very strange.

 

1.png

0 Kudos
Message 5 of 6
(5,578 Views)

I am not familiar with your DLL code.  Is it possible either (if not both) of those numbers are error codes output from the DLL?  Perhaps those numbers have more meaning than you think.  Perhaps consult the manual or programmer of the DLL (assuming it wasn't programmed by you).

 

If possible, try creating a single VI example that just inputs whatever should give you expected outputs.  Then post that.  Your .zip is littered with VIs and other files.  Its too complex for me to try to get involved just by diving in.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 6 of 6
(5,574 Views)