Recent

Author Topic: non English characters in paths  (Read 3462 times)

JHAx86

  • Newbie
  • Posts: 5
non English characters in paths
« on: April 04, 2009, 06:42:30 am »
Hello,

I have the following problem, given the following code:

uses
  Windows, .... , ShellApi;

....

begin
  ShellExecuteA(Handle, 'open', 'C:\Mis documentos\cosas del Río', nil, nil, SW_SHOWNORMAL);
end;

The resulting program behavior is as expected in Delphi 5 but not in Lazarus. After many tries I realized it is because of the 'í' in the path. When you install Windows in spanish, all paths have spanish characters in it, for example: 'My documents' becomes 'Mis documentos', and 'Start Menu' becomes 'Menú inicio'. As a result many of my programs using calls to Windows api fail when running in a spanish installation of Windows (my natural language is spanish). The above piece of code does not run on my own computer if compiled with Lazarus! Only if I use a short path with no 'í' character in it I can compile a working program. But I cannot change the paths my program uses because it allows the user to enter it! And in my country many will have 'í' or 'ú' in it.

How can I make Lazarus to accept non-english characters when doing external calls?

Please note that ShowMessage('Menú inicio') will display the 'ú' normally. I don't known what the problem could be. Also, I don't understand why there is any difference between passing an 'ú' to static libraries and passing an 'ú' to external calls.

Thank you for read.

Edited 2009/04/11:

Before do a call to a Windows API functions don't forget to convert your strings from utf-8 (Lazarus lcl default) to Unicode and then use the Unicode version of the API function. In modern Windows, all functions have an unicode version, usually ended in 'W' again the ANSI version ended in 'A'. For example ShellExecuteW, if you do first utf8ToUnicode and pass the resulting string to ShellExecuteW the behavior will be as expected. Note: do not use utf8toAnsi, that will not work if the string contains 'ú' or 'í', etc, because those characters will be mapped to two characters instead of the correct single byte representation.

Well, I had a hard time trying to figure why my calls to Windows API failed. It is due to string encoding. Maybe this is obvious for regular Lazarus users. If that's the case feel free to delete this post.
« Last Edit: April 11, 2009, 06:24:32 pm by JHAx86 »

 

TinyPortal © 2005-2018