LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using labviews dll's to write to hardware

I'm trying to use an external vc++ program to call some of labviews functions in their dll's. Specifically DIO_Port_WriteInterface found in port write. Looking closely at the function node you can see the dll lvdaq.dll and a prototype: void DIO_Port_WriteInterface(void *arg1, void *arg2, void *arg3, void *arg4, void *arg5);.

I can call it from vc++ by dynamically loading it but labview/windowsXP complain that:
The value of ESP was not properly saved accross the function call.This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

I'm assumming I'm not handling void* properly or not passing the appropriate values. How do I
handle the parameters being passed into the function call? Thanks for any suggestions/help!
0 Kudos
Message 1 of 7
(3,137 Views)
whatsthis wrote:

> I'm trying to use an external vc++ program to call some of labviews
> functions in their dll's. Specifically DIO_Port_WriteInterface found
> in port write. Looking closely at the function node you can see the
> dll lvdaq.dll and a prototype: void DIO_Port_WriteInterface(void
> *arg1, void *arg2, void *arg3, void *arg4, void *arg5);.
>
> I can call it from vc++ by dynamically loading it but
> labview/windowsXP complain that:
> The value of ESP was not properly saved accross the function call.This
> is usually a result of calling a function declared with one calling
> convention with a function pointer declared with a different calling
> convention.
>
> I'm assumming I'm not handling void* properly or not passing the
> appropriate values. How
do I handle the parameters being passed into
> the function call? Thanks for any suggestions/help!

It would be a good idea to install the NI-DAQ for C/C++ development
files and include the according header files in your source code. The
problem you see is most probably that the NI-DAQ functions use cdecl
calling convention whereas you defined stdcall or probably nothing at
all in which case Visual C uses stdcall by default.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 7
(3,137 Views)
Where can I get the header files?

How do I use cdecl to set up my function ptr?

Here's the example code I have been playing with:
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer


hDLL = LoadLibrary("lvdaq");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"DIO_Port_WriteInterface");
0 Kudos
Message 3 of 7
(3,137 Views)
You should not be trying to call lvdaq.dll but instead nidaq. When you install the daq driver, you are given the choice of installing support for various languages. If you select C/C++, then you'll get all of the header files, example code, documentation, etc. that you need.
0 Kudos
Message 4 of 7
(3,137 Views)
Are these files installed in the NI diectory: C:\Program Files\National Instruments\NI-DAQ\Include

There seems to be a lot of info here. Thanks.

But to answer my own question I successfully called the lvdaq fucntion from labview with the following:

typedef void (__cdecl *__cdecl FCNPTR)(void *, void *, void *, void *, void *);

HINSTANCE hDLL; // Handle to DLL
FCNPTR lpfnDllFunc1; // Function pointer


hDLL = LoadLibrary("lvdaq");
if (hDLL != NULL)
{
lpfnDllFunc1 = (FCNPTR)GetProcAddress(hDLL,"DIO_Port_WriteInterface");

if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return;
}
e
lse
{
// call the function
lpfnDllFunc1(taskID, pattern, lineMask, par4, par5);
}
}
0 Kudos
Message 5 of 7
(3,137 Views)
whatsthis wrote:

> Are these files installed in the NI diectory: C:\Program
> Files\National Instruments\NI-DAQ\Include
>
> There seems to be a lot of info here. Thanks.
>
> But to answer my own question I successfully called the lvdaq fucntion
> from labview with the following:

Of course you can do that. But lvdaq.dll is an intermediate layer
between nidaq.dll and LabVIEW to ease some data type conversion as some
of the NI-DAQ types are not so easy to use from within LabVIEW. By
calling lvdaq.dll from your C app you add an additional level of
indirection to your DAQ calls and soon will wonder what strange data
types (in the sense of C programming) some of the functions will take.
You will have to read through the External
Code in LabVIEW manual to
understand some of the types.

Also you need to create a thunk for each function you want to call. If
you use NI-DAQ instead, you have the nidaq.h file to include only and
add the appropriate import library to your project and you are set to
call any of the many hundred DAQ calls.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 7
(3,137 Views)
Yes I agree. I found nidaq.h to be very helpful and that is what I ended up using. lvdaq.dll was very slow, like you said an additional layer. Thank you very much for all the help everyone.
0 Kudos
Message 7 of 7
(3,137 Views)