xref: /trunk/main/sal/osl/w32/salinit.cxx (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sal.hxx"
24 
25 #include "system.h"
26 #include <osl/process.h>
27 #include <sal/types.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 // Prototypes for initialization and deinitialization of SAL library
34 
35 void SAL_CALL sal_detail_initialize(int argc, char ** argv)
36 {
37     // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
38     // SetDllDirectoryW(L"");
39     // SetSearchPathMode(
40     //   BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
41     HMODULE h = GetModuleHandleW(L"kernel32.dll");
42     if (h != 0) {
43         FARPROC p = GetProcAddress(h, "SetProcessDEPPolicy");
44         if (p != 0) {
45             reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
46     }
47     p = GetProcAddress(h, "SetDllDirectoryW");
48         if (p != 0) {
49             reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
50         }
51         p = GetProcAddress(h, "SetSearchPathMode");
52         if (p != 0) {
53             reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
54         }
55     }
56 
57     WSADATA wsaData;
58     int     error;
59     WORD    wVersionRequested;
60 
61     wVersionRequested = MAKEWORD(1, 1);
62 
63     error = WSAStartup(wVersionRequested, &wsaData);
64     if ( 0 == error )
65     {
66         WORD wMajorVersionRequired = 1;
67         WORD wMinorVersionRequired = 1;
68 
69         if ((LOBYTE(wsaData.wVersion) <  wMajorVersionRequired) ||
70             (LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
71             ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired)))
72             {
73                 // How to handle a very unlikely error ???
74             }
75     }
76     else
77     {
78         // How to handle a very unlikely error ???
79     }
80 
81     osl_setCommandArgs(argc, argv);
82 }
83 
84 void SAL_CALL sal_detail_deinitialize()
85 {
86     if ( SOCKET_ERROR == WSACleanup() )
87     {
88         // We should never reach this point or we did wrong elsewhere
89     }
90 }
91 
92 
93 
94 #ifdef __cplusplus
95 }   // extern "C"
96 #endif
97 
98 /* vim: set noet sw=4 ts=4: */
99