home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / mapivb.bas < prev    next >
BASIC Source File  |  1998-04-25  |  10KB  |  295 lines

  1. '****************************************************************************'
  2. '                                                                            '
  3. ' Visual Basic declaration for the MAPI functions.                           '
  4. ' This file can be loaded into the global module.                            '
  5. '                                                                            '                                                                           '
  6. '****************************************************************************'
  7.  
  8.  
  9. '***************************************************
  10. '   MAPI Message holds information about a message
  11. '***************************************************
  12.  
  13. Type MapiMessage
  14.     Reserved As Long
  15.     Subject As String
  16.     NoteText As String
  17.     MessageType As String
  18.     DateReceived As String
  19.     ConversationID As String
  20.     Flags As Long
  21.     RecipCount As Long
  22.     FileCount As Long
  23. End Type
  24.  
  25.  
  26. '************************************************
  27. '   MAPIRecip holds information about a message
  28. '   originator or recipient
  29. '************************************************
  30.  
  31. Type MapiRecip
  32.     Reserved As Long
  33.     RecipClass As Long
  34.     Name As String
  35.     Address As String
  36.     EIDSize As Long
  37.     EntryID As String
  38. End Type
  39.  
  40.  
  41. '******************************************************
  42. '   MapiFile holds information about file attachments
  43. '******************************************************
  44.  
  45. Type MAPIfile
  46.     Reserved As Long
  47.     Flags As Long
  48.     Position As Long
  49.     PathName As String
  50.     FileName As String
  51.     FileType As String
  52. End Type
  53.  
  54.  
  55. '***************************
  56. '   FUNCTION Declarations
  57. '***************************
  58.  
  59. Declare Function MAPILogon Lib "MAPI.DLL" (ByVal UIParam&, ByVal User$, ByVal Password$, ByVal Flags&, ByVal Reserved&, Session&) As Long
  60. Declare Function MAPILogoff Lib "MAPI.DLL" (ByVal Session&, ByVal UIParam&, ByVal Flags&, ByVal Reserved&) As Long
  61. Declare Function BMAPIReadMail Lib "MAPI.DLL" (lMsg&, nRecipients&, nFiles&, ByVal Session&, ByVal UIParam&, MessageID$, ByVal Flag&, ByVal Reserved&) As Long
  62. Declare Function BMAPIGetReadMail Lib "MAPI.DLL" (ByVal lMsg&, Message As MapiMessage, Recip As MapiRecip, File As MAPIfile, Originator As MapiRecip) As Long
  63. Declare Function MAPIFindNext Lib "MAPI.DLL" Alias "BMAPIFindNext" (ByVal Session&, ByVal UIParam&, MsgType$, SeedMsgID$, ByVal Flag&, ByVal Reserved&, MsgID$) As Long
  64. Declare Function MAPISendDocuments Lib "MAPI.DLL" (ByVal UIParam&, ByVal DelimStr$, ByVal FilePaths$, ByVal FileNames$, ByVal Reserved&) As Long
  65. Declare Function MAPIDeleteMail Lib "MAPI.DLL" (ByVal Session&, ByVal UIParam&, ByVal MsgID$, ByVal Flags&, ByVal Reserved&) As Long
  66. Declare Function MAPISendMail Lib "MAPI.DLL" Alias "BMAPISendMail" (ByVal Session&, ByVal UIParam&, Message As MapiMessage, Recipient As MapiRecip, File As MAPIfile, ByVal Flags&, ByVal Reserved&) As Long
  67. Declare Function MAPISaveMail Lib "MAPI.DLL" Alias "BMAPISaveMail" (ByVal Session&, ByVal UIParam&, Message As MapiMessage, Recipient As MapiRecip, File As MAPIfile, ByVal Flags&, ByVal Reserved&, MsgID$) As Long
  68. Declare Function BMAPIAddress Lib "MAPI.DLL" (lInfo&, ByVal Session&, ByVal UIParam&, Caption$, ByVal nEditFields&, Label$, nRecipients&, Recip As MapiRecip, ByVal Flags&, ByVal Reserved&) As Long
  69. Declare Function BMAPIGetAddress Lib "MAPI.DLL" (ByVal lInfo&, ByVal nRecipients&, Recipients As MapiRecip) As Long
  70. Declare Function MAPIDetails Lib "MAPI.DLL" Alias "BMAPIDetails" (ByVal Session&, ByVal UIParam&, Recipient As MapiRecip, ByVal Flags&, ByVal Reserved&) As Long
  71. Declare Function MAPIResolveName Lib "MAPI.DLL" Alias "BMAPIResolveName" (ByVal Session&, ByVal UIParam&, ByVal UserName$, ByVal Flags&, ByVal Reserved&, Recipient As MapiRecip) As Long
  72.  
  73.  
  74.  
  75. '**************************
  76. '   CONSTANT Declarations
  77. '**************************
  78. '
  79.  
  80. Global Const SUCCESS_SUCCESS = 0
  81. Global Const MAPI_USER_ABORT = 1
  82. Global Const MAPI_E_USER_ABORT = MAPI_USER_ABORT
  83. Global Const MAPI_E_FAILURE = 2
  84. Global Const MAPI_E_LOGIN_FAILURE = 3
  85. Global Const MAPI_E_LOGON_FAILURE = MAPI_E_LOGIN_FAILURE
  86. Global Const MAPI_E_DISK_FULL = 4
  87. Global Const MAPI_E_INSUFFICIENT_MEMORY = 5
  88. Global Const MAPI_E_BLK_TOO_SMALL = 6
  89. Global Const MAPI_E_TOO_MANY_SESSIONS = 8
  90. Global Const MAPI_E_TOO_MANY_FILES = 9
  91. Global Const MAPI_E_TOO_MANY_RECIPIENTS = 10
  92. Global Const MAPI_E_ATTACHMENT_NOT_FOUND = 11
  93. Global Const MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
  94. Global Const MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
  95. Global Const MAPI_E_UNKNOWN_RECIPIENT = 14
  96. Global Const MAPI_E_BAD_RECIPTYPE = 15
  97. Global Const MAPI_E_NO_MESSAGES = 16
  98. Global Const MAPI_E_INVALID_MESSAGE = 17
  99. Global Const MAPI_E_TEXT_TOO_LARGE = 18
  100. Global Const MAPI_E_INVALID_SESSION = 19
  101. Global Const MAPI_E_TYPE_NOT_SUPPORTED = 20
  102. Global Const MAPI_E_AMBIGUOUS_RECIPIENT = 21
  103. Global Const MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT
  104. Global Const MAPI_E_MESSAGE_IN_USE = 22
  105. Global Const MAPI_E_NETWORK_FAILURE = 23
  106. Global Const MAPI_E_INVALID_EDITFIELDS = 24
  107. Global Const MAPI_E_INVALID_RECIPS = 25
  108. Global Const MAPI_E_NOT_SUPPORTED = 26
  109.  
  110. Global Const MAPI_ORIG = 0
  111. Global Const MAPI_TO = 1
  112. Global Const MAPI_CC = 2
  113. Global Const MAPI_BCC = 3
  114.  
  115.  
  116. '***********************
  117. '   FLAG Declarations
  118. '***********************
  119.  
  120. '* MAPILogon() flags *
  121.  
  122. Global Const MAPI_LOGON_UI = &H1
  123. Global Const MAPI_NEW_SESSION = &H2
  124. Global Const MAPI_FORCE_DOWNLOAD = &H1000
  125. Global Const MAPI_ALLOW_OTHERS = &H8
  126. Global Const MAPI_EXPLICIT_PROFILE = &H10
  127. Global Const MAPI_USE_DEFAULT = &H40
  128.  
  129. Global Const MAPI_SIMPLE_DEFAULT = MAPI_LOGON_UI Or MAPI_FORCE_DOWNLOAD Or MAPI_ALLOW_OTHERS
  130. Global Const MAPI_SIMPLE_EXPLICIT = MAPI_NEW_SESSION Or MAPI_FORCE_DOWNLOAD Or MAPI_EXPLICIT_PROFILE
  131.  
  132. '* MAPILogoff() flags *
  133.  
  134. Global Const MAPI_LOGOFF_SHARED = &H1
  135. Global Const MAPI_LOGOFF_UI = &H2
  136.  
  137. '* MAPISendMail() flags *
  138.  
  139. Global Const MAPI_DIALOG = &H8
  140.  
  141. '* MAPIFindNext() flags *
  142.  
  143. Global Const MAPI_UNREAD_ONLY = &H20
  144. Global Const MAPI_GUARANTEE_FIFO = &H100
  145. Global Const MAPI_LONG_MSGID = &H4000
  146.  
  147. '* MAPIReadMail() flags *
  148.  
  149. Global Const MAPI_ENVELOPE_ONLY = &H40
  150. Global Const MAPI_PEEK = &H80
  151. Global Const MAPI_BODY_AS_FILE = &H200
  152. Global Const MAPI_SUPPRESS_ATTACH = &H800
  153.  
  154. '* MAPIDetails() flags *
  155.  
  156. Global Const MAPI_AB_NOMODIFY = &H400
  157.  
  158. '* Attachment flags *
  159.  
  160. Global Const MAPI_OLE = &H1
  161. Global Const MAPI_OLE_STATIC = &H2
  162.  
  163. '* MapiMessage flags *
  164.  
  165. Global Const MAPI_UNREAD = &H1
  166. Global Const MAPI_RECEIPT_REQUESTED = &H2
  167. Global Const MAPI_SENT = &H4
  168.  
  169. Function CopyFiles (MfIn As MAPIfile, MfOut As MAPIfile) As Long
  170.  
  171.     MfOut.FileName = MfIn.FileName
  172.     MfOut.PathName = MfIn.PathName
  173.     MfOut.Reserved = MfIn.Reserved
  174.     MfOut.Flags = MfIn.Flags
  175.     MfOut.Position = MfIn.Position
  176.     MfOut.FileType = MfIn.FileType
  177.     CopyFiles = 1&
  178.     
  179. End Function
  180.  
  181. Function CopyRecipient (MrIn As MapiRecip, MrOut As MapiRecip) As Long
  182.  
  183.     MrOut.Name = MrIn.Name
  184.     MrOut.Address = MrIn.Address
  185.     MrOut.EIDSize = MrIn.EIDSize
  186.     MrOut.EntryID = MrIn.EntryID
  187.     MrOut.Reserved = MrIn.Reserved
  188.     MrOut.RecipClass = MrIn.RecipClass
  189.  
  190.     CopyRecipient = 1&
  191.     
  192. End Function
  193.  
  194. Function MAPIAddress (Session As Long, UIParam As Long, Caption As String, nEditFields As Long, Label As String, nRecipients As Long, Recips() As MapiRecip, Flags As Long, Reserved As Long) As Long
  195.  
  196.  
  197.     Dim Info&
  198.     Dim rc&
  199.     Dim nRecips As Long
  200.  
  201.     ReDim Rec(0 To nRecipients) As MapiRecip
  202.     ' Use local variable since BMAPIAddress changes the passed value
  203.     nRecips = nRecipients
  204.  
  205.     '*****************************************************
  206.     ' Copy input recipient structure into local
  207.     ' recipient structure used as input to BMAPIAddress
  208.     '*****************************************************
  209.  
  210.     For i = 0 To nRecipients - 1
  211.     ignore& = CopyRecipient(Recips(i), Rec(i))
  212.     Next i
  213.  
  214.     rc& = BMAPIAddress(Info&, Session&, UIParam&, Caption$, nEditFields&, Label$, nRecips&, Rec(0), Flags, Reserved&)
  215.     
  216.     If (rc& = SUCCESS_SUCCESS) Then
  217.  
  218.     '**************************************************
  219.     ' New recipients are now in the memory referenced
  220.     ' by Info (HANDLE). nRecipients is the number of
  221.     ' new recipients.
  222.     '**************************************************
  223.     nRecipients = nRecips     ' Copy back to parameter
  224.  
  225.     If (nRecipients > 0) Then
  226.         ReDim Rec(0 To nRecipients - 1) As MapiRecip
  227.         rc& = BMAPIGetAddress(Info&, nRecipients&, Rec(0))
  228.                           
  229.         '*********************************************
  230.         ' Copy local recipient structure to
  231.         ' recipient structure passed as procedure
  232.         ' parameter.  This is necessary because
  233.         ' VB doesn't seem to work properly when
  234.         ' the procedure parameter gets passed
  235.         ' directory to the BMAPI.DLL Address routine
  236.         '*********************************************
  237.  
  238.         ReDim Recips(0 To nRecipients - 1) As MapiRecip
  239.  
  240.         For i = 0 To nRecipients - 1
  241.         ignore& = CopyRecipient(Rec(i), Recips(i))
  242.         Next i
  243.  
  244.     End If
  245.  
  246.     End If
  247.  
  248.     MAPIAddress = rc&
  249.     
  250. End Function
  251.  
  252. Function MAPIReadMail (Session As Long, UIParam As Long, MessageID As String, Flags As Long, Reserved As Long, Message As MapiMessage, Orig As MapiRecip, RecipsOut() As MapiRecip, FilesOut() As MAPIfile) As Long
  253.  
  254.     Dim Info&
  255.     Dim nFiles&, nRecips&
  256.     
  257.     rc& = BMAPIReadMail(Info&, nRecips, nFiles, Session, 0, MessageID, Flags, Reserved)
  258.  
  259.     If (rc& = SUCCESS_SUCCESS) Then
  260.  
  261.     'Message is now read into the handles array.  We have to redim the arrays and read
  262.     'the stuff in
  263.  
  264.     If (nRecips = 0) Then nRecips = 1
  265.     If (nFiles = 0) Then nFiles = 1
  266.  
  267.     ReDim Recips(0 To nRecips - 1) As MapiRecip
  268.     ReDim Files(0 To nFiles - 1) As MAPIfile
  269.  
  270.     rc& = BMAPIGetReadMail(Info&, Message, Recips(0), Files(0), Orig)
  271.     
  272.     '*******************************************
  273.     ' Copy Recipient and File structures from
  274.     ' Local structures to those passed as
  275.     ' parameters
  276.     '*******************************************
  277.  
  278.     ReDim FilesOut(0 To nFiles - 1) As MAPIfile
  279.     ReDim RecipsOut(0 To nRecips - 1) As MapiRecip
  280.  
  281.     For i = 0 To nRecips - 1
  282.         ignore& = CopyRecipient(Recips(i), RecipsOut(i))
  283.     Next i
  284.     
  285.     For i = 0 To nFiles - 1
  286.         ignore& = CopyFiles(Files(i), FilesOut(i))
  287.     Next i
  288.  
  289.     End If
  290.  
  291.     MAPIReadMail = rc&
  292.  
  293. End Function
  294.  
  295.