1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macros.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <systools/win32/uwinapi.h>
38 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
39 #pragma warning(disable:4740)
49 // Globally disable "warning C4100: unreferenced formal parameter" caused by
52 #pragma warning(disable:4100)
57 #define MAKE_VER_WIN32( major, minor, build, isWindows ) \
58 ((DWORD)MAKELONG( MAKEWORD( major, minor ), (build) | ( isWindows ? 0x8000 : 0 ) ))
60 #define MAKE_VER_WIN32_NT( major, minor, build ) \
61 MAKE_VER_WIN32( major, minor, build, FALSE )
63 #define MAKE_VER_WIN32_WINDOWS( major, minor, build ) \
64 MAKE_VER_WIN32( major, minor, build, TRUE )
66 #define VER_WIN32_WINDOWS_95 MAKE_VER_WIN32_WINDOWS( 4, 0, 0 )
67 #define VER_WIN32_WINDOWS_98 MAKE_VER_WIN32_WINDOWS( 4, 10, 0 )
68 #define VER_WIN32_WINDOWS_ME MAKE_VER_WIN32_WINDOWS( 4, 90, 0 )
69 #define VER_WIN32_NT_NT4 MAKE_VER_WIN32_NT( 4, 0, 0 )
70 #define VER_WIN32_NT_2000 MAKE_VER_WIN32_NT( 5, 0, 0 )
71 #define VER_WIN32_NT_XP MAKE_VER_WIN32_NT( 5, 1, 0 )
76 #define _AUTO_WSTR2STR( lpStrA, lpStrW ) \
80 int cNeeded = WideCharToMultiByte( CP_ACP, 0, lpStrW, -1, NULL, 0, NULL, NULL ); \
81 lpStrA = (LPSTR)_alloca( cNeeded * sizeof(CHAR) ); \
82 WideCharToMultiByte( CP_ACP, 0, lpStrW, -1, lpStrA, cNeeded, NULL, NULL ); \
88 #define AUTO_WSTR2STR( lpStr ) \
89 _AUTO_WSTR2STR( lpStr##A, lpStr##W )
91 #define AUTO_STR( lpStr, cchBuffer ) \
92 LPSTR lpStr##A = lpStr##W ? (LPSTR)_alloca( (cchBuffer) * sizeof(CHAR) ) : NULL;
94 #endif /* __cplusplus */
97 #define STRBUF2WSTR( lpStr, cchSrcBuffer, cchDestBuffer ) \
98 MultiByteToWideChar( CP_ACP, 0, lpStr##A, cchSrcBuffer, lpStr##W, (int) cchDestBuffer )
100 #define STR2WSTR( lpStr, cchBuffer ) \
101 STRBUF2WSTR( lpStr, -1, cchBuffer )
103 #define WSTR2STR( lpStr, cchBuffer ) \
104 WideCharToMultiByte( CP_ACP, 0, lpStr##W, -1, lpStr##A, cchBuffer, NULL, NULL )
106 EXTERN_C
void WINAPI
ResolveThunk_WINDOWS( FARPROC
*lppfn
, LPCSTR lpLibFileName
, LPCSTR lpFuncName
, FARPROC lpfnEmulate
, FARPROC lpfnFailure
);
107 EXTERN_C
void WINAPI
ResolveThunk_TRYLOAD( FARPROC
*lppfn
, LPCSTR lpLibFileName
, LPCSTR lpFuncName
, FARPROC lpfnEmulate
, FARPROC lpfnFailure
);
108 EXTERN_C
void WINAPI
ResolveThunk_ALLWAYS( FARPROC
*lppfn
, LPCSTR lpLibFileName
, LPCSTR lpFuncName
, FARPROC lpfnEmulate
, FARPROC lpfnFailure
);
114 #define IMPLEMENT_THUNK( module, resolve, rettype, calltype, func, params ) \
115 static void func##_Thunk(); \
116 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
117 EXTERN_C rettype calltype func params \
120 asm(" jmp *(%0)"::"m"(module##_##func##_Ptr)); \
122 EXTERN_C rettype calltype func##_##resolve params; \
123 static rettype calltype func##_##Failure params; \
124 static void func##_Thunk() \
126 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func, (FARPROC)func##_##resolve, (FARPROC)func##_##Failure ); \
127 asm(" movl %ebp, %esp"); \
129 asm(" jmp *(%0)"::"m"(module##_##func##_Ptr)); \
131 static rettype calltype func##_##Failure params \
133 SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); \
136 EXTERN_C rettype calltype func##_##resolve params
138 #define IMPLEMENT_THUNK( module, resolve, rettype, calltype, func, params ) \
139 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
140 EXTERN_C rettype calltype func##_##resolve params; \
141 static rettype calltype func##_##Failure params; \
142 static _declspec ( naked ) void func##_Thunk() \
144 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func, (FARPROC)func##_##resolve, (FARPROC)func##_##Failure ); \
145 _asm jmp [module##_##func##_Ptr] \
147 EXTERN_C _declspec( naked ) rettype calltype func params \
149 _asm jmp [module##_##func##_Ptr] \
151 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
152 static rettype calltype func##_##Failure params \
154 SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); \
157 EXTERN_C rettype calltype func##_##resolve params
163 #define DEFINE_CUSTOM_THUNK( module, resolve, rettype, calltype, func, params ) \
164 static void func##_Thunk(); \
165 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
166 static void func##_Thunk() \
168 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func ); \
169 asm(" movl %ebp, %esp"); \
171 asm(" jmp *(%0)"::"m"(module##_##func##_Ptr)); \
173 EXTERN_C rettype calltype func params \
176 asm(" jmp *(%0)"::"m"(module##_##func##_Ptr)); \
179 #define DEFINE_CUSTOM_THUNK( module, resolve, rettype, calltype, func, params ) \
180 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
181 static _declspec ( naked ) void func##_Thunk() \
183 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func ); \
184 _asm jmp [module##_##func##_Ptr] \
186 EXTERN_C _declspec( naked ) rettype calltype func params \
188 _asm jmp [module##_##func##_Ptr] \
190 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk;
195 #define DEFINE_DEFAULT_THUNK( module, resolve, rettype, calltype, func, params ) \
196 static void func##_Thunk(); \
197 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
198 static rettype calltype func##_##Failure params; \
199 static _declspec ( naked ) void func##_Thunk() \
201 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func, NULL, (FARPROC)func##_##Failure ); \
202 asm(" movl %ebp, %esp"); \
204 asm(" jmp *(%0)"::"m"(module##_##func##_Ptr)); \
206 EXTERN_C _declspec( naked ) rettype calltype func params \
209 asm(" jmp *(%0)"::"m"(module##_##func##_Ptr)); \
211 static rettype calltype func##_##Failure params \
213 SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); \
217 #define DEFINE_DEFAULT_THUNK( module, resolve, rettype, calltype, func, params ) \
218 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
219 static rettype calltype func##_##Failure params; \
220 static _declspec ( naked ) void func##_Thunk() \
222 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func, NULL, (FARPROC)func##_##Failure ); \
223 _asm jmp [module##_##func##_Ptr] \
225 EXTERN_C _declspec( naked ) rettype calltype func params \
227 _asm jmp [module##_##func##_Ptr] \
229 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
230 static rettype calltype func##_##Failure params \
232 SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); \