digitalmars.D.learn - how can D program find it's own executable name on windows ?
- rsk82 (1/1) Jan 29 2013 Are there any build in function or must I resort to winapi ?
- monarch_dodra (9/10) Jan 29 2013 args[0]?
- rsk82 (4/5) Jan 29 2013 It doesn't work while I have WinMain function that then calls
- Regan Heath (21/26) Jan 29 2013 Try..
- Mike Parker (13/19) Jan 29 2013 If you pass the following on the command line:
- n00b (6/7) Jan 29 2013 int main(string[] argv)
Are there any build in function or must I resort to winapi ?
Jan 29 2013
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]); } //----
Jan 29 2013
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?
Jan 29 2013
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: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/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?
Jan 29 2013
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: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.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?
Jan 29 2013
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"); } ^^
Jan 29 2013