12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
102722ceddSAndrew Rist  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
192722ceddSAndrew Rist  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "launcher.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef _WINDOWS_
31cdf0e10cSrcweir #	define WIN32_LEAN_AND_MEAN
32cdf0e10cSrcweir #if defined _MSC_VER
33cdf0e10cSrcweir #pragma warning(push, 1)
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #	include <windows.h>
36cdf0e10cSrcweir #	include <shellapi.h>
37cdf0e10cSrcweir #if defined _MSC_VER
38cdf0e10cSrcweir #pragma warning(pop)
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <stdlib.h>
44cdf0e10cSrcweir #include <malloc.h>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #ifdef __MINGW32__
WinMain(HINSTANCE,HINSTANCE,LPSTR,int)48cdf0e10cSrcweir extern "C" int APIENTRY WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
49cdf0e10cSrcweir #else
50cdf0e10cSrcweir extern "C" int APIENTRY _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir {
53*07a3d7f1SPedro Giffuni 	// Retrieve startup info
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	STARTUPINFO	aStartupInfo;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) );
58cdf0e10cSrcweir 	aStartupInfo.cb = sizeof( aStartupInfo );
59cdf0e10cSrcweir 	GetStartupInfo( &aStartupInfo );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	// Retrieve command line
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	LPTSTR	lpCommandLine = GetCommandLine();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	LPTSTR	*ppArguments = NULL;
66cdf0e10cSrcweir 	int		nArguments = 0;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	ppArguments = GetArgv( &nArguments );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     // if ( 1 == nArguments )
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		lpCommandLine = (LPTSTR)_alloca( sizeof(_TCHAR) * (_tcslen(lpCommandLine) + _tcslen(APPLICATION_SWITCH) + 2) );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		_tcscpy( lpCommandLine, GetCommandLine() );
75cdf0e10cSrcweir 		_tcscat( lpCommandLine, _T(" ") );
76cdf0e10cSrcweir 		_tcscat( lpCommandLine, APPLICATION_SWITCH );
77cdf0e10cSrcweir 	}
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	// Calculate application name
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	TCHAR	szApplicationName[MAX_PATH];
83cdf0e10cSrcweir 	TCHAR	szDrive[MAX_PATH];
84cdf0e10cSrcweir 	TCHAR	szDir[MAX_PATH];
85cdf0e10cSrcweir 	TCHAR	szFileName[MAX_PATH];
86cdf0e10cSrcweir 	TCHAR	szExt[MAX_PATH];
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	GetModuleFileName( NULL, szApplicationName, MAX_PATH );
89cdf0e10cSrcweir 	_tsplitpath( szApplicationName, szDrive, szDir, szFileName, szExt );
90cdf0e10cSrcweir 	_tmakepath( szApplicationName, szDrive, szDir, OFFICE_IMAGE_NAME, _T(".exe") );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	PROCESS_INFORMATION	aProcessInfo;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	BOOL	fSuccess = CreateProcess(
95cdf0e10cSrcweir 		szApplicationName,
96cdf0e10cSrcweir 		lpCommandLine,
97cdf0e10cSrcweir 		NULL,
98cdf0e10cSrcweir 		NULL,
99cdf0e10cSrcweir 		TRUE,
100cdf0e10cSrcweir 		0,
101cdf0e10cSrcweir 		NULL,
102cdf0e10cSrcweir 		NULL,
103cdf0e10cSrcweir 		&aStartupInfo,
104cdf0e10cSrcweir 		&aProcessInfo );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	if ( fSuccess )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		// Wait for soffice process to be terminated to allow other applications
109cdf0e10cSrcweir 		// to wait for termination of started process
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		WaitForSingleObject( aProcessInfo.hProcess, INFINITE );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		CloseHandle( aProcessInfo.hProcess );
114cdf0e10cSrcweir 		CloseHandle( aProcessInfo.hThread );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		return 0;
117cdf0e10cSrcweir 	}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	DWORD	dwError = GetLastError();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	LPVOID lpMsgBuf;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	FormatMessage(
124cdf0e10cSrcweir 		FORMAT_MESSAGE_ALLOCATE_BUFFER |
125cdf0e10cSrcweir 		FORMAT_MESSAGE_FROM_SYSTEM,
126cdf0e10cSrcweir 		NULL,
127cdf0e10cSrcweir 		dwError,
128cdf0e10cSrcweir 		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
129cdf0e10cSrcweir 		(LPTSTR)&lpMsgBuf,
130cdf0e10cSrcweir 		0,
131cdf0e10cSrcweir 		NULL
132cdf0e10cSrcweir 	);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	// Display the string.
135cdf0e10cSrcweir 	MessageBox( NULL, (LPCTSTR)lpMsgBuf, NULL, MB_OK | MB_ICONERROR );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	// Free the buffer.
138cdf0e10cSrcweir 	LocalFree( lpMsgBuf );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	return GetLastError();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143