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