Bump for 3.6-28
[LibreOffice.git] / sal / osl / w32 / salinit.cxx
blobaaa5a5b321c35c09aa5b6d667995cdcc4885281c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
31 #include <iostream>
32 #include <stdlib.h>
34 #include "system.h"
35 #include <osl/process.h>
36 #include <sal/types.h>
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 // _set_invalid_parameter_handler appears unavailable with MinGW:
43 #if defined _MSC_VER
44 namespace {
46 extern "C" void invalidParameterHandler(
47 wchar_t const * expression, wchar_t const * function, wchar_t const * file,
48 unsigned int line, SAL_UNUSED_PARAMETER uintptr_t)
50 std::wcerr
51 << L"Invalid parameter in \"" << (expression ? expression : L"???")
52 << L"\" (" << (function ? function : L"???") << ") at "
53 << (file ? file : L"???") << L':' << line << std::endl;
57 #endif
59 // Prototypes for initialization and deinitialization of SAL library
61 SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv)
63 // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
64 // SetDllDirectoryW(L"");
65 // SetSearchPathMode(
66 // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
67 HMODULE h = GetModuleHandleW(L"kernel32.dll");
68 if (h != 0) {
69 FARPROC p;
70 #ifndef _WIN64
71 p = GetProcAddress(h, "SetProcessDEPPolicy");
72 if (p != 0) {
73 reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
75 #endif
76 p = GetProcAddress(h, "SetDllDirectoryW");
77 if (p != 0) {
78 reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
80 p = GetProcAddress(h, "SetSearchPathMode");
81 if (p != 0) {
82 reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
86 WSADATA wsaData;
87 int error;
88 WORD wVersionRequested;
90 wVersionRequested = MAKEWORD(1, 1);
92 error = WSAStartup(wVersionRequested, &wsaData);
93 if ( 0 == error )
95 WORD wMajorVersionRequired = 1;
96 WORD wMinorVersionRequired = 1;
98 if ((LOBYTE(wsaData.wVersion) < wMajorVersionRequired) ||
99 ((LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
100 ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired))))
102 // How to handle a very unlikely error ???
105 else
107 // How to handle a very unlikely error ???
110 #if defined _MSC_VER // appears unavailable with MinGW
111 // It appears that at least some jvm.dll versions can cause calls to
112 // _fileno(NULL), which leads to a call of the invalid parameter handler,
113 // and the default handler causes the application to crash, so install a
114 // "harmless" one (cf. fdo#38913):
115 _set_invalid_parameter_handler(&invalidParameterHandler);
116 #endif
118 osl_setCommandArgs(argc, argv);
121 SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize()
123 if ( SOCKET_ERROR == WSACleanup() )
125 // We should never reach this point or we did wrong elsewhere
131 #ifdef __cplusplus
132 } // extern "C"
133 #endif
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */