merge the formfield patch from ooo-build
[ooovba.git] / sal / systools / win32 / uwinapi / Uwinapi.h
blob63ca775bef67af4ac8ac5982acef2102fad85b19
1 #pragma once
3 #ifdef _UWINAPI_
4 #define _KERNEL32_
5 #define _USER32_
6 #define _SHELL32_
7 #endif
9 #include <windows.h>
10 #include <malloc.h>
12 #ifndef _UWINAPI_
13 EXTERN_C WINBASEAPI DWORD UWINAPI_dwFakedVersion;
14 #endif
16 EXTERN_C WINBASEAPI DWORD SetVersion( DWORD dwVersion );
18 /* Version macros */
20 #define MAKE_VER_WIN32( major, minor, build, isWindows ) \
21 ((DWORD)MAKELONG( MAKEWORD( major, minor ), (build) | ( isWindows ? 0x8000 : 0 ) ))
23 #define MAKE_VER_WIN32_NT( major, minor, build ) \
24 MAKE_VER_WIN32( major, minor, build, FALSE )
26 #define MAKE_VER_WIN32_WINDOWS( major, minor, build ) \
27 MAKE_VER_WIN32( major, minor, build, TRUE )
29 #define VER_WIN32_WINDOWS_95 MAKE_VER_WIN32_WINDOWS( 4, 0, 0 )
30 #define VER_WIN32_WINDOWS_98 MAKE_VER_WIN32_WINDOWS( 4, 10, 0 )
31 #define VER_WIN32_WINDOWS_ME MAKE_VER_WIN32_WINDOWS( 4, 90, 0 )
32 #define VER_WIN32_NT_NT4 MAKE_VER_WIN32_NT( 4, 0, 0 )
33 #define VER_WIN32_NT_2000 MAKE_VER_WIN32_NT( 5, 0, 0 )
34 #define VER_WIN32_NT_XP MAKE_VER_WIN32_NT( 5, 1, 0 )
37 EXTERN_C WINBASEAPI LPSTR WINAPI lstrchrA( LPCSTR lpString, CHAR c );
38 EXTERN_C WINBASEAPI LPWSTR WINAPI lstrchrW( LPCWSTR lpString, WCHAR c );
39 EXTERN_C WINBASEAPI LPSTR WINAPI lstrrchrA( LPCSTR lpString, CHAR c );
40 EXTERN_C WINBASEAPI LPWSTR WINAPI lstrrchrW( LPCWSTR lpString, WCHAR c );
42 #ifdef UNICODE
43 #define lstrrchr lstrrchrW
44 #define lstrchr lstrchrW
45 #else
46 #define lstrrchr lstrrchrA
47 #define lstrchr lstrchrA
48 #endif
50 // macro that calculates the count of elements of a static array
52 #define bufsizeof(buf) (sizeof(buf) / sizeof((buf)[0]))
55 #define IsValidHandle(Handle) ((DWORD)(Handle) + 1 > 1)
57 #ifdef __cplusplus
59 #define _AUTO_WSTR2STR( lpStrA, lpStrW ) \
60 LPSTR lpStrA; \
61 if ( lpStrW ) \
62 { \
63 int cNeeded = WideCharToMultiByte( CP_ACP, 0, lpStrW, -1, NULL, 0, NULL, NULL ); \
64 lpStrA = (LPSTR)_alloca( cNeeded * sizeof(CHAR) ); \
65 WideCharToMultiByte( CP_ACP, 0, lpStrW, -1, lpStrA, cNeeded, NULL, NULL ); \
66 } \
67 else \
68 lpStrA = NULL;
71 #define AUTO_WSTR2STR( lpStr ) \
72 _AUTO_WSTR2STR( lpStr##A, lpStr##W )
74 #define AUTO_STR( lpStr, cchBuffer ) \
75 LPSTR lpStr##A = lpStr##W ? (LPSTR)_alloca( (cchBuffer) * sizeof(CHAR) ) : NULL;
77 #endif // __cplusplus
79 #define STRBUF2WSTR( lpStr, cchSrcBuffer, cchDestBuffer ) \
80 MultiByteToWideChar( CP_ACP, 0, lpStr##A, cchSrcBuffer, lpStr##W, cchDestBuffer )
82 #define STR2WSTR( lpStr, cchBuffer ) \
83 STRBUF2WSTR( lpStr, -1, cchBuffer )
85 #define WSTR2STR( lpStr, cchBuffer ) \
86 WideCharToMultiByte( CP_ACP, 0, lpStr##W, -1, lpStr##A, cchBuffer, NULL, NULL )
88 EXTERN_C void WINAPI ResolveThunk_WINDOWS( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure );
89 EXTERN_C void WINAPI ResolveThunk_TRYLOAD( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure );
90 EXTERN_C void WINAPI ResolveThunk_ALLWAYS( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure );
95 #define IMPLEMENT_THUNK( module, resolve, rettype, calltype, func, params ) \
96 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
97 EXTERN_C rettype calltype func##_##resolve params; \
98 static rettype calltype func##_##Failure params; \
99 static _declspec ( naked ) func##_Thunk() \
101 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func, (FARPROC)func##_##resolve, (FARPROC)func##_##Failure ); \
102 _asm jmp [module##_##func##_Ptr] \
104 EXTERN_C _declspec( naked ) rettype calltype func params \
106 _asm jmp [module##_##func##_Ptr] \
108 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
109 static rettype calltype func##_##Failure params \
111 SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); \
112 return (rettype)0; \
114 EXTERN_C rettype calltype func##_##resolve params
126 #define DEFINE_CUSTOM_THUNK( module, resolve, rettype, calltype, func, params ) \
127 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
128 static _declspec ( naked ) func##_Thunk() \
130 ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func ); \
131 _asm jmp [module##_##func##_Ptr] \
133 EXTERN_C _declspec( naked ) rettype calltype func params \
135 _asm jmp [module##_##func##_Ptr] \
137 EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk;