2 * Compatibility functions for the various versions of Win32.
4 * ----------------------------------------------------------------
7 * Copyright (C) 2004 Mojave Group, Caltech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation,
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Additional permission is given to link this library with the
24 * OpenSSL project's "OpenSSL" library, and with the OCaml runtime,
25 * and you may distribute the linked executables. See the file
26 * LICENSE.libmojave for more details.
28 * Author: Jason Hickey
29 * @email{jyh@cs.caltech.edu}
33 #include <caml/mlvalues.h>
34 #include <caml/alloc.h>
35 #include <caml/memory.h>
36 #include <caml/fail.h>
37 #include <caml/custom.h>
40 /* Disable some of the warnings */
41 #pragma warning( disable : 4100 4201 )
47 #include "lm_compat_win32.h"
50 * Pointers to the functions.
52 static HANDLE (__stdcall
*OpenThreadF
)(DWORD
, BOOL
, DWORD
);
53 static BOOL (__stdcall
*GetLongPathNameF
)(LPCTSTR
, LPTSTR
, DWORD
);
54 static HANDLE (__stdcall
*CreateToolhelp32SnapshotF
)(DWORD
, DWORD
);
55 static BOOL (__stdcall
*Thread32FirstF
)(HANDLE
, LPTHREADENTRY32
);
56 static BOOL (__stdcall
*Thread32NextF
)(HANDLE
, LPTHREADENTRY32
);
57 static HRESULT (__stdcall
*SHGetFolderPathF
)(HWND
, int, HANDLE
, DWORD
, LPTSTR
);
58 static BOOL (__stdcall
*SHGetSpecialFolderPathF
)(HWND
, LPTSTR
, int, BOOL
);
63 int ExistsOpenThread(void)
65 return OpenThreadF
? 1 : 0;
68 HANDLE
CompatOpenThread(DWORD arg1
, BOOL arg2
, DWORD arg3
)
70 return OpenThreadF(arg1
, arg2
, arg3
);
73 BOOL
CompatGetLongPathName(LPCTSTR arg1
, LPTSTR arg2
, DWORD arg3
)
78 b
= GetLongPathNameF(arg1
, arg2
, arg3
);
82 HANDLE
CompatCreateToolhelp32Snapshot(DWORD arg1
, DWORD arg2
)
84 return CreateToolhelp32SnapshotF(arg1
, arg2
);
87 BOOL
CompatThread32First(HANDLE arg1
, LPTHREADENTRY32 arg2
)
89 return Thread32FirstF(arg1
, arg2
);
92 BOOL
CompatThread32Next(HANDLE arg1
, LPTHREADENTRY32 arg2
)
94 return Thread32NextF(arg1
, arg2
);
97 HRESULT
CompatSHGetFolderPath(HWND hwndOwner
, int nFolder
, HANDLE hToken
, DWORD dwFlags
, LPTSTR pszPath
)
100 return SHGetFolderPathF(hwndOwner
, nFolder
, hToken
, dwFlags
, pszPath
);
101 else if(SHGetSpecialFolderPathF
) {
102 BOOL fCreate
= nFolder
& CSIDL_FLAG_CREATE
? TRUE
: FALSE
;
103 nFolder
&= ~CSIDL_FLAG_CREATE
;
104 fCreate
= SHGetSpecialFolderPathF(hwndOwner
, pszPath
, nFolder
, fCreate
);
105 return fCreate
? S_OK
: E_FAIL
;
112 * Decide whether OpenThread is available.
114 static void init(void)
118 hinst
= LoadLibrary(TEXT("KERNEL32"));
120 *(FARPROC
*)&OpenThreadF
= GetProcAddress(hinst
, "OpenThread");
122 *(FARPROC
*)&GetLongPathNameF
= GetProcAddress(hinst
, "GetLongPathNameW");
124 *(FARPROC
*)&GetLongPathNameF
= GetProcAddress(hinst
, "GetLongPathNameA");
126 *(FARPROC
*)&CreateToolhelp32SnapshotF
= GetProcAddress(hinst
, "CreateToolhelp32Snapshot");
127 *(FARPROC
*)&Thread32FirstF
= GetProcAddress(hinst
, "Thread32First");
128 *(FARPROC
*)&Thread32NextF
= GetProcAddress(hinst
, "Thread32Next");
131 hinst
= LoadLibrary(TEXT("SHELL32"));
134 *(FARPROC
*)&SHGetFolderPathF
= GetProcAddress(hinst
, "SHGetFolderPathW");
135 *(FARPROC
*)&SHGetSpecialFolderPathF
= GetProcAddress(hinst
, "SHGetSpecialFolderPathW");
137 *(FARPROC
*)&SHGetFolderPathF
= GetProcAddress(hinst
, "SHGetFolderPathA");
138 *(FARPROC
*)&SHGetSpecialFolderPathF
= GetProcAddress(hinst
, "SHGetSpecialFolderPathA");
142 if(SHGetFolderPathF
== 0) {
143 hinst
= LoadLibrary(TEXT("SHFOLDER"));
146 *(FARPROC
*)&SHGetFolderPathF
= GetProcAddress(hinst
, "SHGetFolderPathW");
148 *(FARPROC
*)&SHGetFolderPathF
= GetProcAddress(hinst
, "SHGetFolderPathA");
157 value
lm_compat_init(value v_unit
)
165 value
lm_compat_init(value v_unit
)