Kaydet (Commit) 48305927 authored tarafından Mike Kaganski's avatar Mike Kaganski

applauncher: don't use 8-bit string functions

Change-Id: I44e9641fb800a7a0203b689b035adbe27c4efee1
Reviewed-on: https://gerrit.libreoffice.org/42301Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 6997c4fe
...@@ -19,50 +19,42 @@ ...@@ -19,50 +19,42 @@
#include "launcher.hxx" #include "launcher.hxx"
#include <shellapi.h>
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h> #include <malloc.h>
extern "C" int APIENTRY _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) extern "C" int APIENTRY wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
{ {
// Retrieve startup info // Retrieve startup info
STARTUPINFO aStartupInfo; STARTUPINFOW aStartupInfo;
ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) ); ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) );
aStartupInfo.cb = sizeof( aStartupInfo ); aStartupInfo.cb = sizeof( aStartupInfo );
GetStartupInfo( &aStartupInfo ); GetStartupInfoW( &aStartupInfo );
// Retrieve command line // Retrieve command line
LPTSTR lpCommandLine = GetCommandLine(); LPWSTR lpCommandLine = static_cast<LPWSTR>(_alloca( sizeof(WCHAR) * (wcslen(GetCommandLineW()) + wcslen(APPLICATION_SWITCH) + 2) ));
{
lpCommandLine = static_cast<LPTSTR>(_alloca( sizeof(_TCHAR) * (_tcslen(lpCommandLine) + _tcslen(APPLICATION_SWITCH) + 2) ));
_tcscpy( lpCommandLine, GetCommandLine() );
_tcscat( lpCommandLine, _T(" ") );
_tcscat( lpCommandLine, APPLICATION_SWITCH );
}
wcscpy( lpCommandLine, GetCommandLineW() );
wcscat( lpCommandLine, L" " );
wcscat( lpCommandLine, APPLICATION_SWITCH );
// Calculate application name // Calculate application name
TCHAR szApplicationName[MAX_PATH]; WCHAR szApplicationName[MAX_PATH];
TCHAR szDrive[MAX_PATH]; WCHAR szDrive[MAX_PATH];
TCHAR szDir[MAX_PATH]; WCHAR szDir[MAX_PATH];
TCHAR szFileName[MAX_PATH]; WCHAR szFileName[MAX_PATH];
TCHAR szExt[MAX_PATH]; WCHAR szExt[MAX_PATH];
GetModuleFileName( nullptr, szApplicationName, MAX_PATH );
_tsplitpath( szApplicationName, szDrive, szDir, szFileName, szExt );
_tmakepath( szApplicationName, szDrive, szDir, _T("soffice"), _T(".exe") );
GetModuleFileNameW( nullptr, szApplicationName, MAX_PATH );
_wsplitpath( szApplicationName, szDrive, szDir, szFileName, szExt );
_wmakepath( szApplicationName, szDrive, szDir, L"soffice", L".exe" );
PROCESS_INFORMATION aProcessInfo; PROCESS_INFORMATION aProcessInfo;
BOOL fSuccess = CreateProcess( BOOL fSuccess = CreateProcessW(
szApplicationName, szApplicationName,
lpCommandLine, lpCommandLine,
nullptr, nullptr,
...@@ -87,28 +79,28 @@ extern "C" int APIENTRY _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -87,28 +79,28 @@ extern "C" int APIENTRY _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
return 0; return 0;
} }
DWORD dwError = GetLastError(); DWORD dwError = GetLastError();
LPVOID lpMsgBuf; LPWSTR lpMsgBuf;
FormatMessage( FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, nullptr,
dwError, dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
reinterpret_cast<LPTSTR>(&lpMsgBuf), reinterpret_cast<LPWSTR>(&lpMsgBuf),
0, 0,
nullptr nullptr
); );
// Display the string. // Display the string.
MessageBox( nullptr, static_cast<LPCTSTR>(lpMsgBuf), nullptr, MB_OK | MB_ICONERROR ); MessageBoxW( nullptr, lpMsgBuf, nullptr, MB_OK | MB_ICONERROR );
// Free the buffer. // Free the buffer.
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return GetLastError(); return dwError;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -20,23 +20,7 @@ ...@@ -20,23 +20,7 @@
#pragma once #pragma once
#include <windows.h> #include <windows.h>
#include <winbase.h>
#include <windef.h>
#include <shlwapi.h>
#ifndef _INC_TCHAR extern WCHAR APPLICATION_SWITCH[];
# ifdef UNICODE
# define _UNICODE
# endif
# include <tchar.h>
#endif
#ifdef UNICODE
# define GetArgv( pArgc ) CommandLineToArgvW( GetCommandLine(), pArgc )
#else
# define GetArgv( pArgc ) (*pArgc = __argc, __argv)
#endif
extern _TCHAR APPLICATION_SWITCH[];
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--base" ); WCHAR APPLICATION_SWITCH[] = L"--base";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--calc" ); WCHAR APPLICATION_SWITCH[] = L"--calc";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--draw" ); WCHAR APPLICATION_SWITCH[] = L"--draw";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--impress" ); WCHAR APPLICATION_SWITCH[] = L"--impress";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--math" ); WCHAR APPLICATION_SWITCH[] = L"--math";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--web" ); WCHAR APPLICATION_SWITCH[] = L"--web";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
#include "launcher.hxx" #include "launcher.hxx"
_TCHAR APPLICATION_SWITCH[] = _T( "--writer" ); WCHAR APPLICATION_SWITCH[] = L"--writer";
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment