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