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