Results 1 to 8 of 8

Thread: Returning string from DLL in V1.10.7.0

  1. #1

    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

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    One question: what language is your DLL written?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5

    Returning string from DLL V1.10.7.0

    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.

  6. #6

    Returning string from DLL V1.10.7.0

    The declaration of my DLL in Pascal is this:<br>
    FUNCTION&nbsp; F(s1:PChar; s2:PChar):INTEGER;&nbsp; &nbsp;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 &nbsp;<br>
    <br>
    Dim Reply As Asciiz*1024 &nbsp; &nbsp; &nbsp; &nbsp;<br>
    Dim p As DWord<br>
    <br>
    Reply="World" &nbsp;<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.
    Last edited by GrahamC; 20-01-2023 at 18:35.

  7. #7

    Returning string from DLL V1.10.7.0

    The ThinCore.DLL you sent corrects the problem.

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Great, thanks for your feedback.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Returning
    By Katogoon in forum thinBasic General
    Replies: 2
    Last Post: 10-10-2016, 22:11
  2. Problem with returning a string from a function
    By DavidMead in forum Module SDK (Power Basic version)
    Replies: 4
    Last Post: 26-11-2008, 12:51

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •