int WINAPI WinMain(HINSTANCE this_instance, HINSTANCE prev_instance, #ifdef _WIN32_WCE LPWSTR lpCmdLine, #else LPSTR lpCmdLine, #endif int nCmdShow) { TCHAR stunnel_exe_path[MAX_PATH]; LPTSTR c; #ifndef _WIN32_WCE LPTSTR errmsg; #endif (void)prev_instance; /* squash the unused parameter warning */ (void)lpCmdLine; /* squash the unused parameter warning */ (void)nCmdShow; /* squash the unused parameter warning */ tls_init(); /* initialize thread-local storage */ ghInst=this_instance; gui_cmdline(); /* setup global cmdline structure */ GetModuleFileName(0, stunnel_exe_path, MAX_PATH); #ifndef _WIN32_WCE /* find previous instances of the same executable */ if(!cmdline.service && !cmdline.install && !cmdline.uninstall && !cmdline.reload && !cmdline.reopen && !cmdline.start && !cmdline.stop) { EnumWindows(enum_windows, (LPARAM)stunnel_exe_path); if(cmdline.exit) return 1; /* in case EnumWindows didn't find a previous instance */ } #endif /* set current working directory and engine path */ c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash */ if(c) { /* found */ *c=TEXT('\0'); /* truncate the program name */ c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* previous backslash */ if(c && !_tcscmp(c+1, TEXT("bin"))) *c=TEXT('\0'); /* truncate "bin" */ } #ifndef _WIN32_WCE if(!SetCurrentDirectory(stunnel_exe_path)) { errmsg=str_tprintf(TEXT("Cannot set directory to %s"), stunnel_exe_path); message_box(errmsg, MB_ICONERROR); str_free(errmsg); return 1; } /* try to enter the "config" subdirectory, ignore the result */ SetCurrentDirectory(TEXT("config")); #endif _tputenv(str_tprintf(TEXT("OPENSSL_ENGINES=%s\\engines"), stunnel_exe_path)); if(initialize_winsock()) return 1; #ifndef _WIN32_WCE if(cmdline.service) /* "-service" must be processed before "-install" */ return service_initialize(); if(cmdline.install) return service_install(); if(cmdline.uninstall) return service_uninstall(); if(cmdline.start) return service_start(); if(cmdline.stop) return service_stop(); if(cmdline.reload) return service_user(SIGNAL_RELOAD_CONFIG); if(cmdline.reopen) return service_user(SIGNAL_REOPEN_LOG); #endif return gui_loop(); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, #ifdef _WIN32_WCE LPWSTR lpCmdLine, #else LPSTR lpCmdLine, #endif int nCmdShow) { LPSTR command_line; #ifdef _WIN32_WCE command_line=tstr2str(lpCmdLine); #else command_line=lpCmdLine; #endif ghInst=hInstance; parse_cmdline(command_line); /* setup global cmdline structure */ #ifndef _WIN32_WCE if(set_cwd()) /* set current working directory */ return 1; #endif /* setup the windo caption before reading the configuration file * options.win32_service is not available here and may not be used */ #ifdef _WIN32_WCE _tcscpy(win32_name, TEXT("stunnel ") TEXT(VERSION) TEXT(" on Windows CE (not configured)")); #else _tcscpy(win32_name, TEXT("stunnel ") TEXT(VERSION) TEXT(" on Win32 (not configured)")); #endif if(initialize_winsock()) return 1; if(!setjmp(jump_buf)) { /* TRY */ main_initialize( cmdline.config_file[0] ? cmdline.config_file : NULL, NULL); #ifdef _WIN32_WCE _tcscpy(win32_name, TEXT("stunnel ") TEXT(VERSION) TEXT(" on Windows CE")); #else _snprintf(win32_name, STRLEN, "stunnel %s on Win32 (%s)", VERSION, options.win32_service); /* update the information */ if(!cmdline.service) { if(cmdline.install) return service_install(command_line); if(cmdline.uninstall) return service_uninstall(); if(cmdline.start) return service_start(); if(cmdline.stop) return service_stop(); } #endif } /* CATCH */ #ifndef _WIN32_WCE if(cmdline.service) return service_initialize(); else #endif return win_main(hInstance, hPrevInstance, command_line, nCmdShow); }
int WINAPI WinMain(HINSTANCE this_instance, HINSTANCE prev_instance, #ifdef _WIN32_WCE LPWSTR lpCmdLine, #else LPSTR lpCmdLine, #endif int nCmdShow) { LPSTR command_line; char *c, stunnel_exe_path[MAX_PATH]; #ifndef _WIN32_WCE char *errmsg; #endif (void)prev_instance; /* skip warning about unused parameter */ (void)nCmdShow; /* skip warning about unused parameter */ str_init(); /* initialize per-thread string management */ ghInst=this_instance; #ifdef _WIN32_WCE command_line=tstr2str(lpCmdLine); #else command_line=lpCmdLine; #endif parse_cmdline(command_line); /* setup global cmdline structure */ GetModuleFileName(0, stunnel_exe_path, MAX_PATH); #ifndef _WIN32_WCE /* find previous instances of the same executable */ if(!cmdline.service && !cmdline.install && !cmdline.uninstall && !cmdline.start && !cmdline.stop) { EnumWindows(enum_windows, (LPARAM)stunnel_exe_path); if(cmdline.exit) return 0; /* in case EnumWindows didn't find a previous instance */ } #endif /* set current working directory and engine path */ c=strrchr(stunnel_exe_path, '\\'); /* last backslash */ if(c) /* found */ c[1]='\0'; /* truncate program name */ #ifndef _WIN32_WCE if(!SetCurrentDirectory(stunnel_exe_path)) { errmsg=str_printf("Cannot set directory to %s", stunnel_exe_path); message_box(errmsg, MB_ICONERROR); str_free(errmsg); return 1; } #endif _putenv_s("OPENSSL_ENGINES", stunnel_exe_path); if(initialize_winsock()) return 1; #ifndef _WIN32_WCE if(cmdline.service) /* "-service" must be processed before "-install" */ return service_initialize(); if(cmdline.install) return service_install(command_line); if(cmdline.uninstall) return service_uninstall(); if(cmdline.start) return service_start(); if(cmdline.stop) return service_stop(); #endif return gui_loop(); }