LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem calling external code (DLL)....?

Hi, I am having problems calling a function I have written in C from a
DLL.

System is Labview 6.02 on NT4 and MS developer studio 97.

The function prototype in the Call Library Function configuration
looks like this: void binary(unsigned long value, CStr string);
and the code in the c source file looks like this:
------------------------------------------------------
#include "extcode.h"

_declspec(dllexport) void binary(unsigned long value, CStr string);

_declspec(dllexport) void binary(unsigned long value, CStr string)
{

unsigned long mask;
int i = 0;

for (mask = 0x80000000; mask!= 0; i++)
{ if (i == 8||i==17||i==26)
string[i++] = ' ';
string[i] = (mask & value)? '1': '0';
mask=mask>>1;
}
string
[i] = '\0';
}
------------------------------------------------------
I wire a U32 numeric and empty string to the input of the Call Lib
function block, and a string indicator on the output.

When I run the VI I get an error saying the memory could not be
written and I have to terminate labview.

As you can see the function modifies the string passed to it, so I
would like to be able to see that string back in labview.

Anyone got any ideas?

Thanks in advance,
Joe
0 Kudos
Message 1 of 3
(2,607 Views)
Joe;

I just took a quick look at your code. I think your problem is that you are passing a char*, but then you are changing its size. As a general rule, do not pass a char* if you are going to change the size of your string.

The following example are helpful on showing how to manipulate strings. Although the examples are for CIN, you just need to do a little to make it work for a DLL:

Code Interface Node (CIN) That Converts a LabVIEW String to a C String, Modifies it, and Returns it ...

Using a CIN to Create an Array of Strings in LabVIEW

This is just a quick look. There may be other reasons.

Best regards;
Enrique
www.vartortech.com
0 Kudos
Message 2 of 3
(2,607 Views)
On zone.ni.com you can find a lot of useful information about calling
external DLL code. Some of this may help you.

Mark
Message 3 of 3
(2,607 Views)