How to detect current executable file name?

Jacob Carlborg doob at me.com
Mon Feb 18 01:07:45 PST 2013


On 2013-02-18 09:21, eGust wrote:

> Thanks for your reply. Does anyone know, will it be added into D2's
> standard library?

Not until someone makes a pull request.

> p.s. About the code, I don't know how it work on other platform, but on
> windows it will get a bad result if the path contains any non-ASCII
> character and D1's char[] is UTF-8 encoded. GetModuleFileNameA will get
> a string encoded as the ACP setting but not UTF-8. ASCII character is
> well compatible with most character sets (Windows' ACP setting)
> including UTF-8. But once a non-ASCII character in the path (like me, a
> Chinese user, a lot Chinese characters namd dirs on my PC, ACP is
> 936--GBK), it fails. Better way is to use GetModuleFileNameW and wchar[]
> then convert back to char[].
> Anyway, thank you very much!

Yeah, GetModuleFileNameW should be used. I'm pretty sure the other 
platforms will return UTF-8.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list