On 12/30/05, L505 <[EMAIL PROTECTED]> wrote:
> * how can you allocate memory for a function result, on the calling side, and 
> then
> free it on the calling side too? The function result is not a parameter that 
> can be
> controlled by you, on the calling side. A parameter can be allocated 
> precisely,
> controlled precisely, freed precisely.
>
> Now I don't have the original email - is he returning static or constant 
> text? It may
> be safe. I forget now, what he was trying to do. Where is the memory being 
> allocated
> for the Pchar, again?

This is what looks the best to me: the calling application must passe
a pointer to the DLL so that it would be filled. I'm currently doing
this:

function MakeMD5Hash(aValue: pchar): pchar; stdcall;
var
 s: string;
 size: Integer;
begin
 s := MD5Print(MD5String(aValue));
 size := Length(s) + 1;

 Result := nil;
 GetMem(Result,size);
//  Result := StrAlloc(size); //Use strings;

 Move(Pointer(s)^, Result^, size);
end;

But as I see, it should be a procedure, or a function that returns an
integer/boolean value. Then that would be like in a API. I need that
my pascal DLL works with other languages (any of them that support
stdcall and dlls).

I dont know yet the best way to do that... like the calling
application must 'reserve' the 32+1 chars in the string...

Would that works?:

procedure MakeMD5Hash(aValue, hash: pchar); stdcall;
var
 s: string;
begin
 s := MD5Print(MD5String(aValue));
 Move(Pointer(s)^, hash^, Length(s) + 1);
end;

Regards.

--
Alexandre Leclerc

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to