(Solucionado)
Me contesto a mi mismo. He estado estudiando el problema en profundidad y he
encontrado 2 errores en el codigo anterior. Estos son los dos fallos que habia:
1) En el mundo de 64-bit es necesario crecer los parametros DWORD a DWORD_PTR.
Ya que DWORD_PTR se mapea a DWORD en sistemas 32-bits
2) La funcion CallBack debe estar definida y fuera del procedimiento que la va
a llamar.
Ahora he modificado el codigo y ahora funciona tanto en 32 bits como en 64 bits.
Código Delphi
[-]
function EditStreamReader( dwCookie: DWORD_PTR; pbBuff: PByte;
cb: LongInt; var pcb: Longint): LongInt; stdcall;
begin
result := $0000;
try
pcb := TStream(dwCookie).Read(pbBuff^, cb) ;
except
result := $FFFF;
end;
end;
procedure AppendToRichEdit(const source, destination : TRichEdit) ;
var
rtfStream: TEditStream;
sourceStream : TMemoryStream;
begin
destination.Lines.BeginUpdate;
sourceStream := TMemoryStream.Create;
try
source.Lines.SaveToStream(sourceStream) ;
sourceStream.Position := 0;
destination.MaxLength := destination.MaxLength + sourceStream.Size;
rtfStream.dwCookie := DWORD_PTR(sourceStream) ;
rtfStream.dwError := $0000;
rtfStream.pfnCallback := @EditStreamReader;
destination.Perform(
EM_STREAMIN,
SFF_SELECTION or SF_RTF or SFF_PLAINRTF, LPARAM(@rtfStream)
) ;
if rtfStream.dwError <> $0000 then
raise Exception.Create('Error appending RTF data.') ;
finally
sourceStream.Free;
destination.Lines.EndUpdate;
end;
end;