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