xref: /aoo4110/main/sal/osl/w32/salinit.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 
27 #include "system.h"
28 #include <osl/process.h>
29 #include <sal/types.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 // Prototypes for initialization and deinitialization of SAL library
36 
sal_detail_initialize(int argc,char ** argv)37 void SAL_CALL sal_detail_initialize(int argc, char ** argv)
38 {
39     // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
40     // SetDllDirectoryW(L"");
41     // SetSearchPathMode(
42     //   BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
43     HMODULE h = GetModuleHandleW(L"kernel32.dll");
44     if (h != 0) {
45         FARPROC p = GetProcAddress(h, "SetProcessDEPPolicy");
46         if (p != 0) {
47             reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
48 	}
49 	p = GetProcAddress(h, "SetDllDirectoryW");
50         if (p != 0) {
51             reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
52         }
53         p = GetProcAddress(h, "SetSearchPathMode");
54         if (p != 0) {
55             reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
56         }
57     }
58 
59     WSADATA wsaData;
60     int     error;
61     WORD    wVersionRequested;
62 
63     wVersionRequested = MAKEWORD(1, 1);
64 
65     error = WSAStartup(wVersionRequested, &wsaData);
66     if ( 0 == error )
67     {
68         WORD wMajorVersionRequired = 1;
69         WORD wMinorVersionRequired = 1;
70 
71         if ((LOBYTE(wsaData.wVersion) <  wMajorVersionRequired) ||
72             (LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
73             ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired)))
74             {
75 				// How to handle a very unlikely error ???
76             }
77     }
78     else
79     {
80 		// How to handle a very unlikely error ???
81     }
82 
83     osl_setCommandArgs(argc, argv);
84 }
85 
sal_detail_deinitialize()86 void SAL_CALL sal_detail_deinitialize()
87 {
88 	if ( SOCKET_ERROR == WSACleanup() )
89 	{
90 		// We should never reach this point or we did wrong elsewhere
91 	}
92 }
93 
94 
95 
96 #ifdef __cplusplus
97 }	// extern "C"
98 #endif
99