LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call C-Dll

Hello,
i have a DLL where the documentation says:
"The DLL library is a standard windows function library which can be easly used with most common application development tools such as Visal Basic, Visual C++ etc"

I try to call a function like:
int result = funcName(int Parm1_in, long *Parm2_out, long *Parm3_out)

which is attached as an empty example.

But when i run it then LV crashes completely.

Do i pass the Pointer things correct?
What is the difference between "int" and long?

Thx
0 Kudos
Message 1 of 3
(2,631 Views)
In the example you posted, there is no DLL selected, so it is broken.  But, in general, you can get crashes but not having the right data types.  You can also get crashes by using the wrong calling convention (stdcall (WinAPI) or C).  More than likely, your Param 1 and result should be an I16.  More than likely, this should be called with the C calling convention as well.
0 Kudos
Message 2 of 3
(2,627 Views)


@OnlyOne wrote:
Hello,
i have a DLL where the documentation says:
"The DLL library is a standard windows function library which can be easly used with most common application development tools such as Visal Basic, Visual C++ etc"

I try to call a function like:
int result = funcName(int Parm1_in, long *Parm2_out, long *Parm3_out)

which is attached as an empty example.

But when i run it then LV crashes completely.

Do i pass the Pointer things correct?
What is the difference between "int" and long?

Thx


int is a signed integer that depends on the used CPU architecture. 16 bit for 16 bit Windows (Win3.1), 32 bit for modern x86 based OSes. long is always a 32 bit integer independant of the underlaying CPU architecture.

Your first parameter should be passed as a int32 by value and the other two as int32 as a pointer. This assumes that they are just simple skalars. If they are arrays (and there is usually no way to see that from the function prototype since C treats arrays just as pointers too), then that is an entirely dfferent story.

The last thing that can neck you is the calling convention. cdecl and stdcall are absolutely incompatible so if you get that wrong you crash guaranteed the first time you execute the VI.

Rolf Kalbermatter

Message Edited by rolfk on 10-24-2007 10:19 AM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 3
(2,606 Views)