digitalmars.D.learn - Program exited with code 1
- Andrey (25/25) Apr 19 2018 Hello,
- user1234 (3/26) Apr 19 2018 The run-time is not already initialized but the "new" operator
- Andrey (2/4) Apr 19 2018 What will be a solution?
- Andrey (3/4) Apr 19 2018 It seems to me that I found a solution - just replace WinMain()
- Mike Parker (13/17) Apr 19 2018 That's fine when you want a console app, but it leaves you with a
Hello, I wrote a small test code with WinApi: ---------------------------------------------------- import core.runtime; import std.utf; import core.sys.windows.windows; import core.sys.windows.wingdi; class Test { public this() nothrow { } } extern(Windows) int WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) { new Test(); // error is here return 0; } ---------------------------------------------------- When I run it, there is an error: Program exited with code 1. If I comment "new Test();" - no error happens. Why? How to create instances of classes? DMD v2.077.1, Windows 10.
Apr 19 2018
On Thursday, 19 April 2018 at 08:13:00 UTC, Andrey wrote:Hello, I wrote a small test code with WinApi: ---------------------------------------------------- import core.runtime; import std.utf; import core.sys.windows.windows; import core.sys.windows.wingdi; class Test { public this() nothrow { } } extern(Windows) int WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) { new Test(); // error is here return 0; } ---------------------------------------------------- When I run it, there is an error: Program exited with code 1. If I comment "new Test();" - no error happens. Why?The run-time is not already initialized but the "new" operator relies on it.
Apr 19 2018
On Thursday, 19 April 2018 at 08:24:55 UTC, user1234 wrote:The run-time is not already initialized but the "new" operator relies on it.What will be a solution?
Apr 19 2018
On Thursday, 19 April 2018 at 08:37:19 UTC, Andrey wrote:What will be a solution?It seems to me that I found a solution - just replace WinMain() with main().
Apr 19 2018
On Thursday, 19 April 2018 at 11:21:52 UTC, Andrey wrote:On Thursday, 19 April 2018 at 08:37:19 UTC, Andrey wrote:That's fine when you want a console app, but it leaves you with a console window automatically popping up if you create a windowed app. When using WinMain, you have to manually setup and tear down DRuntime as described in the wiki[1]. Alternatively, you can get rid of the console window with a main function via linker flags -- when using OPTLINK (the default): -L/SUBSYSTEM:windows should be enough. With -m32mscoff or -m64, which uses the MS linker, you'll both that and this: -L/ENTRY:mainCRTStartup [1] https://wiki.dlang.org/D_for_Win32What will be a solution?It seems to me that I found a solution - just replace WinMain() with main().
Apr 19 2018