xref: /AOO41X/main/sal/osl/w32/salinit.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
30 
31 #include "system.h"
32 #include <osl/process.h>
33 #include <sal/types.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 // Prototypes for initialization and deinitialization of SAL library
40 
41 void SAL_CALL sal_detail_initialize(int argc, char ** argv)
42 {
43     // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
44     // SetDllDirectoryW(L"");
45     // SetSearchPathMode(
46     //   BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
47     HMODULE h = GetModuleHandleW(L"kernel32.dll");
48     if (h != 0) {
49         FARPROC p = GetProcAddress(h, "SetProcessDEPPolicy");
50         if (p != 0) {
51             reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
52 	}
53 	p = GetProcAddress(h, "SetDllDirectoryW");
54         if (p != 0) {
55             reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
56         }
57         p = GetProcAddress(h, "SetSearchPathMode");
58         if (p != 0) {
59             reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
60         }
61     }
62 
63     WSADATA wsaData;
64     int     error;
65     WORD    wVersionRequested;
66 
67     wVersionRequested = MAKEWORD(1, 1);
68 
69     error = WSAStartup(wVersionRequested, &wsaData);
70     if ( 0 == error )
71     {
72         WORD wMajorVersionRequired = 1;
73         WORD wMinorVersionRequired = 1;
74 
75         if ((LOBYTE(wsaData.wVersion) <  wMajorVersionRequired) ||
76             (LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
77             ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired)))
78             {
79 				// How to handle a very unlikely error ???
80             }
81     }
82     else
83     {
84 		// How to handle a very unlikely error ???
85     }
86 
87     osl_setCommandArgs(argc, argv);
88 }
89 
90 void SAL_CALL sal_detail_deinitialize()
91 {
92 	if ( SOCKET_ERROR == WSACleanup() )
93 	{
94 		// We should never reach this point or we did wrong elsewhere
95 	}
96 }
97 
98 
99 
100 #ifdef __cplusplus
101 }	// extern "C"
102 #endif
103