int WINAPI _tWinMain (HINSTANCE hThisInstance, UNUSED HINSTANCE hPrevInstance, UNUSED LPTSTR lpszArgument, UNUSED int nCmdShow) { MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ DWORD shell32_version; /* Initialize handlers for manangement interface notifications */ mgmt_rtmsg_handler handler[] = { { ready, OnReady }, { hold, OnHold }, { log, OnLogLine }, { state, OnStateChange }, { password, OnPassword }, { proxy, OnProxy }, { stop, OnStop }, { 0, NULL } }; InitManagement(handler); /* initialize options to default state */ InitOptions(&o); #ifdef DEBUG /* Open debug file for output */ if (!(o.debug_fp = fopen(DEBUG_FILE, "w"))) { /* can't open debug file */ ShowLocalizedMsg(IDS_ERR_OPEN_DEBUG_FILE, DEBUG_FILE); exit(1); } PrintDebug(_T("Starting OpenVPN GUI v%S"), PACKAGE_VERSION); #endif o.hInstance = hThisInstance; if(!GetModuleHandle(_T("RICHED20.DLL"))) { LoadLibrary(_T("RICHED20.DLL")); } else { /* can't load riched20.dll */ ShowLocalizedMsg(IDS_ERR_LOAD_RICHED20); exit(1); } /* Check version of shell32.dll */ shell32_version=GetDllVersion(_T("shell32.dll")); if (shell32_version < PACKVERSION(5,0)) { /* shell32.dll version to low */ ShowLocalizedMsg(IDS_ERR_SHELL_DLL_VERSION, shell32_version); exit(1); } #ifdef DEBUG PrintDebug(_T("Shell32.dll version: 0x%lx"), shell32_version); #endif /* Parse command-line options */ ProcessCommandLine(&o, GetCommandLine()); /* Check if a previous instance is already running. */ if ((FindWindow (szClassName, NULL)) != NULL) { /* GUI already running */ ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING); exit(1); } if (!GetRegistryKeys()) { exit(1); } if (!CheckVersion()) { exit(1); } if (!EnsureDirExists(o.log_dir)) { ShowLocalizedMsg(IDS_ERR_CREATE_PATH, _T("log_dir"), o.log_dir); exit(1); } BuildFileList(); if (!VerifyAutoConnections()) { exit(1); } GetProxyRegistrySettings(); #ifndef DISABLE_CHANGE_PASSWORD /* Initialize OpenSSL */ OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); #endif /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadLocalizedIcon(ID_ICO_APP); wincl.hIconSm = LoadLocalizedIcon(ID_ICO_APP); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_3DSHADOW; //COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 1; /* The class is registered, let's create the program*/ CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ szTitleText, /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ (int)CW_USEDEFAULT, /* Windows decides the position */ (int)CW_USEDEFAULT, /* where the window ends up on the screen */ 230, /* The programs width */ 200, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }
int WINAPI WinMain (HINSTANCE hThisInstance, UNUSED HINSTANCE hPrevInstance, LPSTR lpszArgument, UNUSED int nCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ HWND hwndAbout; DWORD shell32_version; /* initialize options to default state */ init_options (&o); #ifdef DEBUG /* Open debug file for output */ if (!(o.debug_fp = fopen(DEBUG_FILE, "w"))) { /* can't open debug file */ ShowLocalizedMsg(GUI_NAME, ERR_OPEN_DEBUG_FILE, DEBUG_FILE); exit(1); } PrintDebug("Starting OpenVPN GUI v%s", GUI_VERSION); #endif o.hInstance = hThisInstance; if(!GetModuleHandle("RICHED20.DLL")) { LoadLibrary("RICHED20.DLL"); } else { /* can't load riched20.dll */ ShowLocalizedMsg(GUI_NAME, ERR_LOAD_RICHED20, ""); exit(1); } /* Check version of shell32.dll */ shell32_version=GetDllVersion("shell32.dll"); if (shell32_version < PACKVERSION(5,0)) { /* shell32.dll version to low */ ShowLocalizedMsg(GUI_NAME, ERR_SHELL_DLL_VERSION, shell32_version); exit(1); } #ifdef DEBUG PrintDebug("Shell32.dll version: 0x%lx", shell32_version); #endif /* Parse command-line options */ Createargcargv(&o, lpszArgument); /* Check if a previous instance is already running. */ if ((FindWindow (szClassName, NULL)) != NULL) { /* GUI already running */ ShowLocalizedMsg(GUI_NAME, ERR_GUI_ALREADY_RUNNING, ""); exit(1); } if (!GetRegistryKeys()) { exit(1); } #ifdef DEBUG PrintDebug("exe_path: %s", o.exe_path); PrintDebug("config_dir: %s", o.config_dir); PrintDebug("log_dir: %s", o.log_dir); PrintDebug("priority_string: %s", o.priority_string); PrintDebug("append_string: %s", o.append_string); PrintDebug("log_viewer: %s", o.log_viewer); PrintDebug("editor: %s", o.editor); PrintDebug("allow_edit: %s", o.allow_edit); PrintDebug("allow_service: %s", o.allow_service); PrintDebug("allow_password: %s", o.allow_password); PrintDebug("allow_proxy: %s", o.allow_proxy); PrintDebug("silent_connection: %s", o.silent_connection); PrintDebug("service_only: %s", o.service_only); PrintDebug("show_balloon: %s", o.show_balloon); PrintDebug("show_script_window: %s", o.show_script_window); PrintDebug("psw_attempts_string: %s", o.psw_attempts_string); PrintDebug("disconnect_on_suspend: %s", o.disconnect_on_suspend); PrintDebug("connectscript_timeout_string: %s", o.connectscript_timeout_string); PrintDebug("disconnectscript_timeout_string: %s", o.disconnectscript_timeout_string); PrintDebug("preconnectscript_timeout_string: %s", o.preconnectscript_timeout_string); #endif if (!CheckVersion()) { exit(1); } if (!BuildFileList()) { exit(1); } if (!VerifyAutoConnections()) { exit(1); } GetProxyRegistrySettings(); #ifndef DISABLE_CHANGE_PASSWORD /* Initialize OpenSSL */ OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); #endif /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (hThisInstance, MAKEINTRESOURCE(APP_ICON)); wincl.hIconSm = LoadIcon (hThisInstance, MAKEINTRESOURCE(APP_ICON)); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_3DSHADOW; //COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 1; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ szTitleText, /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ (int)CW_USEDEFAULT, /* Windows decides the position */ (int)CW_USEDEFAULT, /* where the window ends up on the screen */ 230, /* The programs width */ 200, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }