CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2009
    Posts
    15

    How to pass strings from a dll

    I am new to DLL writing
    I can return numbers from a DLL but seem unable to return strings.
    Anyone know how to do this in a DLL ?

    Thanks in advance !

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: How to pass strings from a dll

    Dll is a library, just a bunch of functions. Can you return strings from functions? If yes, you can return strings from dll.

    BTW, string is the most ambiguous thing in C++. What kind of strings you imply?
    Best regards,
    Igor

  3. #3
    Join Date
    Nov 2009
    Posts
    15

    Re: How to pass strings from a dll

    I want to return


    Either char or a pointer to string.

    Its for use in a basic compiler called Liberty Basic you might have heard of it or not

    I have written DLLs that return numbers for liberty basic but cant seem to get my head around strings at all.

    I think you have to allocate memory for it first but i am not sure the books i have on writing dll's are not that clear when it comes to this.

    They are very clear when returning numbers.

    I will read up on returning strings from functions.

    Any further help will be greatly appreciated.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: How to pass strings from a dll

    Okay man, now it turns out that you need to return Basic strings.

    So let me ask you a few questions. Do you completely understand that these languages may (or better say, must) have different concepts of strings and therefore different implementations of string object? Do you completely understand, that trying to return Basic string from C code you need to know the low-level details of how Basic string should look like in memory? And now, do you know those details? Or do you have an idea of how/where to find them? Or returning pointer to C string, are you sure the Basic is able to understand it?

    BTW, your real situation has no connection to dll stuff.
    Last edited by Igor Vartanov; November 14th, 2009 at 02:40 PM.
    Best regards,
    Igor

  5. #5
    Join Date
    Nov 2009
    Posts
    15

    Re: How to pass strings from a dll

    Yes I understand that this Language handles strings in a non C++ way.

    The Basic copies the string in memory then adds a null terminator (An ASCII ZERO)
    This technique provides a copy of the original string to be passed to the dLL function. If the function then modifies that string directly , then the Liberty BASIC application calling the function cannot access the modified string because only the copy is modified.

    The way to fix this is for the code to include the ASCII zero onto the end of the string that will be used as a parameter in the API call. Liberty BASIC checks for the ASCII zero, and if it finds it, passes the memory address of original string and does not make a copy. This is only necessary if an application passes a string, expecting to get it back modified by the DLL function called.

    Thanks

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: How to pass strings from a dll

    So that's it, all in your hands. (though I didn't get anything)
    Best regards,
    Igor

  7. #7
    Join Date
    Nov 2009
    Posts
    15

    Re: How to pass strings from a dll

    OK thanks anyway

  8. #8
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: How to pass strings from a dll

    I am also not sure what the actual question is now.
    My hobby projects:
    www.rclsoftware.org.uk

  9. #9
    Join Date
    Nov 2009
    Posts
    15

    Smile Re: How to pass strings from a dll

    I have resolved all issues with this.

    As Igor said the issue was not with the dlll
    it was with the basic.

    Once I got my head around that I was able to get it to work.

    Thanks again Igor.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured