home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Source / Rtl / Win / MAPI.PAS < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  23KB  |  595 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Runtime Library                  }
  5. {       Simple MAPI Interface Unit                      }
  6. {                                                       }
  7. {       Copyright (C) 1996,99 Inprise Corporation       }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit Mapi;
  12.  
  13. {NOTE: Do not place the $NOPACKAGEUNIT directive in this file}
  14.  
  15. interface
  16.  
  17. uses Windows;
  18.  
  19. {
  20.   Messaging Applications Programming Interface.
  21.  
  22.   Purpose:
  23.  
  24.     This file defines the structures and constants used by that
  25.     subset of the Messaging Applications Programming Interface
  26.     which is supported under Windows by Microsoft Mail for PC
  27.     Networks version 3.x.
  28. }
  29.  
  30. (*$HPPEMIT '#include <mapi.h>'*)
  31.  
  32. type
  33.   {$EXTERNALSYM FLAGS}
  34.   FLAGS = Cardinal;
  35.   {$EXTERNALSYM LHANDLE}
  36.   LHANDLE = Cardinal;
  37.   PLHANDLE = ^Cardinal;
  38.  
  39. const
  40.   {$EXTERNALSYM lhSessionNull}
  41.   lhSessionNull = (0);
  42.  
  43. type
  44.   PMapiFileDesc = ^TMapiFileDesc;
  45.   {$EXTERNALSYM MapiFileDesc}
  46.   MapiFileDesc = packed record
  47.     ulReserved: Cardinal;        { Reserved for future use (must be 0)     }
  48.     flFlags: Cardinal;           { Flags                                   }
  49.     nPosition: Cardinal;         { character in text to be replaced by attachment }
  50.     lpszPathName: LPSTR;         { Full path name of attachment file       }
  51.     lpszFileName: LPSTR;         { Original file name (optional)           }
  52.     lpFileType: Pointer;         { Attachment file type (can be lpMapiFileTagExt) }
  53.   end;
  54.   TMapiFileDesc = MapiFileDesc;
  55.  
  56. const
  57.   {$EXTERNALSYM MAPI_OLE}
  58.   MAPI_OLE = $00000001;
  59.   {$EXTERNALSYM MAPI_OLE_STATIC}
  60.   MAPI_OLE_STATIC = $00000002;
  61.  
  62.  
  63. type
  64.   PMapiFileTagExt = ^TMapiFileTagExt;
  65.   {$EXTERNALSYM MapiFileTagExt}
  66.   MapiFileTagExt = packed record
  67.     ulReserved: Cardinal;       { Reserved, must be zero.                  }
  68.     cbTag: Cardinal;            { Size (in bytes) of                       }
  69.     lpTag: PByte;               { X.400 OID for this attachment type       }
  70.     cbEncoding: Cardinal;       { Size (in bytes) of                       }
  71.     lpEncoding: PByte;          { X.400 OID for this attachment's encoding }
  72.   end;
  73.   TMapiFileTagExt = MapiFileTagExt;
  74.  
  75.  
  76.   PMapiRecipDesc = ^TMapiRecipDesc;
  77.   {$EXTERNALSYM MapiRecipDesc}
  78.   MapiRecipDesc = packed record
  79.     ulReserved: Cardinal;       { Reserved for future use                  }
  80.     ulRecipClass: Cardinal;     { Recipient class                          }
  81.                                 { MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG    }
  82.     lpszName: LPSTR;            { Recipient name                           }
  83.     lpszAddress: LPSTR;         { Recipient address (optional)             }
  84.     ulEIDSize: Cardinal;        { Count in bytes of size of pEntryID       }
  85.     lpEntryID: Pointer;         { System-specific recipient reference      }
  86.   end;
  87.   TMapiRecipDesc = MapiRecipDesc;
  88.  
  89. const
  90.   {$EXTERNALSYM MAPI_ORIG}
  91.   MAPI_ORIG = 0;                { Recipient is message originator          }
  92.   {$EXTERNALSYM MAPI_TO}
  93.   MAPI_TO = 1;                  { Recipient is a primary recipient         }
  94.   {$EXTERNALSYM MAPI_CC}
  95.   MAPI_CC = 2;                  { Recipient is a copy recipient            }
  96.   {$EXTERNALSYM MAPI_BCC}
  97.   MAPI_BCC = 3;                 { Recipient is blind copy recipient        }
  98.  
  99. type
  100.   PMapiMessage = ^TMapiMessage;
  101.   {$EXTERNALSYM MapiMessage}
  102.   MapiMessage = packed record
  103.     ulReserved: Cardinal;         { Reserved for future use (M.B. 0)       }
  104.     lpszSubject: LPSTR;           { Message Subject                        }
  105.     lpszNoteText: LPSTR;          { Message Text                           }
  106.     lpszMessageType: LPSTR;       { Message Class                          }
  107.     lpszDateReceived: LPSTR;      { in YYYY/MM/DD HH:MM format             }
  108.     lpszConversationID: LPSTR;    { conversation thread ID                 }
  109.     flFlags: FLAGS;               { unread,return receipt                  }
  110.     lpOriginator: PMapiRecipDesc; { Originator descriptor                  }
  111.     nRecipCount: Cardinal;        { Number of recipients                   }
  112.     lpRecips: PMapiRecipDesc;     { Recipient descriptors                  }
  113.     nFileCount: Cardinal;         { # of file attachments                  }
  114.     lpFiles: PMapiFileDesc;       { Attachment descriptors                 }
  115.   end;
  116.   TMapiMessage = MapiMessage;
  117.  
  118. const
  119.   {$EXTERNALSYM MAPI_UNREAD}
  120.   MAPI_UNREAD = $00000001;
  121.   {$EXTERNALSYM MAPI_RECEIPT_REQUESTED}
  122.   MAPI_RECEIPT_REQUESTED = $00000002;
  123.   {$EXTERNALSYM MAPI_SENT}
  124.   MAPI_SENT = $00000004;
  125.  
  126.  
  127. { Entry points. }
  128.  
  129. { flFlags values for Simple MAPI entry points. All documented flags are
  130.   shown for each call. Duplicates are commented out but remain present
  131.   for every call. }
  132.  
  133. { MAPILogon() flags. }
  134.  
  135.   {$EXTERNALSYM MAPI_LOGON_UI}
  136.   MAPI_LOGON_UI = $00000001;                { Display logon UI             }
  137.   {$EXTERNALSYM MAPI_PASSWORD_UI}
  138.   MAPI_PASSWORD_UI = $00020000;             { prompt for password only     }
  139.   {$EXTERNALSYM MAPI_NEW_SESSION}
  140.   MAPI_NEW_SESSION = $00000002;             { Don't use shared session     }
  141.   {$EXTERNALSYM MAPI_FORCE_DOWNLOAD}
  142.   MAPI_FORCE_DOWNLOAD = $00001000;          { Get new mail before return   }
  143.   {$EXTERNALSYM MAPI_ALLOW_OTHERS}
  144.   MAPI_ALLOW_OTHERS = $00000008;            { Make this a shared session   (removed from 4.0 SDK) }
  145.   {$EXTERNALSYM MAPI_EXPLICIT_PROFILE}
  146.   MAPI_EXPLICIT_PROFILE = $00000010;        { Don't use default profile    (removed from 4.0 SDK) }
  147.   {$EXTERNALSYM MAPI_EXTENDED}
  148.   MAPI_EXTENDED = $00000020;                { Extended MAPI Logon          }
  149.   {$EXTERNALSYM MAPI_USE_DEFAULT}
  150.   MAPI_USE_DEFAULT = $00000040;             { Use default profile in logon (removed from 4.0 SDK) }
  151.  
  152.   {$EXTERNALSYM MAPI_SIMPLE_DEFAULT}
  153.   MAPI_SIMPLE_DEFAULT = MAPI_LOGON_UI or MAPI_FORCE_DOWNLOAD or MAPI_ALLOW_OTHERS; { removed from 4.0 SDK }
  154.   {$EXTERNALSYM MAPI_SIMPLE_EXPLICIT}
  155.   MAPI_SIMPLE_EXPLICIT = MAPI_NEW_SESSION or MAPI_FORCE_DOWNLOAD or MAPI_EXPLICIT_PROFILE; { removed from 4.0 SDK }
  156.  
  157. { MAPILogoff() flags.      }
  158.  
  159.   {$EXTERNALSYM MAPI_LOGOFF_SHARED}
  160.   MAPI_LOGOFF_SHARED = $00000001;           { Close all shared sessions  (removed from 4.0 SDK)  }
  161.   {$EXTERNALSYM MAPI_LOGOFF_UI}
  162.   MAPI_LOGOFF_UI = $00000002;               { It's OK to present UI      (removed from 4.0 SDK)  }
  163.  
  164. { MAPISendMail() flags.    }
  165.  
  166. { #define MAPI_LOGON_UI        0x00000001     Display logon UI             }
  167. { #define MAPI_NEW_SESSION     0x00000002     Don't use shared session     }
  168.   {$EXTERNALSYM MAPI_DIALOG}
  169.   MAPI_DIALOG = $00000008;                  { Display a send note UI       }
  170. { # define MAPI_USE_DEFAULT     0x00000040     Use default profile in logon }
  171.  
  172. { MAPIFindNext() flags.    }
  173.  
  174.   {$EXTERNALSYM MAPI_UNREAD_ONLY}
  175.   MAPI_UNREAD_ONLY = $00000020;             { Only unread messages         }
  176.   {$EXTERNALSYM MAPI_GUARANTEE_FIFO}
  177.   MAPI_GUARANTEE_FIFO = $00000100;          { use date order               }
  178.   {$EXTERNALSYM MAPI_LONG_MSGID}
  179.   MAPI_LONG_MSGID = $00004000;              { allow 512 char returned ID   }
  180.  
  181. { MAPIReadMail() flags.    }
  182.  
  183.   {$EXTERNALSYM MAPI_PEEK}
  184.   MAPI_PEEK = $00000080;                    { Do not mark as read.         }
  185.   {$EXTERNALSYM MAPI_SUPPRESS_ATTACH}
  186.   MAPI_SUPPRESS_ATTACH = $00000800;         { header + body, no files      }
  187.   {$EXTERNALSYM MAPI_ENVELOPE_ONLY}
  188.   MAPI_ENVELOPE_ONLY = $00000040;           { Only header information      }
  189.   {$EXTERNALSYM MAPI_BODY_AS_FILE}
  190.   MAPI_BODY_AS_FILE = $00000200;
  191.  
  192. { MAPISaveMail() flags.    }
  193.  
  194. { #define MAPI_LOGON_UI        0x00000001     Display logon UI             }
  195. { #define MAPI_NEW_SESSION     0x00000002     Don't use shared session     }
  196. { #define MAPI_LONG_MSGID      0x00004000  /* allow 512 char returned ID   }
  197.  
  198. { MAPIAddress() flags.     }
  199.  
  200. { #define MAPI_LOGON_UI        0x00000001     Display logon UI             }
  201. { #define MAPI_NEW_SESSION     0x00000002     Don't use shared session     }
  202.  
  203. { MAPIDetails() flags.     }
  204.  
  205. { #define MAPI_LOGON_UI        0x00000001     Display logon UI             }
  206. { #define MAPI_NEW_SESSION     0x00000002     Don't use shared session     }
  207.   {$EXTERNALSYM MAPI_AB_NOMODIFY}
  208.   MAPI_AB_NOMODIFY = $00000400;             { Don't allow mods of AB entries }
  209.  
  210. { MAPIResolveName() flags. }
  211.  
  212. { #define MAPI_LOGON_UI        0x00000001     Display logon UI             }
  213. { #define MAPI_NEW_SESSION     0x00000002     Don't use shared session     }
  214. { #define MAPI_DIALOG          0x00000008     Prompt for choices if ambiguous }
  215. { #define MAPI_AB_NOMODIFY     0x00000400     Don't allow mods of AB entries }
  216.  
  217. type
  218.   PFNMapiLogon = ^TFNMapiLogOn;
  219.   TFNMapiLogOn = function(ulUIParam: Cardinal; lpszProfileName: LPSTR;
  220.     lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  221.     lplhSession: PLHANDLE): Cardinal stdcall;
  222.  
  223.   PFNMapiLogOff = ^TFNMapiLogOff;
  224.   TFNMapiLogOff = function(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS;
  225.     ulReserved: Cardinal): Cardinal stdcall;
  226.  
  227.   PFNMapiSendMail = ^TFNMapiSendMail;
  228.   TFNMapiSendMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  229.     var lpMessage: TMapiMessage; flFlags: FLAGS;
  230.     ulReserved: Cardinal): Cardinal stdcall;
  231.  
  232.   PFNMapiSendDocuments = ^TFNMapiSendDocuments;
  233.   TFNMapiSendDocuments = function(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
  234.     lpszFilePaths: LPSTR; lpszFileNames: LPSTR;
  235.     ulReserved: Cardinal): Cardinal stdcall;
  236.  
  237.   PFNMapiFindNext = ^TFNMapiFindNext;
  238.   TFNMapiFindNext = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  239.     lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
  240.     ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal stdcall;
  241.  
  242.   PFNMapiReadMail = ^TFNMapiReadMail;
  243.   TFNMapiReadMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  244.     lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  245.     var lppMessage: PMapiMessage): Cardinal stdcall;
  246.  
  247.   PFNMapiSaveMail = ^TFNMapiSaveMail;
  248.   TFNMapiSaveMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  249.     var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
  250.     lpszMessageID: LPSTR): Cardinal stdcall;
  251.  
  252.   PFNMapiDeleteMail = ^TFNMapiDeleteMail;
  253.   TFNMapiDeleteMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  254.     lpszMessageID: LPSTR; flFlags: FLAGS;
  255.     ulReserved: Cardinal): Cardinal stdcall;
  256.  
  257.   PFNMapiFreeBuffer = ^TFNMapiFreeBuffer;
  258.   TFNMapiFreeBuffer = function(pv: Pointer): Cardinal stdcall;
  259.  
  260.   PFNMapiAddress = ^TFNMapiAddress;
  261.   TFNMapiAddress = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  262.     lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
  263.     nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
  264.     ulReserved: Cardinal; lpnNewRecips: PULONG;
  265.     var lppNewRecips: PMapiRecipDesc): Cardinal stdcall;
  266.  
  267.   PFNMapiDetails = ^TFNMapiDetails;
  268.   TFNMapiDetails = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  269.     var lpRecip: TMapiRecipDesc; flFlags: FLAGS;
  270.     ulReserved: Cardinal): Cardinal stdcall;
  271.  
  272.   PFNMapiResolveName = ^TFNMapiResolveName;
  273.   TFNMapiResolveName = function(lhSession: LHANDLE; ulUIParam: Cardinal;
  274.     lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  275.     var lppRecip: PMapiRecipDesc): Cardinal stdcall;
  276.  
  277. const
  278.   {$EXTERNALSYM SUCCESS_SUCCESS}
  279.   SUCCESS_SUCCESS = 0;
  280.   {$EXTERNALSYM MAPI_USER_ABORT}
  281.   MAPI_USER_ABORT = 1;
  282.   {$EXTERNALSYM MAPI_E_USER_ABORT}
  283.   MAPI_E_USER_ABORT                  = MAPI_USER_ABORT;
  284.   {$EXTERNALSYM MAPI_E_FAILURE}
  285.   MAPI_E_FAILURE = 2;
  286.   {$EXTERNALSYM MAPI_E_LOGON_FAILURE}
  287.   MAPI_E_LOGON_FAILURE = 3;
  288.   {$EXTERNALSYM MAPI_E_LOGIN_FAILURE}
  289.   MAPI_E_LOGIN_FAILURE               = MAPI_E_LOGON_FAILURE;
  290.   {$EXTERNALSYM MAPI_E_DISK_FULL}
  291.   MAPI_E_DISK_FULL = 4;
  292.   {$EXTERNALSYM MAPI_E_INSUFFICIENT_MEMORY}
  293.   MAPI_E_INSUFFICIENT_MEMORY = 5;
  294.   {$EXTERNALSYM MAPI_E_ACCESS_DENIED}
  295.   MAPI_E_ACCESS_DENIED = 6;
  296.   {$EXTERNALSYM MAPI_E_TOO_MANY_SESSIONS}
  297.   MAPI_E_TOO_MANY_SESSIONS = 8;
  298.   {$EXTERNALSYM MAPI_E_TOO_MANY_FILES}
  299.   MAPI_E_TOO_MANY_FILES = 9;
  300.   {$EXTERNALSYM MAPI_E_TOO_MANY_RECIPIENTS}
  301.   MAPI_E_TOO_MANY_RECIPIENTS = 10;
  302.   {$EXTERNALSYM MAPI_E_ATTACHMENT_NOT_FOUND}
  303.   MAPI_E_ATTACHMENT_NOT_FOUND = 11;
  304.   {$EXTERNALSYM MAPI_E_ATTACHMENT_OPEN_FAILURE}
  305.   MAPI_E_ATTACHMENT_OPEN_FAILURE = 12;
  306.   {$EXTERNALSYM MAPI_E_ATTACHMENT_WRITE_FAILURE}
  307.   MAPI_E_ATTACHMENT_WRITE_FAILURE = 13;
  308.   {$EXTERNALSYM MAPI_E_UNKNOWN_RECIPIENT}
  309.   MAPI_E_UNKNOWN_RECIPIENT = 14;
  310.   {$EXTERNALSYM MAPI_E_BAD_RECIPTYPE}
  311.   MAPI_E_BAD_RECIPTYPE = 15;
  312.   {$EXTERNALSYM MAPI_E_NO_MESSAGES}
  313.   MAPI_E_NO_MESSAGES = 16;
  314.   {$EXTERNALSYM MAPI_E_INVALID_MESSAGE}
  315.   MAPI_E_INVALID_MESSAGE = 17;
  316.   {$EXTERNALSYM MAPI_E_TEXT_TOO_LARGE}
  317.   MAPI_E_TEXT_TOO_LARGE = 18;
  318.   {$EXTERNALSYM MAPI_E_INVALID_SESSION}
  319.   MAPI_E_INVALID_SESSION = 19;
  320.   {$EXTERNALSYM MAPI_E_TYPE_NOT_SUPPORTED}
  321.   MAPI_E_TYPE_NOT_SUPPORTED = 20;
  322.   {$EXTERNALSYM MAPI_E_AMBIGUOUS_RECIPIENT}
  323.   MAPI_E_AMBIGUOUS_RECIPIENT = 21;
  324.   {$EXTERNALSYM MAPI_E_AMBIG_RECIP}
  325.   MAPI_E_AMBIG_RECIP                 = MAPI_E_AMBIGUOUS_RECIPIENT;
  326.   {$EXTERNALSYM MAPI_E_MESSAGE_IN_USE}
  327.   MAPI_E_MESSAGE_IN_USE = 22;
  328.   {$EXTERNALSYM MAPI_E_NETWORK_FAILURE}
  329.   MAPI_E_NETWORK_FAILURE = 23;
  330.   {$EXTERNALSYM MAPI_E_INVALID_EDITFIELDS}
  331.   MAPI_E_INVALID_EDITFIELDS = 24;
  332.   {$EXTERNALSYM MAPI_E_INVALID_RECIPS}
  333.   MAPI_E_INVALID_RECIPS = 25;
  334.   {$EXTERNALSYM MAPI_E_NOT_SUPPORTED}
  335.   MAPI_E_NOT_SUPPORTED = 26;
  336.  
  337.  
  338. { Delphi wrapper calls around Simple MAPI }
  339.  
  340. function MapiLogOn(ulUIParam: Cardinal; lpszProfileName: LPSTR;
  341.   lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  342.   lplhSession: PLHANDLE): Cardinal;
  343.  
  344. function MapiLogOff(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS;
  345.   ulReserved: Cardinal): Cardinal;
  346.  
  347. function MapiSendMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  348.   var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal): Cardinal;
  349.  
  350. function MapiSendDocuments(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
  351.   lpszFilePaths: LPSTR; lpszFileNames: LPSTR; ulReserved: Cardinal): Cardinal;
  352.  
  353. function MapiFindNext(lhSession: LHANDLE; ulUIParam: Cardinal;
  354.   lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
  355.   ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal;
  356.  
  357. function MapiReadMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  358.   lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  359.   var lppMessage: PMapiMessage): Cardinal;
  360.  
  361. function MapiSaveMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  362.   var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
  363.   lpszMessageID: LPSTR): Cardinal;
  364.  
  365. function MapiDeleteMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  366.   lpszMessageID: LPSTR; flFlags: FLAGS;
  367.   ulReserved: Cardinal): Cardinal;
  368.  
  369. function MapiFreeBuffer(pv: Pointer): Cardinal;
  370.  
  371. function MapiAddress(lhSession: LHANDLE; ulUIParam: Cardinal;
  372.   lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
  373.   nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
  374.   ulReserved: Cardinal; lpnNewRecips: PULONG;
  375.   var lppNewRecips: PMapiRecipDesc): Cardinal;
  376.  
  377. function MapiDetails(lhSession: LHANDLE; ulUIParam: Cardinal;
  378.   var lpRecip: TMapiRecipDesc; flFlags: FLAGS;
  379.   ulReserved: Cardinal): Cardinal;
  380.  
  381. function MapiResolveName(lhSession: LHANDLE; ulUIParam: Cardinal;
  382.   lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  383.   var lppRecip: PMapiRecipDesc): Cardinal;
  384.  
  385. var
  386.   MAPIDLL: string = 'MAPI32.DLL';
  387.  
  388. implementation
  389.  
  390. var
  391.   MAPIModule: HModule = 0;
  392.   LogOn: TFNMapiLogOn = nil;
  393.   LogOff: TFNMapiLogOff = nil;
  394.   SendMail: TFNMapiSendMail = nil;
  395.   SendDocuments: TFNMapiSendDocuments = nil;
  396.   FindNext: TFNMapiFindNext = nil;
  397.   ReadMail: TFNMapiReadMail = nil;
  398.   SaveMail: TFNMapiSaveMail = nil;
  399.   DeleteMail: TFNMapiDeleteMail = nil;
  400.   FreeBuffer: TFNMapiFreeBuffer = nil;
  401.   Address: TFNMapiAddress = nil;
  402.   Details: TFNMapiDetails = nil;
  403.   ResolveName: TFNMapiResolveName = nil;
  404.  
  405. var
  406.   MAPIChecked: Boolean = False;
  407.  
  408. procedure InitMapi;
  409. var
  410.   OSVersionInfo: TOSVersionInfo;
  411.   hkWMS: HKEY;
  412.   MAPIValueSize: Longint;
  413.   MAPIValueBuf: array[0..8] of char;
  414.   rType: Longint;
  415. begin
  416.   if not MAPIChecked then
  417.   begin
  418.     MAPIChecked := True;
  419.     MAPIModule := 0;
  420.  
  421.     OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
  422.     GetVersionEx(OSVersionInfo);
  423.     if (OSVersionInfo.dwMajorVersion > 3) or
  424.       ((OSVersionInfo.dwMajorVersion = 3) and
  425.        (OSVersionInfo.dwMinorVersion > 51)) then
  426.     begin
  427.       MAPIValueSize := sizeof(MAPIValueBuf);
  428.       if RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows Messaging Subsystem',
  429.         0, KEY_READ, hkWMS) <> ERROR_SUCCESS then Exit;
  430.       if RegQueryValueEx(hkWMS, 'MAPI', nil, @rType, @MAPIValueBuf,
  431.         @MAPIValueSize) <> ERROR_SUCCESS then Exit;
  432.       RegCloseKey(hkWMS);
  433.       if not ((MAPIValueBuf[0] = '1') and (MAPIValueBuf[1] = #0)) then Exit;
  434.     end
  435.     else if GetProfileInt('Mail', 'MAPI', 0) = 0 then Exit;
  436.  
  437.     MAPIModule := LoadLibrary(PChar(MAPIDLL));
  438.   end;
  439. end;
  440.  
  441. function MapiLogOn(ulUIParam: Cardinal; lpszProfileName: LPSTR;
  442.   lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  443.   lplhSession: PLHANDLE): Cardinal;
  444. begin
  445.   InitMapi;
  446.   if @LogOn = nil then
  447.     @LogOn := GetProcAddress(MAPIModule, 'MAPILogon');
  448.   if @LogOn <> nil then
  449.     Result := LogOn(ulUIParam, lpszProfileName, lpszPassword, flFlags,
  450.       ulReserved, lplhSession)
  451.   else Result := 1;
  452. end;
  453.  
  454. function MapiLogOff(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS;
  455.   ulReserved: Cardinal): Cardinal;
  456. begin
  457.   InitMapi;
  458.   if @LogOff = nil then
  459.     @LogOff := GetProcAddress(MAPIModule, 'MAPILogoff');
  460.   if @LogOff <> nil then
  461.     Result := LogOff(lhSession, ulUIParam, flFlags, ulReserved)
  462.   else Result := 1;
  463. end;
  464.  
  465. function MapiSendMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  466.   var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal): Cardinal;
  467. begin
  468.   InitMapi;
  469.   if @SendMail = nil then
  470.     @SendMail := GetProcAddress(MAPIModule, 'MAPISendMail');
  471.   if @SendMail <> nil then
  472.     Result := SendMail(lhSession, ulUIParam, lpMessage, flFlags, ulReserved)
  473.   else Result := 1;
  474. end;
  475.  
  476. function MapiSendDocuments(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
  477.   lpszFilePaths: LPSTR; lpszFileNames: LPSTR;
  478.   ulReserved: Cardinal): Cardinal;
  479. begin
  480.   InitMapi;
  481.   if @SendDocuments = nil then
  482.     @SendDocuments := GetProcAddress(MAPIModule, 'MAPISendDocuments');
  483.   if @SendDocuments <> nil then
  484.     Result := SendDocuments(ulUIParam, lpszDelimChar, lpszFilePaths,
  485.       lpszFileNames, ulReserved)
  486.   else Result := 1;
  487. end;
  488.  
  489. function MapiFindNext(lhSession: LHANDLE; ulUIParam: Cardinal;
  490.   lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
  491.   ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal;
  492. begin
  493.   InitMapi;
  494.   if @FindNext = nil then
  495.     @FindNext := GetProcAddress(MAPIModule, 'MAPIFindNext');
  496.   if @FindNext <> nil then
  497.     Result := FindNext(lhSession, ulUIParam, lpszMessageType,
  498.       lpszSeedMessageID, flFlags, ulReserved, lpszMessageID)
  499.   else Result := 1;
  500. end;
  501.  
  502. function MapiReadMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  503.   lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  504.   var lppMessage: PMapiMessage): Cardinal;
  505. begin
  506.   InitMapi;
  507.   if @ReadMail = nil then
  508.     @ReadMail := GetProcAddress(MAPIModule, 'MAPIReadMail');
  509.   if @ReadMail <> nil then
  510.     Result := ReadMail(lhSession, ulUIParam, lpszMessageID, flFlags,
  511.       ulReserved, lppMessage)
  512.   else Result := 1;
  513. end;
  514.  
  515. function MapiSaveMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  516.   var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
  517.   lpszMessageID: LPSTR): Cardinal;
  518. begin
  519.   InitMapi;
  520.   if @SaveMail = nil then
  521.     @SaveMail := GetProcAddress(MAPIModule, 'MAPISaveMail');
  522.   if @SaveMail <> nil then
  523.     Result := SaveMail(lhSession, ulUIParam, lpMessage, flFlags, ulReserved,
  524.       lpszMessageID)
  525.   else Result := 1;
  526. end;
  527.  
  528. function MapiDeleteMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  529.   lpszMessageID: LPSTR; flFlags: FLAGS;
  530.   ulReserved: Cardinal): Cardinal;
  531. begin
  532.   InitMapi;
  533.   if @DeleteMail = nil then
  534.     @DeleteMail := GetProcAddress(MAPIModule, 'MAPIDeleteMail');
  535.   if @DeleteMail <> nil then
  536.     Result := DeleteMail(lhSession, ulUIParam, lpszMessageID, flFlags,
  537.       ulReserved)
  538.   else Result := 1;
  539. end;
  540.  
  541. function MapiFreeBuffer(pv: Pointer): Cardinal;
  542. begin
  543.   InitMapi;
  544.   if @FreeBuffer = nil then
  545.     @FreeBuffer := GetProcAddress(MAPIModule, 'MAPIFreeBuffer');
  546.   if @FreeBuffer <> nil then
  547.     Result := FreeBuffer(pv)
  548.   else Result := 1;
  549. end;
  550.  
  551. function MapiAddress(lhSession: LHANDLE; ulUIParam: Cardinal;
  552.   lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
  553.   nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
  554.   ulReserved: Cardinal; lpnNewRecips: PULONG;
  555.   var lppNewRecips: PMapiRecipDesc): Cardinal;
  556. begin
  557.   InitMapi;
  558.   if @Address = nil then
  559.     @Address := GetProcAddress(MAPIModule, 'MAPIAddress');
  560.   if @Address <> nil then
  561.     Result := Address(lhSession, ulUIParam, lpszCaption, nEditFields,
  562.       lpszLabels, nRecips, lpRecips, flFlags, ulReserved, lpnNewRecips,
  563.       lppNewRecips)
  564.   else Result := 1;
  565. end;
  566.  
  567. function MapiDetails(lhSession: LHANDLE; ulUIParam: Cardinal;
  568.   var lpRecip: TMapiRecipDesc; flFlags: FLAGS; ulReserved: Cardinal): Cardinal;
  569. begin
  570.   InitMapi;
  571.   if @Details = nil then
  572.     @Details := GetProcAddress(MAPIModule, 'MAPIDetails');
  573.   if @Details <> nil then
  574.     Result := Details(lhSession, ulUIParam, lpRecip, flFlags, ulReserved)
  575.   else Result := 1;
  576. end;
  577.  
  578. function MapiResolveName(lhSession: LHANDLE; ulUIParam: Cardinal;
  579.   lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  580.   var lppRecip: PMapiRecipDesc): Cardinal;
  581. begin
  582.   InitMapi;
  583.   if @ResolveName = nil then
  584.     @ResolveName := GetProcAddress(MAPIModule, 'MAPIResolveName');
  585.   if @ResolveName <> nil then
  586.     Result := ResolveName(lhSession, ulUIParam, lpszName, flFlags,
  587.       ulReserved, lppRecip)
  588.   else Result := 1;
  589. end;
  590.  
  591. initialization
  592. finalization
  593.   if MAPIModule <> 0 then FreeLibrary(MAPIModule);
  594. end.
  595.