1 /* 2 * M A P I W I N . H 3 * 4 * Definitions used by the MAPI Development Team to aid in 5 * developing single-source service providers that run on 6 * both WIN32 and WIN16 platforms. 7 * There are three sections. 8 * 9 * The first section defines how to call something that 10 * is available by different methods in WIN16 vs. WIN32. 11 * As such, they are totally new mechanisms. 12 * 13 * The second section establishes things that are available 14 * AS-IS in one environment but we have to define for the 15 * other environment. 16 * 17 * The third section simply defines a few conventions 18 * (simplifications) for common operations. 19 * 20 * Copyright (c) 2009 Microsoft Corporation. All Rights Reserved. 21 */ 22 23 /* 24 * Routines are included in the first section to manage per-instance 25 * global variables for DLLs. They assume that all of the DLL's 26 * per-instance global variables live in a single block of memory. 27 * Functions are provided to install and retrieve the correct block of 28 * memory for the current instance. 29 * 30 * There are only two functions: 31 * 32 * PvGetInstanceGlobals Call this to get the address of the 33 * per-instance globals structure. 34 * ScSetinstanceGlobals Call this to install the 35 * per-instance globals structure. It 36 * may fail if the number of instances 37 * exceeds a certain limit. 38 * 39 * The caller is free to choose the name, size, and allocation 40 * method of the per-instance global variables structure. 41 * 42 * The WIN32 implementation uses a pointer in the DLL's data 43 * segment. This assumes that the DLL gets a separate instance 44 * of the default data segment per calling process. 45 * 46 * The WIN16 implementation uses a fixed array of pointers and a 47 * matching fixed array of keys unique to the calling process. 48 */ 49 50 /* 51 * The second section consists largely of Win32 file I/O functions 52 * that are not supported under Win16. These functions are 53 * implemented in mapiwin.c, using DOS calls. Most have limitations 54 * relative to their Win32 counterparts, which are spelled out in 55 * the comments to the source code. 56 */ 57 58 #ifndef __MAPIWIN_H__ 59 #define __MAPIWIN_H__ 60 61 #if _MSC_VER > 1000 62 #pragma once 63 #endif 64 65 #if defined (WIN32) && !defined (_WIN32) 66 #define _WIN32 67 #endif 68 69 #include "mapinls.h" 70 71 #ifdef __cplusplus 72 extern "C" { 73 #endif 74 75 76 #if defined(_MAC) 77 78 #define MULDIV(x,y,z) MulDiv(x,y,z) 79 80 LPVOID FAR PASCAL PvGetInstanceGlobals(WORD wDataSet); 81 LONG FAR PASCAL ScSetInstanceGlobals(LPVOID pv, WORD wDataSet); 82 LONG FAR PASCAL ScSetVerifyInstanceGlobals(LPVOID pv, DWORD dwPid, 83 WORD wDataSet); 84 LPVOID FAR PASCAL PvGetVerifyInstanceGlobals(DWORD dwPid, DWORD wDataSet); 85 LPVOID FAR PASCAL PvSlowGetInstanceGlobals(DWORD dwPid, DWORD wDataSet); 86 BOOL FAR PASCAL FCleanupInstanceGlobals(WORD, DWORD); 87 88 #elif defined(_WIN64) || defined(_WIN32) 89 90 #define MULDIV(x,y,z) MulDiv(x,y,z) 91 92 extern LPVOID pinstX; 93 #define PvGetInstanceGlobals() pinstX 94 #define ScSetInstanceGlobals(_pv) (pinstX = _pv, 0) 95 #define PvGetVerifyInstanceGlobals(_pid) pinstX 96 #define ScSetVerifyInstanceGlobals(_pv,_pid) (pinstX = _pv, 0) 97 #define PvSlowGetInstanceGlobals(_pid) pinstX 98 99 #else 100 #error "Unknown Platform: MAPI is currently supported on Win32 and Win64" 101 #endif 102 103 #if (defined(_WIN64) || defined(_WIN32)) && !defined(_MAC) 104 #define szMAPIDLLSuffix "32" 105 #elif defined(DOS) 106 #define szMAPIDLLSuffix "" 107 #elif defined(_MAC) 108 #define szMAPIDLLSuffix "M" 109 #else 110 #error "Don't know the suffix for DLLs on this platform" 111 #endif 112 113 /********************************/ 114 /* Things missing from one */ 115 /* system-provided environment */ 116 /* or the other. */ 117 /********************************/ 118 119 #if !defined(_WIN64) && !defined(_WIN32) 120 #define ZeroMemory(pb,cb) memset((pb),0,(cb)) 121 #define FillMemory(pb,cb,b) memset((pb),(b),(cb)) 122 #define CopyMemory(pbDst,pbSrc,cb) do \ 123 { \ 124 size_t _cb = (size_t)(cb); \ 125 if (_cb) \ 126 memcpy(pbDst,pbSrc,_cb);\ 127 } while (FALSE) 128 #define MoveMemory(pbDst,pbSrc,cb) memmove((pbDst),(pbSrc),(cb)) 129 130 #define UNALIGNED 131 132 #endif 133 134 #if defined(_MAC) 135 136 typedef int INT; 137 typedef unsigned long ULONG; 138 typedef short SHORT; 139 typedef unsigned short USHORT; 140 typedef double LONGLONG; 141 typedef double DWORDLONG; 142 typedef unsigned char UCHAR; 143 typedef unsigned char FAR* PUCHAR; 144 typedef int BOOL; 145 146 147 /* Synchronization */ 148 #define InterlockedIncrement(plong) (++(*(plong))) 149 #define InterlockedDecrement(plong) (--(*(plong))) 150 151 #ifndef CreateMutex 152 #define CreateMutexA CreateMutex 153 #define CreateMutexW CreateMutex 154 #define CreateMutex(pv, bool, sz) (INVALID_HANDLE_VALUE) 155 #endif 156 157 #define WaitForSingleObject(hObj, dw) ((void)0) 158 #define ReleaseMutex(hObj) ((BOOL)1) 159 #define CloseMutexHandle(hObj) TRUE 160 161 #define CRITICAL_SECTION ULONG 162 #define InitializeCriticalSection(_pcs) ((void)0) 163 #define DeleteCriticalSection(_pcs) ((void)0) 164 #define EnterCriticalSection(_pcs) ((void)0) 165 #define LeaveCriticalSection(_pcs) ((void)0) 166 167 #define MAX_PATH 260 168 169 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 170 171 #define CREATE_NEW 1 172 #define CREATE_ALWAYS 2 173 #define OPEN_EXISTING 3 174 #define OPEN_ALWAYS 4 175 #define TRUNCATE_EXISTING 5 176 177 #define FILE_ATTRIBUTE_READONLY 0x00000001 178 #define FILE_ATTRIBUTE_HIDDEN 0x00000002 179 #define FILE_ATTRIBUTE_SYSTEM 0x00000004 180 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 181 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 182 #define FILE_ATTRIBUTE_NORMAL 0x00000080 183 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 184 185 #define FILE_FLAG_WRITE_THROUGH 0x80000000 186 #define FILE_FLAG_RANDOM_ACCESS 0x10000000 187 188 #define TIME_ZONE_ID_UNKNOWN 0 189 #define TIME_ZONE_ID_STANDARD 1 190 #define TIME_ZONE_ID_DAYLIGHT 2 191 192 193 194 DWORD WINAPI GetLastError(void); 195 DWORD WINAPI GetFileAttributes(LPCSTR lpFileName); 196 DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); 197 BOOL WINAPI GetFileTime(HANDLE hFile, FILETIME FAR *lpftCreation, 198 FILETIME FAR *lpftLastAccess, FILETIME FAR *lpftLastWrite); 199 BOOL WINAPI SetFileTime(HANDLE hFile, const FILETIME FAR *lpftCreation, 200 const FILETIME FAR *lpftLastAccess, 201 const FILETIME FAR *lpftLastWrite); 202 DWORD WINAPI SetFilePointer(HANDLE hFile, LONG lDistanceToMove, 203 LONG FAR *lpDistanceToMoveHigh, DWORD dwMoveMethod); 204 BOOL WINAPI SetEndOfFile(HANDLE hFile); 205 BOOL WINAPI CloseHandle(HANDLE hObject); 206 DWORD WINAPI GetTempPath(DWORD nBufferLength, LPSTR lpBuffer); 207 UINT WINAPI GetTempFileName32 (LPCSTR lpPathName, LPCSTR lpPrefixString, 208 UINT uUnique, LPSTR lpTempFileName); 209 BOOL WINAPI DeleteFile(LPCSTR lpFileName); 210 BOOL WINAPI RemoveDirectory(LPCSTR lpPathName); 211 BOOL WINAPI CopyFile(LPCSTR szSrc, LPCSTR szDst, BOOL fFailIfExists); 212 BOOL WINAPI MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName); 213 HANDLE WINAPI FindFirstFile(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData); 214 BOOL WINAPI FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData); 215 BOOL WINAPI FindClose(HANDLE hFindFile); 216 DWORD WINAPI GetFullPathName(LPCSTR lpFileName, DWORD nBufferLength, 217 LPSTR lpBuffer, LPSTR *lpFilePart); 218 void WINAPI Sleep(DWORD dwMilliseconds); 219 LONG WINAPI CompareFileTime(const FILETIME FAR *, const FILETIME FAR *); 220 BOOL WINAPI LocalFileTimeToFileTime(const FILETIME FAR *, FILETIME FAR *); 221 BOOL WINAPI FileTimeToLocalFileTime(const FILETIME FAR *, FILETIME FAR *); 222 BOOL WINAPI FileTimeToSystemTime(const FILETIME FAR *, SYSTEMTIME FAR *); 223 BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME FAR *, FILETIME FAR *); 224 void WINAPI GetSystemTime(SYSTEMTIME FAR *); 225 void WINAPI GetLocalTime(SYSTEMTIME FAR *); 226 BOOL WINAPI FileTimeToDosDateTime(const FILETIME FAR * lpFileTime, 227 WORD FAR *lpFatDate, WORD FAR *lpFatTime); 228 BOOL WINAPI DosDateTimeToFileTime(WORD wFatDate, WORD wFatTime, 229 FILETIME FAR * lpFileTime); 230 DWORD WINAPI GetTimeZoneInformation( 231 LPTIME_ZONE_INFORMATION lpTimeZoneInformation); 232 BOOL WINAPI SetTimeZoneInformation( 233 const TIME_ZONE_INFORMATION FAR *lpTimeZoneInformation); 234 235 DWORD WINAPI GetCurrentProcessId(void); 236 long WINAPI MulDiv32(long, long, long); 237 238 #else /* _MAC */ 239 240 /* Remaps GetTempFileName32() to the real 32bit version */ 241 242 #define GetTempFileName32(_szPath,_szPfx,_n,_lpbuf) GetTempFileName(_szPath,_szPfx,_n,_lpbuf) 243 244 #define CloseMutexHandle CloseHandle 245 246 #endif /* _MAC */ 247 248 249 #ifdef _MAC 250 #define CRITICAL_SECTION ULONG 251 #define InitializeCriticalSection(_pcs) ((void)0) 252 #define DeleteCriticalSection(_pcs) ((void)0) 253 #define EnterCriticalSection(_pcs) ((void)0) 254 #define LeaveCriticalSection(_pcs) ((void)0) 255 #endif 256 257 /********************************/ 258 /* Our private conventions */ 259 /* (common to WIN32/WIN64) */ 260 /********************************/ 261 262 #define Cbtszsize(_a) ((lstrlen(_a)+1)*sizeof(TCHAR)) 263 #define CbtszsizeA(_a) ((lstrlenA(_a) + 1)) 264 #define CbtszsizeW(_a) ((lstrlenW(_a) + 1) * sizeof(WCHAR)) 265 #define HexCchOf(_s) (sizeof(_s)*2+1) 266 #define HexSizeOf(_s) (HexCchOf(_s)*sizeof(TCHAR)) 267 268 BOOL WINAPI IsBadBoundedStringPtr(const void FAR* lpsz, UINT cchMax); 269 270 #ifdef __cplusplus 271 } 272 #endif 273 274 #endif /* __MAPIWIN_H__ */ 275