26#if !defined WIN32_LEAN_AND_MEAN
27# define WIN32_LEAN_AND_MEAN
34#define MY_SIZE(s) (sizeof (s) / sizeof *(s))
35#define MY_LENGTH(s) (MY_SIZE(s) - 1)
63int WINAPI
wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
64 LPWSTR lpCmdLine,
int nCmdShow )
80 wcscpy(cmd + 1, path);
81 if (wcschr(cmd + 1, L
'"') !=
NULL) {
83 writeError(
"Error: bad characters in UNO installation path!\n");
87 size_t pathsize = wcslen(cmd);
90 &L
"\\unoinfo.exe\" c++"[
91 pathsize == 1 || cmd[pathsize - 1] != L
'\\' ? 0 : 1]);
92 SECURITY_ATTRIBUTES sec;
93 sec.nLength =
sizeof (SECURITY_ATTRIBUTES);
94 sec.lpSecurityDescriptor =
NULL;
95 sec.bInheritHandle =
TRUE;
99 if (CreatePipe(&temp, &stdoutWrite, &sec, 0) == 0 ||
101 GetCurrentProcess(), temp, GetCurrentProcess(), &stdoutRead, 0,
102 FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS) == 0)
105 writeError(
"Error: CreatePipe/DuplicateHandle failed!\n");
109 STARTUPINFOW startinfo;
110 PROCESS_INFORMATION procinfo;
111 memset(&startinfo, 0,
sizeof(startinfo));
112 startinfo.cb =
sizeof(startinfo);
113 startinfo.lpDesktop = L
"";
114 startinfo.dwFlags = STARTF_USESTDHANDLES;
115 startinfo.hStdOutput = stdoutWrite;
116 BOOL ret = CreateProcessW(
127 CloseHandle(stdoutWrite);
128 CloseHandle(procinfo.hThread);
131 tmp = realloc(buf,
n);
135 "Error: out of memory reading unoinfo output!\n");
140 if (!ReadFile(stdoutRead, buf + k,
n - k, &
m,
NULL))
142 DWORD
err = GetLastError();
143 if (
err == ERROR_HANDLE_EOF ||
err == ERROR_BROKEN_PIPE) {
146 writeError(
"Error: cannot read unoinfo output!\n");
155 if (
n >= MAXDWORD / 2) {
157 "Error: out of memory reading unoinfo output!\n");
169 CloseHandle(stdoutRead);
170 if (!GetExitCodeProcess(procinfo.hProcess, &exitcode) ||
173 writeError(
"Error: executing unoinfo failed!\n");
177 path = (
wchar_t*)realloc(buf, k +
sizeof(
wchar_t));
182 "Error: out of memory zero-terminating unoinfo output!\n");
188 if (GetLastError() != ERROR_FILE_NOT_FOUND) {
190 writeError(
"Error: calling unoinfo failed!\n");
194 CloseHandle(stdoutRead);
195 CloseHandle(stdoutWrite);
199 const wchar_t* ENVVARNAME = L
"PATH";
201 wchar_t*
value = _wgetenv( ENVVARNAME );
208 size_t size = wcslen( ENVVARNAME ) + wcslen( L
"=" ) + wcslen( path ) + 1;
211 wchar_t* envstr = (
wchar_t*) malloc(
size*
sizeof(
wchar_t) );
213 wcscpy( envstr, ENVVARNAME );
214 wcscat( envstr, L
"=" );
215 wcscat( envstr, path );
219 wcscat( envstr,
value );
228 writeError(
"Warning: no UNO installation found!\n" );
233 if ( cmdline ==
NULL )
235 writeError(
"Error: cannot create command line!\n" );
241 STARTUPINFOW startup_info;
242 PROCESS_INFORMATION process_info;
243 memset( &startup_info, 0,
sizeof(startup_info) );
244 startup_info.cb =
sizeof(startup_info);
246 &startup_info, &process_info );
250 writeError(
"Error: cannot create process!\n" );
273 writeError(
"Warning: getting path from Windows Registry failed!\n" );
293 const wchar_t* CMDPREFIX = L
"_";
294 const wchar_t* DQUOTE = L
"\"";
295 const wchar_t*
SPACE = L
" ";
297 wchar_t* cmdline =
NULL;
300 wchar_t drive[ _MAX_DRIVE ];
302 wchar_t base[ _MAX_FNAME ];
303 wchar_t newbase[ _MAX_FNAME ];
304 wchar_t ext[ _MAX_EXT ];
307 if ( GetModuleFileNameW(
NULL, cmdname,
MY_SIZE( cmdname ) ) )
310 _wsplitpath( cmdname, drive, dir,
base, ext );
311 wcscpy( newbase, CMDPREFIX );
312 wcscat( newbase,
base );
313 _wmakepath( cmdname, drive, dir, newbase, ext );
316 cmdline = (
wchar_t*) malloc( (wcslen( DQUOTE ) + wcslen( cmdname ) +
317 wcslen ( DQUOTE ) + wcslen(
SPACE ) + wcslen( appendix ) + 1) *
sizeof(wchar_t) );
319 wcscpy( cmdline, DQUOTE );
320 wcscat( cmdline, cmdname );
321 wcscat( cmdline, DQUOTE );
322 wcscat( cmdline,
SPACE );
323 wcscat( cmdline, appendix );
346 const wchar_t* MODE = L
"w";
347 const wchar_t* BASEPOSTFIX = L
"-error";
353 wchar_t drive[ _MAX_DRIVE ];
355 wchar_t base[ _MAX_FNAME ];
356 wchar_t newbase[ _MAX_FNAME ];
357 wchar_t ext[ _MAX_EXT ];
362 if ( GetModuleFileNameW(
NULL, fname,
MY_SIZE( fname ) ) )
365 _wsplitpath( fname, drive, dir,
base, ext );
366 wcscpy( newbase,
base );
367 wcscat( newbase, BASEPOSTFIX );
368 _wmakepath( fname, drive, dir, newbase,
EXTENSION );
369 ferr = _wfopen( fname, MODE );
374 GetTempPathW(
MY_SIZE( fname ), fname );
375 wcscat( fname, newbase );
377 ferr = _wfopen( fname, MODE );
395 fputs( errstr, ferr );
char * cppuhelper_detail_findSofficePath(void)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
const wchar_t *typedef BOOL
static const char * PATHSEPARATOR
static void closeErrorFile(void)
static void writeError(const char *errstr)
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
static wchar_t * createCommandLine(wchar_t const *lpCmdLine)
static wchar_t * getPath(void)
static FILE * getErrorFile(int create)