how can D program find it's own executable name on windows ?
Regan Heath
regan at netmail.co.nz
Tue Jan 29 08:28:33 PST 2013
On Tue, 29 Jan 2013 15:51:08 -0000, rsk82 <rsk82 at live.com> wrote:
> On Tuesday, 29 January 2013 at 15:46:40 UTC, monarch_dodra wrote:
>> stdout.writeln(args[0]);
>
> It doesn't work while I have WinMain function that then calls myWinMain,
> as it is winsamp.d
>
> Error: undefined identifier args, did you mean struct CArgs?
Try..
1. Add these lines to the top of winsamp.d (after other includes)
import core.sys.windows.windows;
import std.utf;
string commandLine = null;
2. Add these lines to myWinMain (after variable declarations, before
wndclass.style..)
wchar[260] moduleName;
uint n = GetModuleFileNameW(null, moduleName.ptr, moduleName.length);
commandLine = toUTF8(moduleName[0..n]);
3. In WindowProc (I had to add nothrow to my definition BTW) change this
line
TextOutA(dc, r.right / 2, r.bottom / 2, text.toStringz, text.length);
to read:
TextOutA(dc, r.right / 2, r.bottom / 2, commandLine.toStringz,
commandLine.length);
4. Compile/run it, i.e. dmd -run winsamp.d
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list