Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to use a DLL function that returns a string

Status
Not open for further replies.

Jonathan

Programmer
Mar 19, 1999
116
GB
I'm trying to use a DLL written in Delphi. Both of the functions in the DLL return a Delphi PChar, which is essentially a null terminated string. When I call the functions, the strings get passed in OK but the return values don't work correctly - one of the functions returns garbage and the other returns an empty string.

Included below are my declare statements...
Code:
Declare Function PutLetterInfoIntoReg Lib "letlib9.dll" _
                    (ByVal lsWhichMacro As String) As String

Declare Function readRegString Lib "letlib9.dll" _
                    (ByVal lsWhichMacro As String, ByVal lsWhichField As String) As String

Any ideas what I'm doing wrong?

Thanks Jonathan
jon_george1@hotmail.com

Working against: Visual Basic, Access, Visual Interdev, VBScript, JavaScript, Active Server Pages, SQL Server, Oracle, XML
 
I'm wont pretend to be a delphi expert but "PChar" lead me to beleive that this is not actually a string but a POINTER to a null terminated string.

Does it seem like the "garbage" could be a memory address?
 
Technically, the Delphi DLL can only modify the string that is passed to it, rather than creating a new string and trying to pass it back.

So either it isn't written correctly do that (in which case it would need to be rewritten) or you are not passing a pointer to a long enough block of memory...

I suspect the latter, so try something like:
[tt]
Dim lsWhichMacro as String
Dim lsWhichField as String
lsWhichMacro=Space(1024) ' reserve 1024 bytes
lsWhichField=Space(1024) ' reserve 1024 bytes
Call readRegString(lsWhichMacro, lsWhichField)
[/tt]
You'll need to do some Trimming of the result, obviously.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top