Bump version to 4.1-6
[LibreOffice.git] / sal / osl / w32 / salinit.cxx
blobe392f4ab3774ee61dd31713f997f3c3a993bcab8
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 // _set_invalid_parameter_handler appears unavailable with MinGW:
35 #if defined _MSC_VER
36 namespace {
38 extern "C" void invalidParameterHandler(
39 wchar_t const * expression, wchar_t const * function, wchar_t const * file,
40 unsigned int line, SAL_UNUSED_PARAMETER uintptr_t)
42 std::wcerr
43 << L"Invalid parameter in \"" << (expression ? expression : L"???")
44 << L"\" (" << (function ? function : L"???") << ") at "
45 << (file ? file : L"???") << L':' << line << std::endl;
49 #endif
51 // Prototypes for initialization and deinitialization of SAL library
53 void sal_detail_initialize(int argc, char ** argv)
55 // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
56 // SetDllDirectoryW(L"");
57 // SetSearchPathMode(
58 // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
59 HMODULE h = GetModuleHandleW(L"kernel32.dll");
60 if (h != 0) {
61 FARPROC p;
62 #ifndef _WIN64
63 p = GetProcAddress(h, "SetProcessDEPPolicy");
64 if (p != 0) {
65 reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
67 #endif
68 p = GetProcAddress(h, "SetDllDirectoryW");
69 if (p != 0) {
70 reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
72 p = GetProcAddress(h, "SetSearchPathMode");
73 if (p != 0) {
74 reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
78 WSADATA wsaData;
79 int error;
80 WORD wVersionRequested;
82 wVersionRequested = MAKEWORD(1, 1);
84 error = WSAStartup(wVersionRequested, &wsaData);
85 if ( 0 == error )
87 WORD wMajorVersionRequired = 1;
88 WORD wMinorVersionRequired = 1;
90 if ((LOBYTE(wsaData.wVersion) < wMajorVersionRequired) ||
91 ((LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
92 ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired))))
94 // How to handle a very unlikely error ???
97 else
99 // How to handle a very unlikely error ???
102 #if defined _MSC_VER // appears unavailable with MinGW
103 // It appears that at least some jvm.dll versions can cause calls to
104 // _fileno(NULL), which leads to a call of the invalid parameter handler,
105 // and the default handler causes the application to crash, so install a
106 // "harmless" one (cf. fdo#38913):
107 _set_invalid_parameter_handler(&invalidParameterHandler);
108 #endif
110 osl_setCommandArgs(argc, argv);
113 void sal_detail_deinitialize()
115 if ( SOCKET_ERROR == WSACleanup() )
117 // We should never reach this point or we did wrong elsewhere
123 #ifdef __cplusplus
124 } // extern "C"
125 #endif
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */