Using C++ DLL's and null-terminated strings
Posted on 2005-04-19
I am trying to interface to a dll that was written in C++ using Delphi 2005 Win32.
All of my interfaces work fine except when a null-terminated string / array of char (C++ : char *returnstring) is used as an var / out parameter.
I essentially have to pass it a pointer / variable to return results in.
I have tried passing a PChar variable, but as soon as the result is returned from the dll i get access violations when trying to access it. This is the case for any assignment to/from it and also when applyting any function to it eg StrLength. I then wrote it to manually assign memory to the variable with GetMem with the same result. I think it might have something to do with the dll becuase the av address and the address it is trying to read is the same. The developer of the dll assured me that he does no memory assignment, allocation or unallocation.
I can access the result with an array of Char, but this variable type is limited in size. I need the variable to go to a maximum of 30Mb and an array of Char starts to give me trouble if it gets to about 750K. I cannot pass a dynamic array and set the size accordingly because the dll won't accept it. So I'm stuck with static arrays.
I'm looking for a way to interface with this out parameter (what variable / pointer type to use) or a way that I can assign 30Mb to a static array of Char.
I've got a deadline to make and this is very urgent so I will pay 1000 points for the solution. I'll register a new question to award the other 500 points as soon as I have a solution.