Since I’ve upgraded from delphi 5 to XE I’m struggling to use specific Dlls that were compiled a while ago. My blocking point seems related to the unicode/ansi character but I haven’t found out how to solve the problem
Here is an example of procedure:
procedure GetFilename(Buffer: PChar; BufSize: Integer); stdcall;
In my code I’m calling this that way
implementation
procedure GetFilename; external 'myDll.dll' name 'GetFilename';
procedure myproc
var
buffer : Array [0..255] of Char;
begin
GetFilename(buffer, length(buffer)-1);
Showmessage(buffer); //This gives me chinese character
end;
Buffer contains this:
byte((@buffer[0])^); // 67 which is the ASCII for C
byte((@buffer[1])^); // 92 which is the ASCII for \
what I’m expecting normal is a string starting with “C:\”
Has anyone faced the same problem?
Because the dll was made using a non-Unicode version of Delphi you must change the declaration from
to
and the buffer variable from
to
Additionally to learn about the Delphi Unicode support take a look to the
Delphi and UnicodeWhitepaper from Marco Cantú.