LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing C String from labview to DLL

I have a problem with my labview VI and my DLL. I know that the DLL works correctly, because I've created a sample exe and called the DLL from it and it works as expected. Now I've decided to use labview to call the DLL, but it keeps crashing.

This is the function prototype:

_declspec (dllexport) void readFile(char *fileName);

Now, the DLL function is called in my labview VI with these specs:
Calling convention: C
Parameter: fileName
Type: Array
Data Type: Signed 8-bit Integer
Dim: 1
Array Format: Array Data Pointer

Which gives me: void readFile_(char *fileName)
I'm inputting the string like this: String->Decimal String to number converter -> readFile

Here the program crashes saying that "Labview: An
Exception occurrec with the external code ... "

compiler: Open Watcom (latest)

Can someone please tell me how to fix this problem!

Thank you!
0 Kudos
Message 1 of 3
(3,833 Views)
boo123;

Try the following:

Parameter: fileName
Type = String
String Format = "C String Pointer"

Also, the name of the variable is "fileName". Aren't you suppose to give the file's name? (probably the whole file path?) The string you are providing may be invalid!

Finally, check the following article:

An Overview of Accessing DLLs or Shared Libraries from LabVIEW

It includes a nice "conversion" table. Keep us posted!

Regards;
Enrique Vargas
www.visecurity.com
www.vartortech.com
0 Kudos
Message 2 of 3
(3,833 Views)
boo123 wrote:
> I have a problem with my labview VI and my DLL. I know that the DLL
> works correctly, because I've created a sample exe and called the DLL
> from it and it works as expected. Now I've decided to use labview to
> call the DLL, but it keeps crashing.
>
> This is the function prototype:
>
> _declspec (dllexport) void readFile(char *fileName);
>
> Now, the DLL function is called in my labview VI with these specs:
> Calling convention: C

Maybe you should try to use stdcall if you are on Windows. Just try out
as this is usually one of the reasons why it could crash.

> Parameter: fileName
> Type: Array

Change this to string

> Data Type: Signed 8-bit Integer
> Dim: 1
> Array Format: Array Data Pointer

and string format: C type pointer


> Which gives me: void readFile_(char *fileName)

Which will give you the same line. C declaration is sometimes not very
unambiguous.

> I'm inputting the string like this: String->Decimal String to number
> converter -> readFile

With above configuration you don't need any conversion and LabVIEW makes
sure that the string is properly zero terminated as most C string
fucntions expect.

> Here the program crashes saying that "Labview: An Exception occurrec
> with the external code ... "

This could also be because the DLL function tries to go through the
string until its NULL termination character and since it isn't where it
should be runs over its end and accesses other data.

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