2626// ---------------------------------------------------------------------
2727PyStand::~PyStand ()
2828{
29+ FreeLibrary (_hDLL);
2930}
3031
3132
@@ -308,13 +309,15 @@ const char *init_script =
308309" ctypes.windll.user32.MessageBoxW(None, str(msg), str(info), 0)\n "
309310" return 0\n "
310311" os.MessageBox = MessageBox\n "
312+ #ifndef PYSTAND_CONSOLE
311313" try:\n "
312314" fd = os.open('CONOUT$', os.O_RDWR | os.O_BINARY)\n "
313315" fp = os.fdopen(fd, 'w')\n "
314316" sys.stdout = fp\n "
315317" sys.stderr = fp\n "
316318" except Exception as e:\n "
317319" pass\n "
320+ #endif
318321" for n in ['lib', 'site-packages']:\n "
319322" test = os.path.join(PYSTAND_HOME, n)\n "
320323" if os.path.exists(test): sys.path.append(test)\n "
@@ -332,17 +335,22 @@ const char *init_script =
332335// main
333336// ---------------------------------------------------------------------
334337
338+ #ifdef PYSTAND_CONSOLE
339+ int main ()
340+ #else
335341// ! flag: -static
336342// ! src:
337343// ! mode: win
338344// ! int: objs
339345int WINAPI
340346WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
347+ #endif
341348{
342349 PyStand ps (" runtime" );
343350 if (ps.DetectScript () != 0 ) {
344351 return 3 ;
345352 }
353+ #ifndef PYSTAND_CONSOLE
346354 if (AttachConsole (ATTACH_PARENT_PROCESS)) {
347355 freopen (" CONOUT$" , " w" , stdout);
348356 freopen (" CONOUT$" , " w" , stderr);
@@ -357,6 +365,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
357365 SetEnvironmentVariableA (" PYSTAND_STDIN" , fn.c_str ());
358366 }
359367 }
368+ #endif
360369 int hr = ps.RunString (init_script);
361370 // printf("finalize\n");
362371 return hr;
0 commit comments