Win32 Application Error
Loopback
elliott.darfink at gmail.com
Tue Jun 28 17:30:25 PDT 2011
Hi!
I've recently been using D to program win32 executables. On the official
D site (d-programming-language.org) there is a template of how a basic
win32 executable is supposed to be. In this template you are supposed to
initialize and terminate the D runtime. If I understand correctly this
runtime is related to garbage collection and static con- and
destructors.
This snippet below from my own code works perfectly fine at my
other computer (though both of my computers uses the exact same OS;
win7 x64 Ultimate).
My problem occurs when I terminate the runtime. With one of my computers
it works flawlessly, while on this computer the application hangs up on
exit. I've debugged the code located it to where I terminate the
runtime. The application stops responding completely. Now the
interesting part is that the application do close, but the process still
runs. So you do not notice it at all practically, until you check in the
task manager. The process ends after a while, varying from 5 seconds to
50 seconds.
This is what happens if I press the close button (in the corner). If I
close the program with PostQuitMessage(0) instead, the application is
still visible but a "Program is not resonding" appears. This also
happens at "runtime terminate".
So my question is; how should I avoid these "process still running" and
program not responding errors?
(if worth mentioning, the program itself works perfectly fine, it is
just at exit the program 'bugs').
The code below is my main.d file.
// Win32 Imports
import win32.windef;
import win32.winuser;
// STD&Core Includes
import core.runtime;
import std.utf;
// Custom Includes
import cwindow;
import global;
// Application Entry Point
extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE
hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
int result;
void exceptionHandler(Throwable e) { throw e; }
try
{
// Start Runtime
Runtime.initialize(&exceptionHandler);
// Create Application
CWindow wndw = new CWindow(hInstance);
// Control Object
if(wndw !is null)
result = 1;
// Terminate Runtime
Runtime.terminate(&exceptionHandler); // It always crashes here
}
catch(Throwable o)
{
MessageBoxW(null, o.toString().toUTF16z, "Error", MB_OK |
MB_ICONEXCLAMATION);
result = 0;
}
return result;
}
More information about the Digitalmars-d-learn
mailing list