06-26-2014 07:41 AM
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"
06-26-2014 08:00 AM - edited 06-26-2014 08:05 AM
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.
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.
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. |
*Source: http://zone.ni.com/reference/en-XX/help/371361K-01/lvdialog/call_lib_function_db/
06-26-2014 08:21 AM
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
And when I choose disable the error, the LabVIEW crash.
So I wonder if there is somting wrong with .dll or .h file?
06-26-2014 08:40 AM
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.
06-26-2014 09:24 AM
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.
06-26-2014 09:30 AM
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.