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 .
21 #error Need C++ to compile
28 #pragma warning(push, 1)
46 # define GetArgv( pArgc ) CommandLineToArgvW( GetCommandLine(), pArgc )
47 # define PROCESS_CREATIONFLAGS CREATE_UNICODE_ENVIRONMENT
49 # define GetArgv( pArgc ) (*pArgc = __argc, __argv)
50 # define PROCESS_CREATIONFLAGS 0
54 #define BIN_EXT_STR TEXT(".bin")
55 #define PARAM_LIBPATH_STR TEXT("-libpath=")
56 #define PARAM_LOCAL_STR TEXT("-local")
57 #define PARAM_REMOTE_STR TEXT("-remote")
60 #define DEFAULT_LIBPATH TEXT("remote;")
61 #elif defined( LOCAL )
62 #define DEFAULT_LIBPATH TEXT("local;")
67 // Retrieve startup info
69 STARTUPINFO aStartupInfo
;
71 ZeroMemory( &aStartupInfo
, sizeof(aStartupInfo
) );
72 aStartupInfo
.cb
= sizeof( aStartupInfo
);
73 GetStartupInfo( &aStartupInfo
);
75 // Retrieve command line
77 LPTSTR lpCommandLine
= GetCommandLine();
79 LPTSTR
*ppArguments
= NULL
;
82 ppArguments
= GetArgv( &nArguments
);
84 // Calculate application name
87 TCHAR szApplicationName
[MAX_PATH
];
88 TCHAR szDrive
[MAX_PATH
];
89 TCHAR szDir
[MAX_PATH
];
90 TCHAR szFileName
[MAX_PATH
];
91 TCHAR szExt
[MAX_PATH
];
93 GetModuleFileName( NULL
, szApplicationName
, MAX_PATH
);
94 _tsplitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
95 _tmakepath( szApplicationName
, szDrive
, szDir
, szFileName
, BIN_EXT_STR
);
97 // Retrieve actual environment
100 TCHAR szPathValue
[1024] = TEXT("");
102 #ifdef DEFAULT_LIBPATH
103 _tmakepath( szPathValue
, szDrive
, szDir
, DEFAULT_LIBPATH
, TEXT("") );
106 for ( int argn
= 1; argn
< nArguments
; argn
++ )
108 if ( 0 == _tcscmp( ppArguments
[argn
], PARAM_REMOTE_STR
) )
110 _tmakepath( szPathValue
, szDrive
, szDir
, TEXT("remote;"), TEXT("") );
113 else if ( 0 == _tcscmp( ppArguments
[argn
], PARAM_LOCAL_STR
) )
115 _tmakepath( szPathValue
, szDrive
, szDir
, TEXT("local;"), TEXT("") );
118 else if ( 0 == _tcsncmp( ppArguments
[argn
], PARAM_LIBPATH_STR
, _tcslen(PARAM_LIBPATH_STR
) ) )
120 LPTSTR pFileSpec
= NULL
;
122 GetFullPathName( ppArguments
[argn
] + _tcslen(PARAM_LIBPATH_STR
), sizeof(szPathValue
) / sizeof(TCHAR
), szPathValue
, &pFileSpec
);
123 _tcscat( szPathValue
, TEXT(";") );
128 GetEnvironmentVariable( TEXT("PATH"), szBuffer
, sizeof(szBuffer
) );
129 _tcscat( szPathValue
, szBuffer
);
130 SetEnvironmentVariable( TEXT("PATH"), szPathValue
);
132 LPVOID lpEnvironment
= GetEnvironmentStrings();
135 // Retrieve current directory
137 TCHAR szCurrentDirectory
[MAX_PATH
];
138 GetCurrentDirectory( MAX_PATH
, szCurrentDirectory
);
142 DWORD dwCreationFlags
= PROCESS_CREATIONFLAGS
;
144 PROCESS_INFORMATION aProcessInfo
;
146 BOOL fSuccess
= CreateProcess(
162 WaitForSingleObject( aProcessInfo
.hProcess
, INFINITE
);
163 fSuccess
= GetExitCodeProcess( aProcessInfo
.hProcess
, &dwExitCode
);
168 DWORD dwError
= GetLastError();
173 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
174 FORMAT_MESSAGE_FROM_SYSTEM
,
177 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
183 // Display the string.
184 MessageBox( NULL
, (LPCTSTR
)lpMsgBuf
, NULL
, MB_OK
| MB_ICONERROR
);
187 LocalFree( lpMsgBuf
);
189 return GetLastError();
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */