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