1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "launcher.hxx"
25 extern "C" int APIENTRY
wWinMain( HINSTANCE
, HINSTANCE
, LPWSTR
, int )
27 // Retrieve startup info
29 STARTUPINFOW aStartupInfo
;
31 ZeroMemory( &aStartupInfo
, sizeof(aStartupInfo
) );
32 aStartupInfo
.cb
= sizeof( aStartupInfo
);
33 GetStartupInfoW( &aStartupInfo
);
35 // Retrieve command line
37 LPWSTR lpCommandLine
= static_cast<LPWSTR
>(_alloca( sizeof(WCHAR
) * (wcslen(GetCommandLineW()) + wcslen(APPLICATION_SWITCH
) + 2) ));
39 wcscpy( lpCommandLine
, GetCommandLineW() );
40 wcscat( lpCommandLine
, L
" " );
41 wcscat( lpCommandLine
, APPLICATION_SWITCH
);
43 // Calculate application name
45 WCHAR szApplicationName
[MAX_PATH
];
46 WCHAR szDrive
[MAX_PATH
];
47 WCHAR szDir
[MAX_PATH
];
48 WCHAR szFileName
[MAX_PATH
];
49 WCHAR szExt
[MAX_PATH
];
51 GetModuleFileNameW( nullptr, szApplicationName
, MAX_PATH
);
52 _wsplitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
53 _wmakepath( szApplicationName
, szDrive
, szDir
, L
"soffice", L
".exe" );
55 PROCESS_INFORMATION aProcessInfo
;
57 bool fSuccess
= CreateProcessW(
71 // Wait for soffice process to be terminated to allow other applications
72 // to wait for termination of started process
74 WaitForSingleObject( aProcessInfo
.hProcess
, INFINITE
);
76 CloseHandle( aProcessInfo
.hProcess
);
77 CloseHandle( aProcessInfo
.hThread
);
82 DWORD dwError
= GetLastError();
84 LPWSTR lpMsgBuf
= nullptr;
87 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
90 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
91 reinterpret_cast<LPWSTR
>(&lpMsgBuf
),
96 // Display the string.
97 MessageBoxW( nullptr, lpMsgBuf
, nullptr, MB_OK
| MB_ICONERROR
);
100 HeapFree( GetProcessHeap(), 0, lpMsgBuf
);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */