annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

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
Messaggio 1 di 13
10.268Visualizzazioni

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 Strizza l'occhio

Cheers!

 

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Messaggio 2 di 13
10.256Visualizzazioni

"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 Strizza l'occhio
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
Messaggio 3 di 13
10.252Visualizzazioni

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
Messaggio 4 di 13
10.250Visualizzazioni

That's two, Wiebe!Smiley Strizza l'occhio

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
Messaggio 5 di 13
10.242Visualizzazioni


@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
Messaggio 6 di 13
10.232Visualizzazioni
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
Messaggio 7 di 13
10.228Visualizzazioni
Smiley Felice
... 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)
Scarica tutti
0 Kudos
Messaggio 8 di 13
10.229Visualizzazioni

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
Messaggio 9 di 13
10.187Visualizzazioni

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 Strizza l'occhio

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Messaggio 10 di 13
10.176Visualizzazioni