diff options
author | William A. Rowe Jr <wrowe@apache.org> | 2008-03-03 00:57:11 +0100 |
---|---|---|
committer | William A. Rowe Jr <wrowe@apache.org> | 2008-03-03 00:57:11 +0100 |
commit | 22b889ef926707f2f2ec99e65f4c859d6d648835 (patch) | |
tree | 8795029cdad64b64af8e3ca629cd4b0c404e0876 /support/win32/ApacheMonitor.c | |
parent | * If the cached entity contained Cache-Control: no-cache, treat it as stale (diff) | |
download | apache2-22b889ef926707f2f2ec99e65f4c859d6d648835.tar.xz apache2-22b889ef926707f2f2ec99e65f4c859d6d648835.zip |
A large refactoring, but no behavior change;
replace all relevant ascii strxxx fn's with _tcsxxx macros and encode relevant text
with the _T() macro wrapper, permitting /D UNICODE builds in place of /D _MCBS
builds in use today. This allows for internationalized unicode service names and
textual modification. Since this is win32 only, using APR style utf-8-ization is silly.
Because today this module simply isn't loadable on Win95-ME, nobody has actually
complained, and we really have no desire to support such a dangerous OS in the
wild of the internet, the unicode build should become the default.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@632885 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support/win32/ApacheMonitor.c')
-rw-r--r-- | support/win32/ApacheMonitor.c | 301 |
1 files changed, 169 insertions, 132 deletions
diff --git a/support/win32/ApacheMonitor.c b/support/win32/ApacheMonitor.c index e39f9b8d98..4f4d3d9784 100644 --- a/support/win32/ApacheMonitor.c +++ b/support/win32/ApacheMonitor.c @@ -44,6 +44,7 @@ #include <stdlib.h> #include <stdio.h> #include <WtsApi32.h> +#include <tchar.h> #include "ApacheMonitor.h" #ifndef AM_STRINGIFY @@ -75,24 +76,24 @@ typedef struct _st_APACHE_SERVICE { - LPSTR szServiceName; - LPSTR szDisplayName; - LPSTR szDescription; - LPSTR szImagePath; - LPSTR szComputerName; + LPTSTR szServiceName; + LPTSTR szDisplayName; + LPTSTR szDescription; + LPTSTR szImagePath; + LPTSTR szComputerName; DWORD dwPid; } ST_APACHE_SERVICE; typedef struct _st_MONITORED_COMPUTERS { - LPSTR szComputerName; + LPTSTR szComputerName; HKEY hRegistry; } ST_MONITORED_COMP; /* Global variables */ HINSTANCE g_hInstance = NULL; -CHAR *g_szTitle; /* The title bar text */ -CHAR *g_szWindowClass; /* Window Class Name */ +TCHAR *g_szTitle; /* The title bar text */ +TCHAR *g_szWindowClass; /* Window Class Name */ HICON g_icoStop; HICON g_icoRun; UINT g_bUiTaskbarCreated; @@ -120,10 +121,10 @@ HANDLE g_hpipeStdError; LANGID g_LangID; PROCESS_INFORMATION g_lpRedirectProc; CRITICAL_SECTION g_stcSection; -LPSTR g_szLocalHost; +LPTSTR g_szLocalHost; /* locale language support */ -static CHAR *g_lpMsg[IDS_MSG_LAST - IDS_MSG_FIRST + 1]; +static TCHAR *g_lpMsg[IDS_MSG_LAST - IDS_MSG_FIRST + 1]; void am_ClearServicesSt() @@ -167,11 +168,11 @@ void am_ClearComputersSt() } -BOOL am_IsComputerConnected(LPSTR szComputerName) +BOOL am_IsComputerConnected(LPTSTR szComputerName) { int i = 0; while (g_stComputers[i].szComputerName != NULL) { - if (strcmp(g_stComputers[i].szComputerName, szComputerName) == 0) { + if (_tcscmp(g_stComputers[i].szComputerName, szComputerName) == 0) { return TRUE; } ++i; @@ -180,11 +181,11 @@ BOOL am_IsComputerConnected(LPSTR szComputerName) } -void am_DisconnectComputer(LPSTR szComputerName) +void am_DisconnectComputer(LPTSTR szComputerName) { int i = 0, j; while (g_stComputers[i].szComputerName != NULL) { - if (strcmp(g_stComputers[i].szComputerName, szComputerName) == 0) { + if (_tcscmp(g_stComputers[i].szComputerName, szComputerName) == 0) { break; } ++i; @@ -202,7 +203,7 @@ void am_DisconnectComputer(LPSTR szComputerName) } -void ErrorMessage(LPCSTR szError, BOOL bFatal) +void ErrorMessage(LPCTSTR szError, BOOL bFatal) { LPVOID lpMsgBuf = NULL; if (szError) { @@ -214,8 +215,8 @@ void ErrorMessage(LPCSTR szError, BOOL bFatal) FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), g_LangID, - (LPSTR) &lpMsgBuf, 0, NULL); - MessageBox(NULL, (LPCSTR)lpMsgBuf, + (LPTSTR) &lpMsgBuf, 0, NULL); + MessageBox(NULL, (LPCTSTR)lpMsgBuf, g_lpMsg[IDS_MSG_ERROR - IDS_MSG_FIRST], MB_OK | (bFatal ? MB_ICONERROR : MB_ICONEXCLAMATION)); LocalFree(lpMsgBuf); @@ -226,14 +227,14 @@ void ErrorMessage(LPCSTR szError, BOOL bFatal) } -BOOL am_ConnectComputer(LPSTR szComputerName) +BOOL am_ConnectComputer(LPTSTR szComputerName) { int i = 0; HKEY hKeyRemote; - char szTmp[MAX_PATH]; + TCHAR szTmp[MAX_PATH]; while (g_stComputers[i].szComputerName != NULL) { - if (strcmp(g_stComputers[i].szComputerName, szComputerName) == 0) { + if (_tcscmp(g_stComputers[i].szComputerName, szComputerName) == 0) { return FALSE; } ++i; @@ -243,22 +244,23 @@ BOOL am_ConnectComputer(LPSTR szComputerName) } if (RegConnectRegistry(szComputerName, HKEY_LOCAL_MACHINE, &hKeyRemote) != ERROR_SUCCESS) { - sprintf(szTmp, g_lpMsg[IDS_MSG_ECONNECT - IDS_MSG_FIRST], - szComputerName); + _sntprintf(szTmp, sizeof(szTmp) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_ECONNECT - IDS_MSG_FIRST], + szComputerName); ErrorMessage(szTmp, FALSE); return FALSE; } else { - g_stComputers[i].szComputerName = strdup(szComputerName); + g_stComputers[i].szComputerName = _tcsdup(szComputerName); g_stComputers[i].hRegistry = hKeyRemote; return TRUE; } } -LPSTR GetStringRes(int id) +LPTSTR GetStringRes(int id) { - static CHAR buffer[MAX_PATH]; + static TCHAR buffer[MAX_PATH]; buffer[0] = 0; LoadString(GetModuleHandle(NULL), id, buffer, MAX_PATH); @@ -334,22 +336,24 @@ static VOID ShowNotifyIcon(HWND hWnd, DWORD dwMessage) nid.hIcon = NULL; } if (n == i && n > 0) { - lstrcpy(nid.szTip, g_lpMsg[IDS_MSG_RUNNINGALL - IDS_MSG_FIRST]); + _tcscpy(nid.szTip, g_lpMsg[IDS_MSG_RUNNINGALL - IDS_MSG_FIRST]); } else if (n) { - sprintf(nid.szTip, g_lpMsg[IDS_MSG_RUNNING - IDS_MSG_FIRST], n, i); + _sntprintf(nid.szTip, sizeof(nid.szTip) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_RUNNING - IDS_MSG_FIRST], n, i); } else if (i) { - sprintf(nid.szTip, g_lpMsg[IDS_MSG_RUNNINGNONE - IDS_MSG_FIRST], i); + _sntprintf(nid.szTip, sizeof(nid.szTip) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_RUNNINGNONE - IDS_MSG_FIRST], i); } else { - lstrcpy(nid.szTip, g_lpMsg[IDS_MSG_NOSERVICES - IDS_MSG_FIRST]); + _tcscpy(nid.szTip, g_lpMsg[IDS_MSG_NOSERVICES - IDS_MSG_FIRST]); } Shell_NotifyIcon(dwMessage, &nid); } -void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, +void appendMenuItem(HMENU hMenu, UINT uMenuId, LPTSTR szName, BOOL fDefault, BOOL fEnabled) { MENUITEMINFO mii; @@ -357,7 +361,7 @@ void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, memset(&mii, 0, sizeof(MENUITEMINFO)); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE; - if (lstrlen(szName)) + if (_tcslen(szName)) { mii.fType = MFT_STRING; mii.wID = uMenuId; @@ -377,7 +381,7 @@ void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, void appendServiceMenu(HMENU hMenu, UINT uMenuId, - LPSTR szServiceName, BOOL fRunning) + LPTSTR szServiceName, BOOL fRunning) { MENUITEMINFO mii; HMENU smh; @@ -422,7 +426,7 @@ void ShowTryPopupMenu(HWND hWnd) g_lpMsg[IDS_MSG_MNUSERVICES - IDS_MSG_FIRST], FALSE, TRUE); } - appendMenuItem(hMenu, 0, "", FALSE, TRUE); + appendMenuItem(hMenu, 0, _T(""), FALSE, TRUE); appendMenuItem(hMenu, IDM_EXIT, g_lpMsg[IDS_MSG_MNUEXIT - IDS_MSG_FIRST], FALSE, TRUE); @@ -496,7 +500,7 @@ BOOL CenterWindow(HWND hwndChild) } -static void addListBoxItem(HWND hDlg, LPSTR lpStr, HBITMAP hBmp) +static void addListBoxItem(HWND hDlg, LPTSTR lpStr, HBITMAP hBmp) { LRESULT nItem; @@ -505,7 +509,7 @@ static void addListBoxItem(HWND hDlg, LPSTR lpStr, HBITMAP hBmp) } -static void addListBoxString(HWND hListBox, LPSTR lpStr) +static void addListBoxString(HWND hListBox, LPTSTR lpStr) { static int nItems = 0; if (!g_bDlgServiceOn) { @@ -523,6 +527,32 @@ static void addListBoxString(HWND hListBox, LPSTR lpStr) } +#ifndef UNICODE +#define addListBoxStringA addListBoxString +#else +static void addListBoxStringA(HWND hListBox, LPSTR lpStr) +{ + static int nItems = 0; + TCHAR WStr[16384]; + + if (!g_bDlgServiceOn) { + return; + } + if (!MultiByteToWideChar(CP_ACP, 0, lpStr, (int)strlen(lpStr) + 1, + WStr, (int) (sizeof(WStr) / sizeof(TCHAR)))) + return; + ++nItems; + if (nItems > MAX_LOADSTRING) + { + SendMessage(hListBox, LB_RESETCONTENT, 0, 0); + nItems = 1; + } + ListBox_SetCurSel(hListBox, + ListBox_AddString(hListBox, WStr)); +} +#endif + + static DWORD WINAPI ConsoleOutputThread(LPVOID lpThreadParameter) { static BYTE lpBuffer[MAX_PATH+1]; @@ -537,7 +567,7 @@ static DWORD WINAPI ConsoleOutputThread(LPVOID lpThreadParameter) if (ch == '\n' || nPtr >= MAX_PATH) { lpBuffer[nPtr] = '\0'; - addListBoxString(g_hwndStdoutList, lpBuffer); + addListBoxStringA(g_hwndStdoutList, lpBuffer); nPtr = 0; } else if (ch == '\t' && nPtr < (MAX_PATH - 4)) @@ -570,7 +600,7 @@ DWORD WINAPI ConsoleWaitingThread(LPVOID lpThreadParameter) } -BOOL RunRedirectedConsole(LPSTR szCmdLine) +BOOL RunRedirectedConsole(LPTSTR szCmdLine) { DWORD dwThreadId; HANDLE hProc; @@ -637,7 +667,7 @@ BOOL RunRedirectedConsole(LPSTR szCmdLine) } -BOOL RunAndForgetConsole(LPSTR szCmdLine, BOOL bRedirectConsole) +BOOL RunAndForgetConsole(LPTSTR szCmdLine, BOOL bRedirectConsole) { STARTUPINFO stInfo; PROCESS_INFORMATION prInfo; @@ -676,12 +706,12 @@ BOOL RunAndForgetConsole(LPSTR szCmdLine, BOOL bRedirectConsole) } -BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, - LPSTR szComputerName, DWORD dwCommand) +BOOL ApacheManageService(LPCTSTR szServiceName, LPCTSTR szImagePath, + LPTSTR szComputerName, DWORD dwCommand) { - CHAR szBuf[MAX_PATH]; - CHAR szMsg[MAX_PATH]; - LPSTR sPos; + TCHAR szBuf[MAX_PATH]; + TCHAR szMsg[MAX_PATH]; + LPTSTR sPos; BOOL retValue; BOOL serviceFlag = TRUE; SC_HANDLE schService; @@ -691,32 +721,33 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, if (g_dwOSVersion == OS_VERSION_WIN9X) { - sPos = strstr(szImagePath, "-k start"); + sPos = _tcsstr(szImagePath, _T("-k start")); if (sPos) { - lstrcpyn(szBuf, szImagePath, (int)(sPos - szImagePath)); + _tcsncpy(szBuf, szImagePath, (int)(sPos - szImagePath)); switch (dwCommand) { case SERVICE_CONTROL_STOP: - lstrcat(szBuf, " -k shutdown -n "); + _tcscat(szBuf, _T(" -k shutdown -n ")); break; case SERVICE_CONTROL_CONTINUE: - sprintf(szMsg, g_lpMsg[IDS_MSG_SRVSTART - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVSTART - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); - lstrcat(szBuf, " -k start -n "); + _tcscat(szBuf, _T(" -k start -n ")); serviceFlag = FALSE; break; case SERVICE_APACHE_RESTART: - lstrcat(szBuf, " -k restart -n "); + _tcscat(szBuf, _T(" -k restart -n ")); break; default: return FALSE; } - lstrcat(szBuf, szServiceName); + _tcscat(szBuf, szServiceName); } else { return FALSE; @@ -732,8 +763,9 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, } else if (!serviceFlag) { - sprintf(szMsg, g_lpMsg[IDS_MSG_SRVSTARTED - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVSTARTED - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); g_bConsoleRun = FALSE; SetCursor(g_hCursorArrow); @@ -759,8 +791,9 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, switch (dwCommand) { case SERVICE_CONTROL_STOP: - sprintf(szMsg, g_lpMsg[IDS_MSG_SRVSTOP - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVSTOP - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); if (ControlService(schService, SERVICE_CONTROL_STOP, &schSStatus)) { @@ -781,17 +814,18 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, if (schSStatus.dwCurrentState == SERVICE_STOPPED) { retValue = TRUE; - sprintf(szMsg, - g_lpMsg[IDS_MSG_SRVSTOPPED - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVSTOPPED - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); } } break; case SERVICE_CONTROL_CONTINUE: - sprintf(szMsg, g_lpMsg[IDS_MSG_SRVSTART - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVSTART - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); if (StartService(schService, 0, NULL)) @@ -813,17 +847,18 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, if (schSStatus.dwCurrentState == SERVICE_RUNNING) { retValue = TRUE; - sprintf(szMsg, - g_lpMsg[IDS_MSG_SRVSTARTED - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVSTARTED - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); } } break; case SERVICE_APACHE_RESTART: - sprintf(szMsg, g_lpMsg[IDS_MSG_SRVRESTART - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVRESTART - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); if (ControlService(schService, SERVICE_APACHE_RESTART, &schSStatus)) @@ -848,9 +883,9 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, if (schSStatus.dwCurrentState == SERVICE_RUNNING) { retValue = TRUE; - sprintf(szMsg, - g_lpMsg[IDS_MSG_SRVRESTARTED - IDS_MSG_FIRST], - szServiceName); + _sntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), + g_lpMsg[IDS_MSG_SRVRESTARTED - IDS_MSG_FIRST], + szServiceName); addListBoxString(g_hwndStdoutList, szMsg); } break; @@ -876,7 +911,7 @@ BOOL ApacheManageService(LPCSTR szServiceName, LPCSTR szImagePath, } -BOOL IsServiceRunning(LPCSTR szServiceName, LPCSTR szComputerName, +BOOL IsServiceRunning(LPCTSTR szServiceName, LPCTSTR szComputerName, LPDWORD lpdwPid) { DWORD dwPid; @@ -887,7 +922,7 @@ BOOL IsServiceRunning(LPCSTR szServiceName, LPCSTR szComputerName, if (g_dwOSVersion == OS_VERSION_WIN9X) { - hWnd = FindWindow("ApacheWin95ServiceMonitor", szServiceName); + hWnd = FindWindow(_T("ApacheWin95ServiceMonitor"), szServiceName); if (hWnd && GetWindowThreadProcessId(hWnd, &dwPid)) { *lpdwPid = 1; @@ -956,11 +991,11 @@ BOOL FindRunningServices(void) BOOL GetApacheServicesStatus() { - CHAR szKey[MAX_PATH]; - CHAR achKey[MAX_PATH]; - CHAR szImagePath[MAX_PATH]; - CHAR szBuf[MAX_PATH]; - CHAR szTmp[MAX_PATH]; + TCHAR szKey[MAX_PATH]; + TCHAR achKey[MAX_PATH]; + TCHAR szImagePath[MAX_PATH]; + TCHAR szBuf[MAX_PATH]; + TCHAR szTmp[MAX_PATH]; HKEY hKey, hSubKey, hKeyRemote; DWORD retCode, rv, dwKeyType; DWORD dwBufLen = MAX_PATH; @@ -973,7 +1008,7 @@ BOOL GetApacheServicesStatus() while (g_stComputers[computers].szComputerName != NULL) { hKeyRemote = g_stComputers[computers].hRegistry; retCode = RegOpenKeyEx(hKeyRemote, - "System\\CurrentControlSet\\Services\\", + _T("System\\CurrentControlSet\\Services\\"), 0, KEY_READ, &hKey); if (retCode != ERROR_SUCCESS) { @@ -985,60 +1020,57 @@ BOOL GetApacheServicesStatus() retCode = RegEnumKey(hKey, i, achKey, MAX_PATH); if (retCode == ERROR_SUCCESS) { - lstrcpy(szKey, "System\\CurrentControlSet\\Services\\"); - lstrcat(szKey, achKey); + _tcscpy(szKey, _T("System\\CurrentControlSet\\Services\\")); + _tcscat(szKey, achKey); if (RegOpenKeyEx(hKeyRemote, szKey, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) { dwBufLen = MAX_PATH; - rv = RegQueryValueEx(hSubKey, "ImagePath", NULL, - &dwKeyType, szImagePath, &dwBufLen); + rv = RegQueryValueEx(hSubKey, _T("ImagePath"), NULL, + &dwKeyType, (LPBYTE)szImagePath, &dwBufLen); if (rv == ERROR_SUCCESS && (dwKeyType == REG_SZ || dwKeyType == REG_EXPAND_SZ) && dwBufLen) { - lstrcpy(szBuf, szImagePath); + _tcscpy(szBuf, szImagePath); CharLower(szBuf); /* the service name could be httpd*.exe or Apache*.exe */ - if (((strstr(szBuf, "\\apache") != NULL) - || (strstr(szBuf, "\\httpd") != NULL)) - && strstr(szBuf, ".exe") - && (strstr(szBuf, "--ntservice") != NULL - || strstr(szBuf, "-k ") != NULL)) + if (((_tcsstr(szBuf, _T("\\apache")) != NULL) + || (_tcsstr(szBuf, _T("\\httpd")) != NULL)) + && _tcsstr(szBuf, _T(".exe")) + && (_tcsstr(szBuf, _T("--ntservice")) != NULL + || _tcsstr(szBuf, _T("-k ")) != NULL)) { - g_stServices[stPos].szServiceName = strdup(achKey); - g_stServices[stPos].szImagePath = - strdup(szImagePath); + g_stServices[stPos].szServiceName = _tcsdup(achKey); + g_stServices[stPos].szImagePath = _tcsdup(szImagePath); g_stServices[stPos].szComputerName = - strdup(g_stComputers[computers].szComputerName); + _tcsdup(g_stComputers[computers].szComputerName); dwBufLen = MAX_PATH; - if (RegQueryValueEx(hSubKey, "Description", NULL, - &dwKeyType, szBuf, &dwBufLen) + if (RegQueryValueEx(hSubKey, _T("Description"), NULL, + &dwKeyType, (LPBYTE)szBuf, &dwBufLen) == ERROR_SUCCESS) { - g_stServices[stPos].szDescription = - strdup(szBuf); + g_stServices[stPos].szDescription = _tcsdup(szBuf); } dwBufLen = MAX_PATH; - if (RegQueryValueEx(hSubKey, "DisplayName", NULL, - &dwKeyType, szBuf, &dwBufLen) + if (RegQueryValueEx(hSubKey, _T("DisplayName"), NULL, + &dwKeyType, (LPBYTE)szBuf, &dwBufLen) == ERROR_SUCCESS) { - if (strcmp(g_stComputers[computers] + if (_tcscmp(g_stComputers[computers] .szComputerName, g_szLocalHost) != 0) { - strcpy(szTmp, g_stComputers[computers] + _tcscpy(szTmp, g_stComputers[computers] .szComputerName + 2); - strcat(szTmp, "@"); - strcat(szTmp, szBuf); + _tcscat(szTmp, _T("@")); + _tcscat(szTmp, szBuf); } else { - strcpy(szTmp, szBuf); + _tcscpy(szTmp, szBuf); } - g_stServices[stPos].szDisplayName - = strdup(szTmp); + g_stServices[stPos].szDisplayName = _tcsdup(szTmp); } ++stPos; @@ -1062,7 +1094,7 @@ BOOL GetApacheServicesStatus() LRESULT CALLBACK ConnectDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - CHAR szCmp[MAX_COMPUTERNAME_LENGTH+4]; + TCHAR szCmp[MAX_COMPUTERNAME_LENGTH+4]; switch (message) { case WM_INITDIALOG: @@ -1077,14 +1109,14 @@ LRESULT CALLBACK ConnectDlgProc(HWND hDlg, UINT message, switch (LOWORD(wParam)) { case IDOK: - memset(szCmp, 0, MAX_COMPUTERNAME_LENGTH+4); - strcpy(szCmp, "\\\\"); + memset(szCmp, 0, sizeof(szCmp)); + _tcscpy(szCmp, _T("\\\\")); SendMessage(GetDlgItem(hDlg, IDC_COMPUTER), WM_GETTEXT, (WPARAM) MAX_COMPUTERNAME_LENGTH, (LPARAM) szCmp+2); - strupr(szCmp); - if (strlen(szCmp) < 3) { + _tcsupr(szCmp); + if (_tcslen(szCmp) < 3) { EndDialog(hDlg, TRUE); return TRUE; } @@ -1103,7 +1135,7 @@ LRESULT CALLBACK ConnectDlgProc(HWND hDlg, UINT message, memset(&bi, 0, sizeof(BROWSEINFO)); SHGetSpecialFolderLocation(hDlg, CSIDL_NETWORK, &il); - bi.lpszTitle = "ApacheMonitor :\nSelect Network Computer!"; + bi.lpszTitle = _T("ApacheMonitor :\nSelect Network Computer!"); bi.pszDisplayName = szCmp; bi.hwndOwner = hDlg; bi.ulFlags = BIF_BROWSEFORCOMPUTER; @@ -1142,7 +1174,7 @@ LRESULT CALLBACK ConnectDlgProc(HWND hDlg, UINT message, LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - CHAR szBuf[MAX_PATH]; + TCHAR szBuf[MAX_PATH]; HWND hListBox; static HWND hStatusBar; TEXTMETRIC tm; @@ -1153,7 +1185,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, LPMEASUREITEMSTRUCT lpmis; LPDRAWITEMSTRUCT lpdis; - memset(szBuf, 0, MAX_PATH); + memset(szBuf, 0, sizeof(szBuf)); switch (message) { case WM_INITDIALOG: @@ -1186,7 +1218,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, g_hwndStdoutList = GetDlgItem(hDlg, IDL_STDOUT); hStatusBar = CreateStatusWindow(0x0800 /* SBT_TOOLTIPS */ | WS_CHILD | WS_VISIBLE, - "", hDlg, IDC_STATBAR); + _T(""), hDlg, IDC_STATBAR); if (GetApacheServicesStatus()) { i = 0; @@ -1217,7 +1249,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, case WM_UPDATEMESSAGE: hListBox = GetDlgItem(hDlg, IDL_SERVICES); SendMessage(hListBox, LB_RESETCONTENT, 0, 0); - SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)""); + SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)_T("")); Button_Enable(GetDlgItem(hDlg, IDC_SSTART), FALSE); Button_Enable(GetDlgItem(hDlg, IDC_SSTOP), FALSE); Button_Enable(GetDlgItem(hDlg, IDC_SRESTART), FALSE); @@ -1306,7 +1338,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, Button_Enable(GetDlgItem(hDlg, IDC_SSTOP), FALSE); Button_Enable(GetDlgItem(hDlg, IDC_SRESTART), FALSE); } - if (strcmp(g_stServices[lpdis->itemID].szComputerName, + if (_tcscmp(g_stServices[lpdis->itemID].szComputerName, g_szLocalHost) == 0) { Button_Enable(GetDlgItem(hDlg, IDC_SDISCONN), FALSE); } @@ -1319,7 +1351,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, (LPARAM)g_stServices[lpdis->itemID].szDescription); } else { - SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)""); + SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)_T("")); } SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT)); @@ -1331,7 +1363,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, SetBkColor(lpdis->hDC, GetSysColor(COLOR_WINDOW)); FillRect(lpdis->hDC, &rcBitmap, (HBRUSH)(COLOR_WINDOW+1)); } - TextOut(lpdis->hDC, XBITMAP + 6, y, szBuf, (int)strlen(szBuf)); + TextOut(lpdis->hDC, XBITMAP + 6, y, szBuf, (int)_tcslen(szBuf)); break; case ODA_FOCUS: @@ -1406,7 +1438,7 @@ LRESULT CALLBACK ServiceDlgProc(HWND hDlg, UINT message, case IDC_SMANAGER: if (g_dwOSVersion >= OS_VERSION_WIN2K) { - ShellExecute(hDlg, "open", "services.msc", "/s", + ShellExecute(NULL, _T("open"), _T("services.msc"), _T("/s"), NULL, SW_NORMAL); } else { @@ -1619,7 +1651,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, case IDC_SMANAGER: if (g_dwOSVersion >= OS_VERSION_WIN2K) { - ShellExecute(NULL, "open", "services.msc", "/s", + ShellExecute(NULL, _T("open"), _T("services.msc"), _T("/s"), NULL, SW_NORMAL); } else { @@ -1705,7 +1737,7 @@ static int KillAllMonitors(void) * the user hovers over it or when the taskbar area is updated. */ for (i = 0; i < tsProcCount; ++i) { - if (strcmp(tsProcs[i].pProcessName, AM_STRINGIFY(BIN_NAME)) == 0 + if (_tcscmp(tsProcs[i].pProcessName, _T(AM_STRINGIFY(BIN_NAME))) == 0 && tsProcs[i].ProcessId != thisProcId) WTSTerminateProcess(WTS_CURRENT_SERVER_HANDLE, tsProcs[i].ProcessId, 1); @@ -1745,12 +1777,16 @@ HWND CreateMainWindow(HINSTANCE hInstance) return hWnd; } - +#ifdef UNICODE +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPWSTR lpCmdLine, int nCmdShow) +#else int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +#endif { - CHAR szTmp[MAX_LOADSTRING]; - CHAR szCmp[MAX_COMPUTERNAME_LENGTH+4]; + TCHAR szTmp[MAX_LOADSTRING]; + TCHAR szCmp[MAX_COMPUTERNAME_LENGTH+4]; MSG msg; /* single instance mutex */ HANDLE hMutex; @@ -1769,28 +1805,28 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } for (i = IDS_MSG_FIRST; i <= IDS_MSG_LAST; ++i) { LoadString(hInstance, i, szTmp, MAX_LOADSTRING); - g_lpMsg[i - IDS_MSG_FIRST] = strdup(szTmp); + g_lpMsg[i - IDS_MSG_FIRST] = _tcsdup(szTmp); } LoadString(hInstance, IDS_APMONITORTITLE, szTmp, MAX_LOADSTRING); d = MAX_COMPUTERNAME_LENGTH+1; - strcpy(szCmp, "\\\\"); + _tcscpy(szCmp, _T("\\\\")); GetComputerName(szCmp + 2, &d); - strupr(szCmp); - g_szLocalHost = strdup(szCmp); + _tcsupr(szCmp); + g_szLocalHost = _tcsdup(szCmp); memset(g_stComputers, 0, sizeof(ST_MONITORED_COMP) * MAX_APACHE_COMPUTERS); - g_stComputers[0].szComputerName = strdup(szCmp); + g_stComputers[0].szComputerName = _tcsdup(szCmp); g_stComputers[0].hRegistry = HKEY_LOCAL_MACHINE; - g_szTitle = strdup(szTmp); + g_szTitle = _tcsdup(szTmp); LoadString(hInstance, IDS_APMONITORCLASS, szTmp, MAX_LOADSTRING); - g_szWindowClass = strdup(szTmp); + g_szWindowClass = _tcsdup(szTmp); - if (strstr(lpCmdLine, "--kill") != NULL) { + if (_tcsstr(lpCmdLine, _T("--kill")) != NULL) { /* Off to chase and close up every ApacheMonitor taskbar window */ return KillAllMonitors(); } - hMutex = CreateMutex(NULL, FALSE, "APSRVMON_MUTEX"); + hMutex = CreateMutex(NULL, FALSE, _T("APSRVMON_MUTEX")); if ((hMutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) { ErrorMessage(g_lpMsg[IDS_MSG_APPRUNNING - IDS_MSG_FIRST], FALSE); @@ -1822,7 +1858,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, InitCommonControls(); g_hInstance = hInstance; g_hwndMain = CreateMainWindow(hInstance); - g_bUiTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); + g_bUiTaskbarCreated = RegisterWindowMessage(_T("TaskbarCreated")); InitializeCriticalSection(&g_stcSection); g_hwndServiceDlg = NULL; if (g_hwndMain != NULL) @@ -1846,3 +1882,4 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, CoUninitialize(); return 0; } + |