View Full Version : Returning string from DLL in V1.10.7.0
Hi New user here. Hope I haven't broken any rules!
I have recently upgraded from earlier version to current release V1.10.7.0
I find that returning a string from a DLL no longer works. Is this a known problem?
I use:
Declare Function MyName Lib "MyDllName.DLL" Alias "MyName" (ByRef InString As Asciiz, ByRef OutString As Asciiz) As Long
The DLL modifies OutString internally but on return to ThinBasic, the original value of OutString is maintained and the expected new value is lost. This works fine in V1.8.9.0 and V1.9.16.17 but fails in V1.10.7.0
ErosOlmi
16-01-2023, 08:29
Ciao GrahamC
I have to check simulating a DLL function like yours.
An ASCIIZ string is in reality a pointer to a null terminated sequence of chars.
Passing it BYREF means you are passing a pointer to a pointer to a null terminated sequence of chars.
I do not remember if I changed it in some ways.
I will check and let you know
Eros
ErosOlmi
16-01-2023, 09:06
One question: what language is your DLL written?
ErosOlmi
16-01-2023, 18:01
Ciao GrahamC
I've checked thinCore.dll Core engine and I think I've introduced a bug while adding support for WStringZ (Unicode null terminated strings) data type when interfacing with external DLLs.
Please find attached to this post a new thinCore.dll
Copy and replace the one you have into your \thinBasic\ install directory
Let me know if this fixes the problem.
Ciao
Eros
Thanks Eros for responding. I will try out that DLL and answer more fully before the weekend. My DLL is written in Lazarus Free Pascal. Currently I have a work around which works with old and new versions by replacing
Byref OutString As Asciiiz with
Dword OutString but it does not feel right to assign an Asciiz to a Dword.
The declaration of my DLL in Pascal is this:<br>
FUNCTION F(s1:PChar; s2:PChar):INTEGER; STDCALL;<br>The DLL performs some action depending on s1 and returns a response in s2. It does not modify s1. Usually s2 is not set on calling the DLL but it is here for debugging purposes.<br><br>This is the ThinBasic code I am using:<br>
Uses "trace"<br>
Uses "CONSOLE"<br>
<br>
Declare Function F Lib "FILE.DLL" Alias "F" ( ByRef s1 As Asciiz, ByRef s2 As Asciiz) As Long <br>
<br>
Dim Reply As Asciiz*1024 <br>
Dim p As DWord<br>
<br>
Reply="World" <br>
p=VarPtr(Reply)<br>
Console_WriteLine(F("Hello", Reply))<br>
Console_WriteLine(Reply)
In ThinBasic V1.8.9.0 I get this:
On calling the DLL, the value of p in ThinBasic is the same as the value of s2 in the DLL, and the contents of Reply in ThinBasic is the same as the contents of s2 in the DLL. On return from the DLL, the contents of Reply in ThinBasic is the same as the contents of s2 set by the DLL. So as expected.
In ThinBasic V1.10.7.0 I get this:
On calling the DLL, the value of p in ThinBasic is not the same as the value of s2 in the DLL, but the contents of Reply in ThinBasic <em>is</em> the same as the contents of s2 in the DLL. On return from the DLL, the contents of Reply in ThinBasic has not changed even though the contents of s2 in the DLL has been changed.
I will now test the ThinCore.Dll you sent.
The ThinCore.DLL you sent corrects the problem.
ErosOlmi
20-01-2023, 19:12
Great, thanks for your feedback.