1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: genericloader.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
36 #define WIN32_LEAN_AND_MEAN
38 #pragma warning(push, 1)
51 #include <systools/win32/uwinapi.h>
53 #include "tools/pathutils.hxx"
54 #include "../extendloaderenvironment.hxx"
56 //---------------------------------------------------------------------------
58 static int GenericMain()
60 TCHAR szTargetFileName
[MAX_PATH
];
61 TCHAR szIniDirectory
[MAX_PATH
];
62 STARTUPINFO aStartupInfo
;
64 desktop_win32::extendLoaderEnvironment(szTargetFileName
, szIniDirectory
);
66 ZeroMemory( &aStartupInfo
, sizeof(aStartupInfo
) );
67 aStartupInfo
.cb
= sizeof(aStartupInfo
);
69 GetStartupInfo( &aStartupInfo
);
71 DWORD dwExitCode
= (DWORD
)-1;
73 PROCESS_INFORMATION aProcessInfo
;
75 size_t iniDirLen
= wcslen(szIniDirectory
);
77 DWORD cwdLen
= GetCurrentDirectoryW(MAX_PATH
, cwd
);
78 if (cwdLen
>= MAX_PATH
) {
81 WCHAR redirect
[MAX_PATH
];
85 redirect
, szIniDirectory
, szIniDirectory
+ iniDirLen
,
86 MY_STRING(L
"redirect.ini")) != NULL
&&
87 (GetBinaryType(redirect
, &dummy
) || // cheaper check for file existence?
88 GetLastError() != ERROR_FILE_NOT_FOUND
);
89 LPTSTR cl1
= GetCommandLine();
90 WCHAR
* cl2
= new WCHAR
[
93 ? (MY_LENGTH(L
" \"-env:INIFILENAME=vnd.sun.star.pathname:") +
94 iniDirLen
+ MY_LENGTH(L
"redirect.ini\""))
96 MY_LENGTH(L
" \"-env:OOO_CWD=2") + 4 * cwdLen
+ MY_LENGTH(L
"\"") + 1];
97 // 4 * cwdLen: each char preceded by backslash, each trailing backslash
99 WCHAR
* p
= desktop_win32::commandLineAppend(cl2
, cl1
);
101 p
= desktop_win32::commandLineAppend(
102 p
, MY_STRING(L
" \"-env:INIFILENAME=vnd.sun.star.pathname:"));
103 p
= desktop_win32::commandLineAppend(p
, szIniDirectory
);
104 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
"redirect.ini\""));
106 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
" \"-env:OOO_CWD="));
108 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
"0"));
110 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
"2"));
111 p
= desktop_win32::commandLineAppendEncoded(p
, cwd
);
113 desktop_win32::commandLineAppend(p
, MY_STRING(L
"\""));
115 BOOL fSuccess
= CreateProcess(
135 // On Windows XP it seems as the desktop calls WaitForInputIdle after "OpenWidth" so we have to do so
136 // as if we where processing any messages
138 dwWaitResult
= MsgWaitForMultipleObjects( 1, &aProcessInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
);
140 if ( WAIT_OBJECT_0
+ 1 == dwWaitResult
)
144 PeekMessage( &msg
, NULL
, 0, 0, PM_REMOVE
);
146 } while ( WAIT_OBJECT_0
+ 1 == dwWaitResult
);
149 GetExitCodeProcess( aProcessInfo
.hProcess
, &dwExitCode
);
151 CloseHandle( aProcessInfo
.hProcess
);
152 CloseHandle( aProcessInfo
.hThread
);
158 //---------------------------------------------------------------------------
161 int WINAPI
WinMain( HINSTANCE
, HINSTANCE
, LPSTR
, int )
163 int WINAPI
_tWinMain( HINSTANCE
, HINSTANCE
, LPTSTR
, int )
166 return GenericMain();
169 //---------------------------------------------------------------------------
177 return GenericMain();