LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling C DLL functions

Hello

 

I have a VI that contains only a call library function node. This calls a DLL function to open an instrument, which will return if no instrument is found.

 

When I run it, it behaves as expected and the VI stops running. However, once it has stopped, LabVIEW will throw an exception and exit when I close the VI. Also, the splash screen that is displayed during the function call does not completely disappear; it reamains as an empty window until LabVIEW is closed.

 

I have tried the same call in C with no problems.

 

Is there something else that I should be doing to release the DLL, for example? 

 

Thanks

 

Robin 

0 Kudos
Message 1 of 8
(2,767 Views)

Hi RobinM2,

 

If you mine can you attached or snapshot of your program so I can figure out your problem.

 

regards,

Ludz

0 Kudos
Message 2 of 8
(2,759 Views)

Hi Ludz

 

Thanks for your reply.

 

Here is an image.  

 

Robin

 

VI.png 

0 Kudos
Message 3 of 8
(2,749 Views)
We'll need more information than that. How is the Call Library Function Node function setup? Is the function supposed to be called using C calling conventions of stdcall (WINAPI) calling conventions? What is the prototype for the function? Is there an error generated by the Call Library Function Node function?
0 Kudos
Message 4 of 8
(2,735 Views)

Thanks for the reply.

 

The Call Library Function node does generate an error. It (correctly) uses stdcall and runs in UI thread. The prototype is 

 

unsigned long (short*) 

0 Kudos
Message 5 of 8
(2,710 Views)

RobinM2 wrote:

 

It (correctly) uses stdcall and runs in UI thread.


How do you know this is correct? In fact, ...


The prototype is 

 

unsigned long (short*) 


This tells me it's C calling convention.

 

Clearly the argument is supposed to be a pointer to an integer. Are you passing the argument as a pointer?

 

Why don't you go ahead and post your VI and your DLL source code?

 

0 Kudos
Message 6 of 8
(2,693 Views)

I have found that this only happens when using a debug DLL, there are no problems when using a release version. I'm not sure why this is, but it seems unlikely to be a problem on the labview side.

 

Anyway, thanks for the replies. 

0 Kudos
Message 7 of 8
(2,662 Views)
This problem sounds like you have the wrong calling convention.  If you are using WINAPI, try switching to C calling convention, as mentioned by smercurio.  Typically, when you assign the wrong convention, the code will work up to the point where the return from DLL happens.  The stack is messed up and will cause strange errors, including Labview crash.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 8
(2,603 Views)