Thread overview
Re: Possible codegen bug when using Tcl/Tk (related to DMC and DMD)
Aug 17, 2013
Andrej Mitrovic
Aug 18, 2013
yaz
Aug 18, 2013
Andrej Mitrovic
August 17, 2013
On 8/17/13, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> First, here is the C code:

Btw, here's the D equivalent where I can also recreate the bug:

-----
import core.sys.windows.windows;
import std.stdio;

alias extern(C) void* function() Tcl_CreateInterp_Type;
alias extern(C) int function(void*) Tcl_Init_Type;
alias extern(C) int function(void*) Tk_Init_Type;
alias extern(C) int function(void*, const(char)*) Tcl_Eval_Type;
alias extern(C) void function() Tk_MainLoop_Type;

int main()
{
    HMODULE hTcl = LoadLibraryA("tcl86.dll");
    HMODULE hTk = LoadLibraryA("tk86.dll");

    Tcl_CreateInterp_Type Tcl_CreateInterp;
    Tcl_CreateInterp = cast(Tcl_CreateInterp_Type)GetProcAddress(hTcl,
"Tcl_CreateInterp");

    Tcl_Init_Type Tcl_Init;
    Tcl_Init = cast(Tcl_Init_Type)GetProcAddress(hTcl, "Tcl_Init");

    Tk_Init_Type Tk_Init;
    Tk_Init = cast(Tk_Init_Type)GetProcAddress(hTk, "Tk_Init");

    Tcl_Eval_Type Tcl_Eval;
    Tcl_Eval = cast(Tcl_Eval_Type)GetProcAddress(hTcl, "Tcl_Eval");

    Tk_MainLoop_Type Tk_MainLoop;
    Tk_MainLoop = cast(Tk_MainLoop_Type)GetProcAddress(hTk, "Tk_MainLoop");

    void* _interp = Tcl_CreateInterp();
    Tcl_Init(_interp);
    Tk_Init(_interp);

    Tcl_Eval(_interp, "tkwait visibility .");
    Tcl_Eval(_interp, "tk::toplevel .mywin");
    Tcl_Eval(_interp, "wm resizable .mywin false false");

    Tk_MainLoop();

    return 0;
}
-----

I've also tried the C sample with various DMC versions such as 857, 846, 837, 830, but I still haven't found a version that doesn't have this bug.

Maybe the issue is with something else.. I can't tell what DMC and GCC are doing differently here.
August 18, 2013
On Saturday, 17 August 2013 at 21:34:24 UTC, Andrej Mitrovic wrote:

I think this is the same issue as https://github.com/aldacron/Derelict3/issues/143

The solution advised by aldacron (Mike Parker) in his last few posts is to compile your D executable as a Windows subsystem exe or use WinMain instead of main.

> On 8/17/13, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
>> First, here is the C code:
>
> Btw, here's the D equivalent where I can also recreate the bug:
>
> -----
> import core.sys.windows.windows;
> import std.stdio;
>
> alias extern(C) void* function() Tcl_CreateInterp_Type;
> alias extern(C) int function(void*) Tcl_Init_Type;
> alias extern(C) int function(void*) Tk_Init_Type;
> alias extern(C) int function(void*, const(char)*) Tcl_Eval_Type;
> alias extern(C) void function() Tk_MainLoop_Type;
>
> int main()
> {
>     HMODULE hTcl = LoadLibraryA("tcl86.dll");
>     HMODULE hTk = LoadLibraryA("tk86.dll");
>
>     Tcl_CreateInterp_Type Tcl_CreateInterp;
>     Tcl_CreateInterp = cast(Tcl_CreateInterp_Type)GetProcAddress(hTcl,
> "Tcl_CreateInterp");
>
>     Tcl_Init_Type Tcl_Init;
>     Tcl_Init = cast(Tcl_Init_Type)GetProcAddress(hTcl, "Tcl_Init");
>
>     Tk_Init_Type Tk_Init;
>     Tk_Init = cast(Tk_Init_Type)GetProcAddress(hTk, "Tk_Init");
>
>     Tcl_Eval_Type Tcl_Eval;
>     Tcl_Eval = cast(Tcl_Eval_Type)GetProcAddress(hTcl, "Tcl_Eval");
>
>     Tk_MainLoop_Type Tk_MainLoop;
>     Tk_MainLoop = cast(Tk_MainLoop_Type)GetProcAddress(hTk, "Tk_MainLoop");
>
>     void* _interp = Tcl_CreateInterp();
>     Tcl_Init(_interp);
>     Tk_Init(_interp);
>
>     Tcl_Eval(_interp, "tkwait visibility .");
>     Tcl_Eval(_interp, "tk::toplevel .mywin");
>     Tcl_Eval(_interp, "wm resizable .mywin false false");
>
>     Tk_MainLoop();
>
>     return 0;
> }
> -----
>
> I've also tried the C sample with various DMC versions such as 857,
> 846, 837, 830, but I still haven't found a version that doesn't have
> this bug.
>
> Maybe the issue is with something else.. I can't tell what DMC and GCC
> are doing differently here.

August 18, 2013
On 8/18/13, yaz <yazan.dabain@gmail.com> wrote:
> I think this is the same issue as https://github.com/aldacron/Derelict3/issues/143

I remember seeing that! I also tried -L/SUBSYSTEM:WINDOWS at first (without the number), but it didnt' make a difference. However using -L/SUBSYSTEM:WINDOWS:5.01 actually fixes the issue. Thanks!

But I would still like to know why this behavior happens without this flag. Does anyone know?