Thread: Delphi DLL Problem, C++ hates Delphi strings

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    62

    Delphi DLL Problem, C++ hates Delphi strings

    So I have a problem that I can't easily solve. I have dlls that I need to access. The problem is that I don't have the source code to them and they are writen in delphi. They come with a handy function that lists out all procedures in the DLL, but alas, many of the procedures use the Delphi string.

    Whats worse is that the function itself seems to use a delphi string so I can only get about 2 calls out of it before it decides it must write somewhere I don't want it to.

    So is there any sort of compatibility library or even just some code I could use that would make a delphi string in c++ so that I can access these functions. or even a suggestion of what route I should take to solve this problem.
    Last edited by Cogman; 09-06-2008 at 04:29 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    My guess is that delphi strings are a byte of length and length number of bytes of string content. But I have never used Delphi, only it's predecessor Turbo Pascal.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    62
    Strings in delphi are somewhat dynamic (IE 'string ' + 'string' = 'string string'). Some have told me that the first bit declares how long the string is, but I haven't seen that for myself. Maybe I am missing something, I don't know. The problem is that some of those functions have the string passed in by reference.

    Ok, so I was mess up with the application. For reasons beyond me, the function needed to have its own thread to run in (I thought the access violation was due to memory being written that shouldn't have been). So I made a thread for the function and viola. things worked as they should. Go figure. As for the string thing, delphi strings variables point to the first element of the strings actual data while the stuff before the string is data on the string length ect. Thats just confusing. Either way, the function accepted my call when a thread was created and now things are hunky dory. Thank for reading.
    Last edited by Cogman; 09-06-2008 at 10:21 PM.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    FYI: That technique is no stranger to Windows; You've just described the BSTR.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    As far as I am aware, that is how strings are stored in Delphi, Cogman. Though I won't lie and pretend like I pass strings between languages. I will mess with my delphi compiler later on tonight to see what the deal is. I bet one could probably google the answer before I even write down a single line of code.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok, I am going to go ahead and confirm the string thing. Why not just stick to using PChars in the first place?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 11:47 PM
  2. problem in calling DLL
    By bhagwat_maimt in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 10:43 PM
  3. DLL Function / Load Library Problem
    By cboard_member in forum Windows Programming
    Replies: 5
    Last Post: 12-10-2005, 10:11 AM
  4. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  5. Question about Delphi DLL
    By cpryor in forum C++ Programming
    Replies: 0
    Last Post: 11-23-2001, 08:39 AM