home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / RUNIMAGE / DELPHI30 / SOURCE / RTL / WIN / MAPI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-03  |  19.5 KB  |  524 lines

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