Hello all!
I'm running a program that's using GRX 2.4.6 under windows XP and
have noticed when 'X' button on GRX window is clicked and after I
confirm program abort in abort dialog, the window closes, but the
program process still remains active. If the program terminates
naturaly (ends main) no process is left hanging.
I have witnessed this behaviour on several XP machines, some with SP1
installed and some with no SP installed at all. I have not tried it on winXP
with SP2.
Under win2000 this effect does not occur and process terminates
itself nicely.
I've traced the problem to grx246/src/vdrivers/vd_win32.c
and to the call of ExitProcess(1) inside WM_CLOSE message handling
in WndProc method (line:523).
It apears that under windows XP ExitProcess() in grx lib does not terminate
the process properly for some reason, but I have not been able to establish
why is that nor have I tried an independent test of this function behaviour.
Anyway, I was able to produce the proper process termination of GRX program
with substituing ExitProcess(1) with TerminateProcess(GetCurrentProcess(),0)
which terminates GRX prg nicely both under windows XP, 2000 and 98.
Anyone noticed this?
I compiled GRX lib and example src using:
g++.exe (GCC) 3.2.3 (mingw special 20030504-1)
GNU Make version 3.79.1
The source file and a patch to 2.4.6 src tree I made that
aparently fixes the problem are attached below.
Best regards,
Mario Zagar
mario.zagar "AT" wbs-tech.hr
--- begin test.cc ---
#include <string.h>
#include <grx20.h>
#include <grxkeys.h>
#include <iostream>
#include <windows.h>
using namespace std;
int myexit(void)
{
cout << "myexit\n"; cout.flush();
return 0;
}
int GRXMain(void)
{
char *message = "Hello, GRX world";
int x, y;
GrTextOption grt;
_onexit(myexit);
GrSetMode( GR_default_graphics );
grt.txo_font = &GrDefaultFont;
grt.txo_fgcolor.v = GrWhite();
grt.txo_bgcolor.v = GrBlack();
grt.txo_direct = GR_TEXT_RIGHT;
grt.txo_xalign = GR_ALIGN_CENTER;
grt.txo_yalign = GR_ALIGN_CENTER;
grt.txo_chrtype = GR_BYTE_TEXT;
GrBox( 0,0,GrMaxX(),GrMaxY(),GrWhite() );
GrBox( 4,4,GrMaxX()-4,GrMaxY()-4,GrWhite() );
x = GrMaxX()/2;
y = GrMaxY()/2;
GrDrawString( message,strlen( message ),x,y,&grt );
// while(1) { cout << "forever\n"; cout.flush(); Sleep(1000); }
cout << "press key...\n"; cout.flush();
GrKeyRead();
cout << "done.\n"; cout.flush();
return 0;
}
--- end test.cc---
--- begin patch-grx-2.4.6-ExitProcess ---
diff -urN grx246/src/vdrivers/vd_win32.c grx246.fix/src/vdrivers/vd_win32.c
--- grx246/src/vdrivers/vd_win32.c 2003-04-14 21:49:54.000000000 +0200
+++ grx246.fix/src/vdrivers/vd_win32.c 2005-02-11 15:15:58.000000000 +0100
@@ -520,7 +520,7 @@
return 0;
DestroyWindow(hWnd);
if (!isMainWaitingTermination)
- ExitProcess(1);
+ TerminateProcess(GetCurrentProcess(), 0);
break;
case WM_DESTROY:
--- end patch-grx-2.4.6-ExitProcess ---