Hello All,
I am having a problem when returning a PChar from a function using Delphi 6. First of all, most of my functions pass type 'strings' around, but I am creating a DLL, to make sure it's universal, i can only pass type 'PChar' in and out of my DLL function. So when I get the 'PChar' from the function call, I change them to strings. I do this because strings are so much easier to work with, and performance with this DLL is not really an issue.
So pressing forward. When I get to the end of my function, I want to to pass the string back out of the function, so I do a PChar(MyString) where MyString is my variable of type string. What happens is when I get the PChar out of my function, I get a ASCII '0' (zero) appended to the end. Inside my function I get no such character. Let me show you the different ways I have tried to pass this PChar:
result := PChar(MyString);
and
MyString := MyString + #0;
result := @MyString[1];
and my function looks like this, MyPChar is of type 'PCHar'
MyPChar := DLLFunction(RandomCrap);
The second on was a long shot, I assume that is what the PChar function does. But I still get a '0' printed to the end of my string.
Any suggestions or comments would help.