Hi Coders!
I would like to make two DLL function:
1.) EnCode a PChar text with TBase64EncodingStream
2.) DeCode a PChar text with TBase64DecodingStream
Here it is my code:
library code_v004;
uses
sysutils, Classes, base64;
var
DecodedStream: TStringStream;
EncodedStream: TStringStream;
Encoder: TBase64EncodingStream;
Decoder: TBase64DecodingStream;
// enCode
function enCode(x: PChar): PChar; stdcall;
begin
DecodedStream := TStringStream.Create(x);
EncodedStream := TStringStream.Create('');
Encoder := TBase64EncodingStream.Create(EncodedStream);
Encoder.CopyFrom(DecodedStream, DecodedStream.Size);
result := PChar(EncodedStream.DataString);
end;
// deCode
function deCode(x: PChar): PChar; stdcall;
begin
EncodedStream := TStringStream.Create(x);
DecodedStream := TStringStream.Create('');
Decoder := TBase64DecodingStream.Create(EncodedStream);
DecodedStream.CopyFrom(Decoder, Decoder.Size);
result := PChar(DecodedStream.DataString);
end;
exports
enCode, deCode;
begin
end.
First look, it seems working.
But with every text!
Try this string: Háromszéki Zsolt
The encoded string will be: SOFyb21zeulraSBac29s
But really, the encoded string isn't the whole string. Four characters (dA0K) miss from the end. The real encoded string should be: SOFyb21zeulraSBac29sdA0K
With other strings, the enCode() function works properly. But what about the 'Háromszéki Zsolt' text? Why doesn't work with it?
Do you have any idea?
Thank you in advance.
Relative