home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / mapiwin.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  16KB  |  431 lines

  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 1986-1996 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 defined (WIN32) && !defined (_WIN32)
  62. #define _WIN32
  63. #endif
  64.  
  65. #include "mapinls.h"
  66.  
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70.  
  71.  
  72. /********************************/
  73. /*  Our conventions for things  */
  74. /*  we choose to do differently */
  75. /*  on WIN16 vs. WIN32.         */
  76. /********************************/
  77.  
  78. #ifdef  WIN16
  79.  
  80. #define MULDIV(x,y,z)               MulDiv32(x,y,z)
  81. #define IsBadReadPtr(lp,cb)         FBadReadPtr(lp,cb)
  82.  
  83. #define cInstMax                    50
  84. LPVOID FAR PASCAL   PvGetInstanceGlobals(void);
  85. LONG FAR PASCAL     ScSetInstanceGlobals(LPVOID pv);
  86. LONG FAR PASCAL     ScSetVerifyInstanceGlobals(LPVOID pv, DWORD dwPid);
  87. LPVOID FAR PASCAL   PvGetVerifyInstanceGlobals(DWORD dwPid);
  88. LPVOID FAR PASCAL   PvSlowGetInstanceGlobals(DWORD dwPid);
  89. BOOL __export FAR PASCAL FCleanupInstanceGlobals(WORD, DWORD);
  90.  
  91. #elif defined(_MAC) /* !WIN16 */
  92.  
  93. #define MULDIV(x,y,z)               MulDiv(x,y,z)
  94.  
  95. LPVOID FAR PASCAL   PvGetInstanceGlobals(WORD wDataSet);
  96. LONG FAR PASCAL     ScSetInstanceGlobals(LPVOID pv, WORD wDataSet);
  97. LONG FAR PASCAL     ScSetVerifyInstanceGlobals(LPVOID pv, DWORD dwPid,
  98.                         WORD wDataSet);
  99. LPVOID FAR PASCAL   PvGetVerifyInstanceGlobals(DWORD dwPid, DWORD wDataSet);
  100. LPVOID FAR PASCAL   PvSlowGetInstanceGlobals(DWORD dwPid, DWORD wDataSet);
  101. BOOL FAR PASCAL     FCleanupInstanceGlobals(WORD, DWORD);
  102.  
  103. #else   /* !WIN16 */
  104.  
  105. #define MULDIV(x,y,z)               MulDiv(x,y,z)
  106.  
  107. extern LPVOID pinstX;
  108. #define PvGetInstanceGlobals()                  pinstX
  109. #define ScSetInstanceGlobals(_pv)               (pinstX = _pv, 0)
  110. #define PvGetVerifyInstanceGlobals(_pid)        pinstX
  111. #define ScSetVerifyInstanceGlobals(_pv,_pid)    (pinstX = _pv, 0)
  112. #define PvSlowGetInstanceGlobals(_pid)          pinstX
  113.  
  114. #endif  /* WIN16 */
  115.  
  116. #if defined(_WIN32) && !defined(_MAC)
  117. #define szMAPIDLLSuffix     "32"
  118. #elif defined(WIN16) || defined(DOS)
  119. #define szMAPIDLLSuffix     ""
  120. #elif  defined(_MAC)
  121. #define szMAPIDLLSuffix     "M"
  122. #else
  123. #error "Don't know the suffix for DLLs on this platform"
  124. #endif
  125.  
  126. /********************************/
  127. /*  Things missing from one     */
  128. /*  system-provided environment */
  129. /*  or the other.               */
  130. /********************************/
  131.  
  132. #if !defined(_WIN32) 
  133. #define ZeroMemory(pb,cb)           memset((pb),0,(cb))
  134. #define FillMemory(pb,cb,b)         memset((pb),(b),(cb))
  135. #define CopyMemory(pbDst,pbSrc,cb)  do                              \
  136.                                     {                               \
  137.                                         size_t _cb = (size_t)(cb);  \
  138.                                         if (_cb)                    \
  139.                                             memcpy(pbDst,pbSrc,_cb);\
  140.                                     } while (FALSE)
  141. #define MoveMemory(pbDst,pbSrc,cb)  memmove((pbDst),(pbSrc),(cb))
  142.  
  143. #define UNALIGNED
  144.  
  145. #endif
  146.  
  147. #if defined(WIN16) || defined(_MAC)
  148.  
  149. #ifndef _MAC
  150. #include <error.h>              /*  for GetLastError() */
  151. #endif
  152.  
  153. typedef int                 INT;
  154. typedef unsigned long       ULONG;
  155. typedef short               SHORT;
  156. typedef unsigned short      USHORT;
  157. typedef double              LONGLONG;
  158. typedef double              DWORDLONG;
  159. typedef unsigned char       UCHAR;
  160. typedef unsigned char FAR*  PUCHAR;
  161. typedef int                 BOOL;
  162.  
  163.  
  164. #ifndef _MAC
  165. typedef char                BOOLEAN;
  166.  
  167. #ifndef _FILETIME_
  168. #define _FILETIME_
  169. typedef struct tagFILETIME
  170. {
  171.     DWORD dwLowDateTime;
  172.     DWORD dwHighDateTime;
  173. } FILETIME;
  174. #endif      /* _FILETIME */
  175.  
  176. typedef struct _SYSTEMTIME {
  177.     WORD wYear;
  178.     WORD wMonth;
  179.     WORD wDayOfWeek;
  180.     WORD wDay;
  181.     WORD wHour;
  182.     WORD wMinute;
  183.     WORD wSecond;
  184.     WORD wMilliseconds;
  185. } SYSTEMTIME, *PSYSTEMTIME, FAR *LPSYSTEMTIME;
  186.  
  187. typedef struct _TIME_ZONE_INFORMATION {
  188.     LONG Bias;
  189.     CHAR StandardName[ 32 ];        /* was WCHAR */
  190.     SYSTEMTIME StandardDate;
  191.     LONG StandardBias;
  192.     CHAR DaylightName[ 32 ];        /* was WCHAR */
  193.     SYSTEMTIME DaylightDate;
  194.     LONG DaylightBias;
  195. } TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION, FAR *LPTIME_ZONE_INFORMATION;
  196.  
  197.  
  198. #if defined(DOS) || defined(WIN16)
  199. /* Simulate effect of afx header */
  200. #define __T(x)      x
  201. #define _T(x)       __T(x)
  202. #define TEXT        _T
  203. #endif
  204.  
  205. #define APIENTRY        WINAPI
  206.  
  207. #define SetForegroundWindow         SetActiveWindow
  208.  
  209. #define wsprintfA                   wsprintf
  210. #define GetWindowsDirectoryA        GetWindowsDirectory
  211. #define GetSystemDirectoryA         GetSystemDirectory
  212. #define GetPrivateProfileStringA    GetPrivateProfileString
  213. #define GetPrivateProfileIntA       GetPrivateProfileInt
  214. #define GetProfileStringA           GetProfileString
  215. #define GetModuleFileNameA          GetModuleFileName
  216. #define CharUpperBuffA              CharUpperBuff
  217. #define LoadLibraryA                LoadLibrary
  218. #define lstrcatA                    lstrcat
  219. #define RegisterWindowMessageA      RegisterWindowMessage
  220. #define MAKEINTRESOURCEA            MAKEINTRESOURCE
  221.  
  222. #define WNDCLASSA                   WNDCLASS                                    
  223.  
  224. #endif  /* !_MAC */
  225.  
  226. /* Synchronization */
  227. #define InterlockedIncrement(plong) (++(*(plong)))
  228. #define InterlockedDecrement(plong) (--(*(plong)))
  229.  
  230. #ifndef CreateMutex
  231. #define CreateMutexA    CreateMutex
  232. #define CreateMutexW    CreateMutex
  233. #define CreateMutex(pv, bool, sz)   (INVALID_HANDLE_VALUE)
  234. #endif
  235.  
  236. #define WaitForSingleObject(hObj, dw)   ((void)0)
  237. #define ReleaseMutex(hObj)              ((BOOL)1)
  238. #define CloseMutexHandle(hObj)          TRUE
  239.  
  240. #define CRITICAL_SECTION            ULONG
  241. #define InitializeCriticalSection(_pcs) ((void)0)
  242. #define DeleteCriticalSection(_pcs)     ((void)0)
  243. #define EnterCriticalSection(_pcs)      ((void)0)
  244. #define LeaveCriticalSection(_pcs)      ((void)0)
  245.  
  246. #define MAX_PATH                    260
  247.  
  248. #ifndef _MAC
  249. /*
  250.  *  File Access Modes
  251.  *
  252.  *  The possible combination of file access modes as passed into
  253.  *  the CreateFile() api map to OpenFile() as follows:
  254.  *
  255.  *   GENERIC_READ                       OPEN_ACCESS_READONLY
  256.  *   GENERIC_WRITE                      OPEN_ACCESS_WRITEONLY
  257.  *   GENERIC_READ | GENERIC_WRITE       OPEN_ACCESS_READWRITE
  258.  *
  259.  *   0                                  OPEN_SHARE_DENYREADWRITE
  260.  *   FILE_SHARE_READ                    OPEN_SHARE_DENYWRITE
  261.  *   FILE_SHARE_WRITE                   OPEN_SHARE_DENYREAD
  262.  *   FILE_SHARE_READ | FILE_SHARE_WRITE OPEN_SHARE_DENYNONE
  263.  *
  264.  *  Due to the mappings we cannot pass them through directly,
  265.  *  so we will have to use a conversion within APIs that test
  266.  *  these bits.  It would be best to use the Win32 #defines
  267.  *  for these flags and convert as needed in the APIs.
  268.  */
  269. #define GENERIC_READ                (0x80000000) /* from WINNT.H */
  270. #define GENERIC_WRITE               (0x40000000) /* from WINNT.H */
  271. #define FILE_SHARE_READ             (0x00000001) /* from WINNT.H */
  272. #define FILE_SHARE_WRITE            (0x00000002) /* from WINNT.H */
  273. #endif  /* _MAC */
  274.  
  275. #define FILE_FLAG_SEQUENTIAL_SCAN   0x08000000
  276.  
  277. #define CREATE_NEW          1
  278. #define CREATE_ALWAYS       2
  279. #define OPEN_EXISTING       3
  280. #define OPEN_ALWAYS         4
  281. #define TRUNCATE_EXISTING   5
  282.  
  283. #ifndef _MAC
  284. #define INVALID_HANDLE_VALUE        ((HANDLE)(-1))
  285. #define DELETE                      0x00010000L
  286.  
  287. #define FILE_BEGIN                  0
  288. #define FILE_CURRENT                1
  289. #define FILE_END                    2
  290. #endif
  291.  
  292. #define FILE_ATTRIBUTE_READONLY         0x00000001
  293. #define FILE_ATTRIBUTE_HIDDEN           0x00000002
  294. #define FILE_ATTRIBUTE_SYSTEM           0x00000004
  295. #define FILE_ATTRIBUTE_DIRECTORY        0x00000010
  296. #define FILE_ATTRIBUTE_ARCHIVE          0x00000020
  297. #define FILE_ATTRIBUTE_NORMAL           0x00000080
  298. #define FILE_ATTRIBUTE_TEMPORARY        0x00000100
  299.  
  300. #define FILE_FLAG_WRITE_THROUGH     0x80000000
  301. #define FILE_FLAG_RANDOM_ACCESS     0x10000000
  302.  
  303. #ifndef _MAC
  304. typedef struct _WIN32_FIND_DATA {
  305.     DWORD       dwFileAttributes;
  306.     FILETIME    ftCreationTime;
  307.     FILETIME    ftLastAccessTime;
  308.     FILETIME    ftLastWriteTime;
  309.     DWORD       nFileSizeHigh;
  310.     DWORD       nFileSizeLow;
  311.     DWORD       dwReserved0;
  312.     DWORD       dwReserved1;
  313.     CHAR        cFileName[ MAX_PATH ];
  314.     CHAR        cAlternateFileName[ 16 ];
  315. } WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA;
  316.  
  317. #define TIME_ZONE_ID_INVALID        0xFFFFFFFF
  318. #endif
  319. #define TIME_ZONE_ID_UNKNOWN        0
  320. #define TIME_ZONE_ID_STANDARD       1
  321. #define TIME_ZONE_ID_DAYLIGHT       2
  322.  
  323.  
  324.  
  325. DWORD WINAPI    GetLastError(void);
  326. DWORD WINAPI    GetFileAttributes(LPCSTR lpFileName);
  327. DWORD WINAPI    GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
  328. BOOL WINAPI     GetFileTime(HANDLE hFile, FILETIME FAR *lpftCreation,
  329.                 FILETIME FAR *lpftLastAccess, FILETIME FAR *lpftLastWrite);
  330. BOOL WINAPI     SetFileTime(HANDLE hFile, const FILETIME FAR *lpftCreation,
  331.                 const FILETIME FAR *lpftLastAccess,
  332.                 const FILETIME FAR *lpftLastWrite);
  333. #ifndef _MAC
  334. /*  IsTask can crash - here's a safer one.  */
  335. BOOL WINAPI     FIsTask(HTASK hTask);
  336.  
  337. HANDLE WINAPI   CreateFile(LPCSTR lpFileName, DWORD dwDesiredAccess,
  338.                 DWORD dwShareMode, LPVOID lpSecurityAttributes,
  339.                 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
  340.                 HANDLE hTemplateFile);
  341. BOOL WINAPI     ReadFile(HANDLE hFile, LPVOID lpBuffer,
  342.                 DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
  343.                 LPVOID lpOverlapped);
  344. BOOL WINAPI     WriteFile(HANDLE hFile, LPCVOID lpBuffer,
  345.                 DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten,
  346.                 LPVOID lpOverlapped);
  347. #endif
  348. DWORD WINAPI    SetFilePointer(HANDLE hFile, LONG lDistanceToMove,
  349.                 LONG FAR *lpDistanceToMoveHigh, DWORD dwMoveMethod);
  350. BOOL WINAPI     SetEndOfFile(HANDLE hFile);
  351. BOOL WINAPI     CloseHandle(HANDLE hObject);
  352. DWORD WINAPI    GetTempPath(DWORD nBufferLength, LPSTR lpBuffer);
  353. UINT WINAPI     GetTempFileName32 (LPCSTR lpPathName, LPCSTR lpPrefixString,
  354.                 UINT uUnique, LPSTR lpTempFileName);
  355. BOOL WINAPI     DeleteFile(LPCSTR lpFileName);
  356. #ifndef _MAC
  357. BOOL WINAPI     CreateDirectory(LPCSTR lpPathName, LPVOID lpSecurityAttributes);
  358. #endif
  359. BOOL WINAPI     RemoveDirectory(LPCSTR lpPathName);
  360. BOOL WINAPI     CopyFile(LPCSTR szSrc, LPCSTR szDst, BOOL fFailIfExists);
  361. BOOL WINAPI     MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
  362. HANDLE WINAPI   FindFirstFile(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);
  363. BOOL WINAPI     FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData);
  364. BOOL WINAPI     FindClose(HANDLE hFindFile);
  365. DWORD WINAPI    GetFullPathName(LPCSTR lpFileName, DWORD nBufferLength,
  366.                 LPSTR lpBuffer, LPSTR *lpFilePart);
  367. void WINAPI     Sleep(DWORD dwMilliseconds);
  368. LONG WINAPI     CompareFileTime(const FILETIME FAR *, const FILETIME FAR *);
  369. BOOL WINAPI     LocalFileTimeToFileTime(const FILETIME FAR *, FILETIME FAR *);
  370. BOOL WINAPI     FileTimeToLocalFileTime(const FILETIME FAR *, FILETIME FAR *);
  371. BOOL WINAPI     FileTimeToSystemTime(const FILETIME FAR *, SYSTEMTIME FAR *);
  372. BOOL WINAPI     SystemTimeToFileTime(const SYSTEMTIME FAR *, FILETIME FAR *);
  373. void WINAPI     GetSystemTime(SYSTEMTIME FAR *);
  374. void WINAPI     GetLocalTime(SYSTEMTIME FAR *);
  375. BOOL WINAPI     FileTimeToDosDateTime(const FILETIME FAR * lpFileTime,
  376.                 WORD FAR *lpFatDate, WORD FAR *lpFatTime);
  377. BOOL WINAPI     DosDateTimeToFileTime(WORD wFatDate, WORD wFatTime,
  378.                 FILETIME FAR * lpFileTime);
  379. DWORD WINAPI    GetTimeZoneInformation(
  380.                 LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
  381. BOOL WINAPI     SetTimeZoneInformation(
  382.                 const TIME_ZONE_INFORMATION FAR *lpTimeZoneInformation);
  383.  
  384. DWORD WINAPI    GetCurrentProcessId(void);
  385. long WINAPI     MulDiv32(long, long, long);
  386. #ifndef _MAC
  387. BOOL WINAPI     FBadReadPtr(const void FAR* lp, UINT cb);
  388. #endif
  389.  
  390. #else   /* !WIN16 */
  391.  
  392. /* Remaps GetTempFileName32() to the real 32bit version */
  393.  
  394. #define GetTempFileName32(_szPath,_szPfx,_n,_lpbuf) GetTempFileName(_szPath,_szPfx,_n,_lpbuf)
  395.  
  396. #define CloseMutexHandle    CloseHandle
  397.  
  398. #endif  /* !WIN16 */
  399.  
  400.  
  401. #ifdef _MAC
  402. #define CRITICAL_SECTION            ULONG
  403. #define InitializeCriticalSection(_pcs) ((void)0)
  404. #define DeleteCriticalSection(_pcs)     ((void)0)
  405. #define EnterCriticalSection(_pcs)      ((void)0)
  406. #define LeaveCriticalSection(_pcs)      ((void)0)
  407. #endif
  408.  
  409. /********************************/
  410. /*  Our private conventions     */
  411. /*  (common to WIN16/WIN32)     */
  412. /********************************/
  413.  
  414. #define Cbtszsize(_a)   ((lstrlen(_a)+1)*sizeof(TCHAR))
  415. #define CbtszsizeA(_a)  ((lstrlenA(_a) + 1))
  416. #define CbtszsizeW(_a)  ((lstrlenW(_a) + 1) * sizeof(WCHAR))
  417. #define HexCchOf(_s)    (sizeof(_s)*2+1)
  418. #define HexSizeOf(_s)   (HexCchOf(_s)*sizeof(TCHAR))
  419.  
  420. BOOL WINAPI IsBadBoundedStringPtr(const void FAR* lpsz, UINT cchMax);
  421.  
  422. /* FUTURE - obsolete. OLE2 no longer contains these */
  423. #define GetSCode                    GetScode
  424. #define ReportResult(_a,_b,_c,_d)   ResultFromScode(_b)
  425.  
  426. #ifdef __cplusplus
  427. }
  428. #endif
  429.  
  430. #endif /* __MAPIWIN_H__ */
  431.