Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / osl / w32 / salinit.cxx
blob3eb9290a87fd62dcc06006d7b5a7c048ba9d86ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "sal/config.h"
22 #include <iostream>
23 #include <stdlib.h>
25 #include "system.h"
26 #include <osl/process.h>
27 #include <sal/main.h>
28 #include <sal/types.h>
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 //From time.c
35 void sal_initGlobalTimer();
37 // _set_invalid_parameter_handler appears unavailable with MinGW:
38 #if defined _MSC_VER
39 namespace {
41 extern "C" void invalidParameterHandler(
42 wchar_t const * expression, wchar_t const * function, wchar_t const * file,
43 unsigned int line, SAL_UNUSED_PARAMETER uintptr_t)
45 std::wcerr
46 << L"Invalid parameter in \"" << (expression ? expression : L"???")
47 << L"\" (" << (function ? function : L"???") << ") at "
48 << (file ? file : L"???") << L':' << line << std::endl;
52 #endif
54 // Prototypes for initialization and deinitialization of SAL library
56 void sal_detail_initialize(int argc, char ** argv)
58 sal_initGlobalTimer();
59 // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
60 // SetDllDirectoryW(L"");
61 // SetSearchPathMode(
62 // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
63 HMODULE h = GetModuleHandleW(L"kernel32.dll");
64 if (h != 0) {
65 FARPROC p;
66 #ifndef _WIN64
67 p = GetProcAddress(h, "SetProcessDEPPolicy");
68 if (p != 0) {
69 reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
71 #endif
72 p = GetProcAddress(h, "SetDllDirectoryW");
73 if (p != 0) {
74 reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
76 p = GetProcAddress(h, "SetSearchPathMode");
77 if (p != 0) {
78 reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
82 WSADATA wsaData;
83 int error;
84 WORD wVersionRequested;
86 wVersionRequested = MAKEWORD(1, 1);
88 error = WSAStartup(wVersionRequested, &wsaData);
89 if ( 0 == error )
91 WORD wMajorVersionRequired = 1;
92 WORD wMinorVersionRequired = 1;
94 if ((LOBYTE(wsaData.wVersion) < wMajorVersionRequired) ||
95 ((LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
96 ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired))))
98 // How to handle a very unlikely error ???
101 else
103 // How to handle a very unlikely error ???
106 #if defined _MSC_VER // appears unavailable with MinGW
107 // It appears that at least some jvm.dll versions can cause calls to
108 // _fileno(NULL), which leads to a call of the invalid parameter handler,
109 // and the default handler causes the application to crash, so install a
110 // "harmless" one (cf. fdo#38913):
111 _set_invalid_parameter_handler(&invalidParameterHandler);
112 #endif
114 osl_setCommandArgs(argc, argv);
117 void sal_detail_deinitialize()
119 if ( SOCKET_ERROR == WSACleanup() )
121 // We should never reach this point or we did wrong elsewhere
127 #ifdef __cplusplus
128 } // extern "C"
129 #endif
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */