LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help! DLL's replying with strings give errors

Hi ,

I use the Call Library node to call a DLL function I wrote in C

void test (char Text[50])
{
strcpy(Text, "This is a test\0\n");
}


Next, I configured the Call Library Function as follows:
Parameter RETURN TYPE: Type = Void;
Parameter ARG1: Type = String; String format = C String Pointer;

(Which leads to Function prototype: void test(CStr arg1) )


The function executes just fine, but when I close the VI, I get an
APPLCATION ERROR! ("The instruction at '0x123456' referenced memory at
'0x123456'. The memory could not be read"). I guess this is when the DLL
is unloaded, but what am I doing wrong?

I am Using LabVIEW 5.1.1 & Win NT 4.0

Please help!

Patrick Pol
The Netherlands
0 Kudos
Message 1 of 4
(2,914 Views)
P.s.

What should I wire to the string INPUT terminal of the Call Library node? an
empty string constant? a local variable of the indicator that I wired to the
output terminal?

I tried both....
0 Kudos
Message 2 of 4
(2,914 Views)
> What should I wire to the string INPUT terminal of the Call Library node? an
> empty string constant? a local variable of the indicator that I wired to the
> output terminal?
>
> I tried both....

I believe that your problem here is that you told the C compiler that there
were 50 characters reserved for the function to write in. A caller of this
function will need to allocate storage for the DLL function to scribble into,
or this will be a possible crash/corruption.

The same thing is true of LV. The caller, in this case, LV has no idea
how much space to allocate for the DLL call. You will need to do this
on the diagram using a constant, a control, or some other function that
produces a string large enough to store the data into.

Greg McKaskle
0 Kudos
Message 3 of 4
(2,914 Views)
Thanks Greg,

I wired a string constant containing at least 50 characters to the input of the
Library node, and that got rid of my crashing-problems.

Patrick Pol


Greg McKaskle wrote:

> I believe that your problem here is that you told the C compiler that there
> were 50 characters reserved for the function to write in. A caller of this
> function will need to allocate storage for the DLL function to scribble into,
> or this will be a possible crash/corruption.
>
> The same thing is true of LV. The caller, in this case, LV has no idea
> how much space to allocate for the DLL call. You will need to do this
> on the diagram using a constant, a control, or some other function that
> produces a string large enough to store the data into.
>
> Greg M
cKaskle
0 Kudos
Message 4 of 4
(2,914 Views)