Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 24, 2018 Windows 7 x64. Prevent appearing of console with GUI application | ||||
---|---|---|---|---|
| ||||
Hello! I'm trying run my GUI application getting a console hidden. The application is on top of GTKD, compiled with dmd 2.081.1 in Windows 7 x64. I read a few threads on the forum and StackOverflow and I got that I need to add a module definition file [1] or to add -L/SUBSYSTEM:WINDOWS -L/ENTRY:mainCRTStartup options to compiler [2] or to add only /SUBSYSTEM:WINDOWS [3] or use a command getting console hidden [4]. Actually no one case works properly. The first one doesn't affect, the second "unbinds" appeared console giving ability to close it without closing the application, the third one raises a linker error about unresolved symbol WinMain, the fourth one hides a console but it does it with delay. Also, I tried to use `editbin /SUBSYSTEM:windows myapp.exe` but I it doesn't affect anything. Here is my dub.json [5] So... how prevent appearing of console on the startup of the application? [1] https://wiki.dlang.org/D_for_Win32 [2] https://forum.dlang.org/post/bhswtzoklrzzslliqkvr@forum.dlang.org [3] https://forum.dlang.org/post/qcejigllwticykoiwppr@forum.dlang.org [4] https://stackoverflow.com/a/2139903 [5] http://vpaste.net/mEy2P |
July 24, 2018 Re: Windows 7 x64. Prevent appearing of console with GUI application | ||||
---|---|---|---|---|
| ||||
Posted in reply to ANtlord | On Tuesday, 24 July 2018 at 08:09:33 UTC, ANtlord wrote:
> So... how prevent appearing of console on the startup of the application?
Here's my test
---
module HelloMsg;
import core.runtime;
import std.utf;
import core.sys.windows.windows;
auto toUTF16z(S)(S s)
{
return toUTFz!(const(wchar)*)(s);
}
extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
int result;
void exceptionHandler(Throwable e) { throw e; }
try
{
Runtime.initialize();
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, iCmdShow);
Runtime.terminate();
}
catch (Throwable o)
{
MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | MB_ICONEXCLAMATION);
result = 0;
}
return result;
}
int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
MessageBox(NULL, "Hello, Windows!", "Your Application", 0);
return 0;
}
---
dmd -L/SUBSYSTEM:WINDOWS main.d
main.obj : error LNK2019: unresolved external symbol MessageBoxW referenced in function WinMain
dmd -L/SUBSYSTEM:WINDOWS main.d User32.lib
Success!
Executing from PowerShell: no console
Executing from Command Prompt: no console
Double-clicking in Explorer: no console
Windows 10 64-bit
Mike
|
July 24, 2018 Re: Windows 7 x64. Prevent appearing of console with GUI application | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Franklin | On Tuesday, 24 July 2018 at 08:48:54 UTC, Mike Franklin wrote: > > Here's my test > > extern (Windows) > int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) When using WinMain, subsystem:windows is the default. The OP wants to use main as the entry point, where the console subsystem is the default. |
July 24, 2018 Re: Windows 7 x64. Prevent appearing of console with GUI application | ||||
---|---|---|---|---|
| ||||
Posted in reply to ANtlord | On Tuesday, 24 July 2018 at 08:09:33 UTC, ANtlord wrote:
> Hello! I'm trying run my GUI application getting a console hidden. The application is on top of GTKD, compiled with dmd 2.081.1 in Windows 7 x64. I read a few threads on the forum and StackOverflow and I got that I need to add a module definition file [1] or to add -L/SUBSYSTEM:WINDOWS -L/ENTRY:mainCRTStartup options to compiler [2] or to add only /SUBSYSTEM:WINDOWS [3] or use a command getting console hidden [4].
I've never used a module definition file for this. The /subsystem:windows switch has always worked for me. When linking with OPTLINK, that's all you need. When using the MS linker, you'll need that along with the /ENTRY:mainCRTStartup. With recent versions, if you don't have the MS tools installed, you'll get the LLVM linker when using -m64 or -m43mscoff. If that's the case, I don't know that it even supports changing the subsystem or, if it does, what the syntax looks like. A cursory search turns up nothing.
Anyway, if you are using OPTLINK or the MS Linker, try a test program without gtkD to make sure it works standalone for you.
```
import core.sys.windows.windows;
void main() {
MessageBoxA(null, "Look, Ma! No console!", "It works!", MB_OK);
}
```
Both of the following command lines work for me.
With OPTLINK:
dmd -L/SUBSYSTEM:windows win.d
With the MS linker:
dmd -m64 -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup win.d user32.lib
|
July 24, 2018 Re: Windows 7 x64. Prevent appearing of console with GUI application | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Tuesday, 24 July 2018 at 09:20:22 UTC, Mike Parker wrote:
> On Tuesday, 24 July 2018 at 08:09:33 UTC, ANtlord wrote:
>
> Anyway, if you are using OPTLINK or the MS Linker, try a test program without gtkD to make sure it works standalone for you.
>
> ```
> import core.sys.windows.windows;
>
> void main() {
> MessageBoxA(null, "Look, Ma! No console!", "It works!", MB_OK);
> }
> ```
You partially are right, the issue is related to the application internals but not to GTKD. I forgot that I launch the second application inside. I recompiled both of the with -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup and that's it.
Thanks a lot everyone!
|
Copyright © 1999-2021 by the D Language Foundation