LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing string to PChar data type in a dll created in delphi

Solved!
Go to solution

Hello everybody,

I am trying to call a function in DLL created with Delphi. The function takes File name (type Pchar) as the parameter and returns the file handle (signed integer 32).

I wrote a very simple VI consisting of a String constant linked to a Call Library Function Node. In the Call Library Function Node I used stdcall Calling Convention and String - Pascal String Pointer as arg1. When I run the vi, the dll returns error code as it is junk characters instead of the file name (show in the attached image) passed to the function. I am suspecting this has to do with how Labview string is passed to Pchar data type

I have tried all combinations of Calling Convention and argument type in the Call Library Function Node but none seemed to work.

Can any body tell me how to pass labview string to Pchar in delphi?

Thank you very much!

0 Kudos
Message 1 of 7
(4,603 Views)

I might be wrong thought delphi strings were typically null terminated like C strings, not prepended with length like pascal strings.

 

I would wire the string in as C string pointer.

 

0xDEAD

0 Kudos
Message 2 of 7
(4,591 Views)

I tried that and still the same result.

0 Kudos
Message 3 of 7
(4,583 Views)

Did you try appending a null terminator to the string? I haven't any delphi experience, not sure how fussy it is.

0 Kudos
Message 4 of 7
(4,571 Views)

I was bored, so did a bit of googling. It seems that in certain Delphi versions the default Char is a 16 bit (unicode rather than ANSI string). 

Looking at the garbage you got back, this might be the issue.

 

Message 5 of 7
(4,565 Views)
Solution
Accepted by topic author vvpn75024

Thank you. I was able to finally get it working by using the  STR_ASCII-Unicode.vi  lcoated in "vi.lib\registry\registry.llb" to convert the string to unicode and passing it to the c String 

0 Kudos
Message 6 of 7
(4,556 Views)

No problem. I got to learn something new.

 

0xDEAD

Message 7 of 7
(4,551 Views)