Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 29, 2013 how can D program find it's own executable name on windows ? | ||||
---|---|---|---|---|
| ||||
Are there any build in function or must I resort to winapi ? |
January 29, 2013 Re: how can D program find it's own executable name on windows ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rsk82 | On Tuesday, 29 January 2013 at 15:33:29 UTC, rsk82 wrote:
> Are there any build in function or must I resort to winapi ?
args[0]?
//----
import std.stdio;
void main(string[] args)
{
stdout.writeln(args[0]);
}
//----
|
January 29, 2013 Re: how can D program find it's own executable name on windows ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rsk82 | Le 29/01/2013 10:33, rsk82 a écrit :
> Are there any build in function or must I resort to winapi ?
int main(string[] argv)
{
writeln(argv[0] ~ " is what you are looking for");
}
^^
|
January 29, 2013 Re: how can D program find it's own executable name on windows ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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?
|
January 29, 2013 Re: how can D program find it's own executable name on windows ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rsk82 | On Tue, 29 Jan 2013 15:51:08 -0000, rsk82 <rsk82@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/ |
January 30, 2013 Re: how can D program find it's own executable name on windows ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rsk82 | On Tuesday, 29 January 2013 at 15:51:09 UTC, rsk82 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?
If you pass the following on the command line:
-L/SUBSYSTEM:windows:5
You can get rid of your WinMain function and use a standard main, while still getting a "windowed" app instead of a console app. Dropping the :5 would allow you to support Windows 9x, but DMD doesn't (or isn't going to) support that anymore anyway. I always add :5 for XP and higher.
When running with main, DRuntime stores the args, so you can access them anywhere in your program by importing core.runtime and accessing the Runtime.args property. I had assumed that held true when WinMain was used, but after scanning through the source I don't see that it is.
|
Copyright © 1999-2021 by the D Language Foundation