From eef4c133e9649ebd690918bd7b83c2d5dc0dfcff Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 20 Sep 2017 20:20:44 +0300 Subject: Windows: avoid dependence on UNICODE define; prefer W functions Change-Id: I95b90128e93f0d88ed73601bcc5a7ca9279d4cf1 Reviewed-on: https://gerrit.libreoffice.org/42560 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- desktop/win32/source/QuickStart/QuickStart.cxx | 40 ++++++++++++++------------ desktop/win32/source/guistdio/guistdio.inc | 28 ++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) (limited to 'desktop/win32/source') diff --git a/desktop/win32/source/QuickStart/QuickStart.cxx b/desktop/win32/source/QuickStart/QuickStart.cxx index 2c426be6c2bb..0cc673c77191 100644 --- a/desktop/win32/source/QuickStart/QuickStart.cxx +++ b/desktop/win32/source/QuickStart/QuickStart.cxx @@ -39,35 +39,39 @@ #include #include #include -#include bool SofficeRuns() { // check for soffice by searching the communication window - return FindWindowEx( nullptr, nullptr, QUICKSTART_CLASSNAME, nullptr ) != nullptr; + return FindWindowExW( nullptr, nullptr, QUICKSTART_CLASSNAME, nullptr ) != nullptr; } bool launchSoffice( ) { if ( !SofficeRuns() ) { - char filename[_MAX_PATH + 1]; + wchar_t filename[_MAX_PATH + 1]; filename[_MAX_PATH] = 0; - GetModuleFileName( nullptr, filename, _MAX_PATH ); // soffice resides in the same dir - char *p = strrchr( filename, '\\' ); + GetModuleFileNameW( nullptr, filename, _MAX_PATH ); // soffice resides in the same dir + wchar_t *p = wcsrchr( filename, L'\\' ); if ( !p ) return false; - strncpy( p+1, "soffice.exe", _MAX_PATH - (p+1 - filename) ); + wcsncpy( p+1, L"soffice.exe", _MAX_PATH - (p+1 - filename) ); - char imagename[_MAX_PATH + 1]; + wchar_t imagename[_MAX_PATH + 1]; imagename[_MAX_PATH] = 0; - _snprintf(imagename, _MAX_PATH, "\"%s\" --quickstart", filename ); - - UINT ret = WinExec( imagename, SW_SHOW ); - if ( ret < 32 ) + _snwprintf(imagename, _MAX_PATH, L"\"%s\" --quickstart", filename ); + + STARTUPINFOW aStartupInfo; + ZeroMemory(&aStartupInfo, sizeof(aStartupInfo)); + aStartupInfo.cb = sizeof(aStartupInfo); + aStartupInfo.wShowWindow = SW_SHOW; + PROCESS_INFORMATION aProcessInfo; + BOOL bSuccess = CreateProcessW(filename, imagename, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &aStartupInfo, &aProcessInfo); + if ( !bSuccess ) return false; return true; @@ -76,10 +80,10 @@ bool launchSoffice( ) return true; } -int APIENTRY WinMain(HINSTANCE /*hInstance*/, - HINSTANCE /*hPrevInstance*/, - LPSTR /*lpCmdLine*/, - int /*nCmdShow*/) +int APIENTRY wWinMain(HINSTANCE /*hInstance*/, + HINSTANCE /*hPrevInstance*/, + LPWSTR /*lpCmdLine*/, + int /*nCmdShow*/) { // Look for --killtray argument @@ -87,12 +91,12 @@ int APIENTRY WinMain(HINSTANCE /*hInstance*/, { if ( 0 == strcmp( __argv[i], "--killtray" ) ) { - HWND hwndTray = FindWindow( QUICKSTART_CLASSNAME, nullptr ); + HWND hwndTray = FindWindowW( QUICKSTART_CLASSNAME, nullptr ); if ( hwndTray ) { - UINT uMsgKillTray = RegisterWindowMessage( SHUTDOWN_QUICKSTART_MESSAGE ); - SendMessage( hwndTray, uMsgKillTray, 0, 0 ); + UINT uMsgKillTray = RegisterWindowMessageW( SHUTDOWN_QUICKSTART_MESSAGE ); + SendMessageW( hwndTray, uMsgKillTray, 0, 0 ); } return 0; diff --git a/desktop/win32/source/guistdio/guistdio.inc b/desktop/win32/source/guistdio/guistdio.inc index 5617d889a402..5d6634bb9c5c 100644 --- a/desktop/win32/source/guistdio/guistdio.inc +++ b/desktop/win32/source/guistdio/guistdio.inc @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#define UNICODE #define WIN32_LEAN_AND_MEAN #ifdef _MSC_VER #pragma warning(push,1) // disable warnings within system headers @@ -27,9 +26,6 @@ #pragma warning(pop) #endif -#define _UNICODE -#include - #include #include #include @@ -250,7 +246,7 @@ DWORD WINAPI WaitForUIThread( LPVOID pParam ) #ifndef UNOPKG HANDLE hProcess = (HANDLE)pParam; - if ( !_tgetenv( TEXT("UNOPKG") ) ) + if ( !wgetenv( L"UNOPKG" ) ) WaitForInputIdle( hProcess, INFINITE ); #else (void) pParam; @@ -274,10 +270,10 @@ BOOL WINAPI CtrlBreakHandler( return TRUE; } -int _tmain( int, _TCHAR ** ) +int wmain( int, wchar_t** ) { - TCHAR szTargetFileName[MAX_PATH] = TEXT(""); - STARTUPINFO aStartupInfo; + WCHAR szTargetFileName[MAX_PATH] = L""; + STARTUPINFOW aStartupInfo; PROCESS_INFORMATION aProcessInfo; ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) ); @@ -331,23 +327,23 @@ int _tmain( int, _TCHAR ** ) // Get image path with same name but with .exe extension - TCHAR szModuleFileName[MAX_PATH]; + WCHAR szModuleFileName[MAX_PATH]; - GetModuleFileName( nullptr, szModuleFileName, MAX_PATH ); - _TCHAR *lpLastDot = _tcsrchr( szModuleFileName, '.' ); - if ( lpLastDot && 0 == _tcsicmp( lpLastDot, _T(".COM") ) ) + GetModuleFileNameW( nullptr, szModuleFileName, MAX_PATH ); + WCHAR *lpLastDot = wcsrchr( szModuleFileName, '.' ); + if ( lpLastDot && 0 == wcsicmp( lpLastDot, L".COM" ) ) { size_t len = lpLastDot - szModuleFileName; - _tcsncpy( szTargetFileName, szModuleFileName, len ); - _tcsncpy( szTargetFileName + len, _T(".EXE"), SAL_N_ELEMENTS(szTargetFileName) - len ); + wcsncpy( szTargetFileName, szModuleFileName, len ); + wcsncpy( szTargetFileName + len, L".EXE", SAL_N_ELEMENTS(szTargetFileName) - len ); } // Create process with same command line, environment and stdio handles which // are directed to the created pipes - BOOL fSuccess = CreateProcess( + BOOL fSuccess = CreateProcessW( szTargetFileName, - GetCommandLine(), + GetCommandLineW(), nullptr, nullptr, TRUE, -- cgit