LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass pascal string pointer to Delphi DLL?

Hi there,
 
I was trying to call DLL in Labview. The declaration of this DLL in Delphi is:
function YL_Write_DO(addr,tunnel,action:PChar):PChar; far;external 'ComDll.dll';
 
I need to pass Pchar(Pascal String Pointer) type inputs from Labview to the DLL. When I wire a string control to the Call Library Function Node input directly, it prompt error 1097, an exceptional error in the external node.
 
My question is can I pass Pascal String Pointer to the DLL by wiring string control directly?  If not, how to do it? I appreciate if somebody provides an example.
 
Regards,
Bob Wu
0 Kudos
Message 1 of 13
(8,015 Views)

Hi Bob,

      If I remember correctly, the first byte of a Pascal "string" is the string's character-length.  I'd define this CLF parameter as an array of bytes(U8).  Convert the input string to an array of U8 and concatinate the array-length as the first byte (obviously you don't want to try to pass strings larger than 255 characters!)  It's been a long time since I programmed in Pascal (~1988) and I'm only fairly confident this advice is right. Smiley Wink

Cheers!

 

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 2 of 13
(8,003 Views)

"tbd" <x@no.email> wrote in message news:1175056807199-498504@exchange.ni.com...
Hi Bob,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If I remember correctly, the first byte of a&nbsp;Pascal "string" is the string's character-length.&nbsp; I'd define this CLF parameter as an array of bytes(U8).&nbsp; Convert the input string to an array of U8 and concatinate&nbsp;the array-length&nbsp;as the first byte (obviously you don't want to try to pass strings larger than 255 characters!)&nbsp; It's been a long time since I programmed in Pascal (~1988) and I'm only fairly confident this advice is right.&nbsp;Smiley Wink
Cheers!
&nbsp;



pascal.vi:
http://forums.ni.com/attachments/ni/170/238186/1/pascal.vi


Have you tried to select the type string, and then select "Pascal String Pointer" as String format?


Regards,


Wiebe.
0 Kudos
Message 3 of 13
(7,999 Views)

Thanks for the replies.

I've selected the "Pascal String Pointer" in the configuration of Call Library Function node.  I tried the "pascal.vi", it seems that the U8 array output is not compatible with the CLF node input(shown as String type). I  also tried to add a U8 to String converter in the pascal.vi. The error code shown up is still #1097. Looks like the string has not been successfully transfered into the DLL node.  Any other solutions?  thanks....

Best regards,

Bob Wu

0 Kudos
Message 4 of 13
(7,997 Views)

That's two, Wiebe!Smiley Wink

Bob, Wiebe's right, the "Pascal String Pointer" is the way to go.  It will allow you to pass-in the string directly - no worries about concatinating the length-byte - LabVIEW will take care of that.

As for error  1097, what "Calling Convention" are you using?  Is the DLL supposed to return any data?  The prototype you posted is kinda confusing (those smiley-faces have a mind of their own.)  What, exactly, are the data-types being passed?

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 5 of 13
(7,989 Views)


@tbd wrote:

... What, exactly, are the data-types being passed?


This question should have been: "exactly what data-types are expected by the DLL? (what are the 'addr' and 'tunnel' types?)  Is "action" the Pchar type?"
 
Cheers!
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 6 of 13
(7,979 Views)
All the input arguments and return are "Pchar" type in Delphi. It's interesting that the "Pchar" changed to a "smiling face" + char.
 
Thanks,
 
Bob Wu
0 Kudos
Message 7 of 13
(7,975 Views)
Smiley Happy
... is string-space being pre-allocated for any return value?
 

Message Edited by tbd on 03-28-2007 10:19 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Download All
0 Kudos
Message 8 of 13
(7,976 Views)

Thanks, even pre-allocated space for the return value, the error still happened. I'm wondering if there is any problem within the DLL itsself.

Bob Wu

0 Kudos
Message 9 of 13
(7,934 Views)

Hi Bob,

      Forgive me! - I've been assuming we were trying to use a working DLL - is this a DLL you're developing?  It seems from reading here, here, and here, that pchars need to be paired with a length-parameter.  They also said that return-values are allocated by the DLL (Delphi) and may be "freed" by delphi - invalidating the reference in the caller.

Not sure what it takes to get a Delphi compiler environment going.  I'd try building a DLL with a U32 return_type.  Once that's working, add a pchar parameter w/length parameter passed by value, and modify the pchar inside the DLL.  Once that's working, you're home free.Smiley Wink

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 10 of 13
(7,923 Views)