I have a DLL in which I have a function that returns a pchar. (as to avoid having to use borlndmm) What I was doing originally was casting a string as a pchar and returning that
Result := pChar(SomeFuncThatReturnsString)
But I was getting expected results 90% of the time and the other times I would get back nothing.
I then got to thinking that I needed to allocate the memory for the pchar and that doing it my original way was having a pchar point to memory that was not always going to be what was there when the function was called originally. So I now have this
Result := StrAlloc(128);
Strcopy(Result,PAnsiChar(Hash(Hash(Code,1,128),2,128)));
But this leaves me with having to clean up the allocated memory on the programs end which I do with
StrDispose(Pstr);
So the $64 question is: Do I have to allocate memory when returning a PChar from a function inside a DLL or can I just cast it to a PChar?