I’m probably missing something really obvious here, so I’m hoping that someone will be able to point out precisely how I’m being an idiot
I’m using an instance of Shell to run commands on Windows, and struggling to work out how to work with file paths that include accented characters. Here’s a simple test:
Create a file that contains an accented character (e.g. “”) in its path.
Copy the following into a sample project:
[code]dim theShell as Shell = New Shell
dim theCommand as String
dim theDialog as New OpenDialog
dim theFile as FolderItem
theFile = theDialog.ShowModal
if theFile = Nil then
Return
end if
if theShell.ErrorCode <> 0 then
Break
end if[/code]
Run that, and select the file that you created in step 1.
If you select a file that doesn’t include an accented character, the shell command will open the file. If the path includes an accented character, the shell returns error code 1, “The system cannot find the path specified.”
I must be doing something pathetically obviously wrong here. How do I make this work with accented characters?
Thanks, Paul. That looks helpful if I were working with batch files and know which code page to specify, but I don’t know how I would go about applying that to a shell command that needs to work with an arbitrary file path.
This is probably really obvious to people who know more about Windows than I do, especially those who are more likely to have an accented character in their username. The actual example that I’ve seen from a customer is ““C:\Users\Cline\AppData\Local\Temp\257612791824.html””
It looks like Xojo is using the ASCII call instead of the Unicode call, try this (works here)
Declare Function ShellExecute Lib "Shell32" Alias "ShellExecuteW" (hwnd As Ptr, lpOperation As WString, lpFile As WString, lpParameters As WString, lpDirectory As WString, nShowCmd As Int32) As Integer
Dim ok As Integer
ok = ShellExecute(Nil, "open", theFile.NativePath, "", "", 5)
Thanks, Julian. Yes, it does rather look like Xojo might be using ASCII rather than Unicode.
Your example works well in my test case, so thanks for that. However, the real use case is rather more complicated in that I’m using a shell command to tell WKHTMLTOPDF to convert an HTML file to a PDF, like so:
Thanks, Julian. I’ve just tried what you suggested with a non-accented file path and, although the returned value is >32 and therefore according to this page not an error, something’s wrong with the call to WKHTMLTOPDF but I’m not sure where to find the error output.
I submitted this feedback case with regard to building Windows 64-bit (2015 R3B9) applications when some of the files use accented characters. The status is “verified”.
Therefore, as of current releases, one still cannot build 64 bit with containers, classes etc. using accented characters.