FILE: DLL to Read and Write RTF with Active Messaging

Last reviewed: November 21, 1997
Article ID: Q172038
The information in this article applies to:
  • Extended Messaging Application Programming Interface (MAPI), version 1.0
  • Collaboration Data Objects (CDO), version 1.1

SUMMARY

When writing an Active Messaging client, it would be useful to be able to use rich text formatting (RTF) in the body of the messages that are created. However, the Active Messaging Libraries provide access only to the plain text version of the body of the message, giving no control over the font characteristics of the message body.

This sample contains a DLL with functions that may be called from an Active Messaging client to read and write RTF text of a message.

The following file is available for download from the Microsoft Software Library:

 ~ Mapirtf.exe (size: 109180 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

MORE INFORMATION

Below are the contents of the Readme.txt file for this sample.

MAPIRTF Sample

This sample illustrates how use Extended MAPI to allow RTF-formatting in a message created by Active Messaging.

Files

The self-extracting executable, Mapirtf.exe, contains the following files:
  • Readme.txt: Contains information about the sample
  • Mapirtf.dll: The release version of the DLL
  • Mapirtfd.dll: The debug version of the DLL
  • Vbmaprtf.exe: Microsoft Visual Basic Active Messaging client
  • Vbmaprtf.pdb: Debug symbols for Vbmaprtf.exe
  • CSource Folder: Contains the source file and Microsoft Visual C++ version 5.0 workspace and project files for Mapirtf(d).dll
  • VBSource Folder: Contains the Microsoft Visual Basic version 5.0 project, form, and module files for Vbmaprtf.exe

General

The files Mapirtf.dll (release version) and Mapirtfd.dll (debug version) contain the following functions:

  • "Writertf" writes RTF-formatted text to a message created by Active Messaging, when passed the profile name, entry ID of the message, entry ID of the message store, and the RTF text.
  • "Readrtf" reads RTF-formatted text from a message when passed the profile name, entry ID of the message, entry ID of the message store, and a string variable to which to store the text.

How to Use

Before use, the DLL files should be placed in the Windows\System directory (for Windows 95) or the Winnt\System32 directory (for Windows NT.

In Visual Basic, declare the functions as follows:

    ' For the Debug version of the DLL, remark the following lines
    Public Declare Function WriteRTF _
        Lib "mapirtf.dll" _
        Alias "writertf" (ByVal ProfileName As String, _
                          ByVal MessageID As String, _
                          ByVal StoreID As String, _
                          ByVal cText As String) _
        As Integer

    Public Declare Function ReadRTF _
        Lib "mapirtf.dll" _
        Alias "readrtf" (ByVal ProfileName As String, _
                       ByVal SrcMsgID As String, _
                         ByVal SrcStoreID As String, _
                   ByRef MsgRTF As String) _
        As Integer

    ' For the Debug version of the DLL, un-remark the following lines
    'Public Declare Function WriteRTF _
        Lib "mapirtfd.dll" _
        Alias "writertf" (ByVal ProfileName As String, _
                          ByVal MessageID As String, _
                          ByVal StoreID As String, _
                          ByVal cText As String) _
        As Integer

    'Public Declare Function ReadRTF _
        Lib "mapirtfd.dll" _
        Alias "readrtf" (ByVal ProfileName As String, _
                       ByVal SrcMsgID As String, _
                         ByVal SrcStoreID As String, _
                   ByRef MsgRTF As String) _
        As Integer

Sample Code

The following sample code assumes that you have already declared the DLL function as described above. For a more complete example, please see the Visual Basic project accompanying this sample.

  • WriteRTF Sample. (This code assumes you already have a variable called cRTF defined which contains RTF-formatted text.)

        Sub SendRTF()
          Dim objSession, objMessage, objMessageFilter As Object
          Dim MessageID As String
          Dim bRet As Integer
    

          Set objSession = CreateObject("MAPI.Session")
          objSession.Logon
    

          ' Create a new message
          Set objMessage = objSession.Outbox.Messages.Add
          objMessage.Update
          MessageID = objMessage.ID
    

          bRet = WriteRTF(objSession.Name, objMessage.ID, _
    
                          objMessage.StoreID, cRTF)
    
          If Not bRet = 0 Then
             MsgBox "RTF Not Written Successfully"
          End If
    
          ' Because the object has changed, we must re-create
          ' our Message object variable
          ' First clear our current variable
          Set objMessage = Nothing
          ' Next set a filter on the outbox for our Message ID
          Set objMessageFilter = objSession.Outbox.Messages.Filter
          objMessageFilter.Fields(ActMsgPR_ENTRYID) = MessageID
          ' Get our message
          Set objMessage = objSession.Outbox.Messages.GetFirst
          ' Clear the filter we have set
          Set objMessageFilter = Nothing
    
          ' Send the Message
          objMessage.Send ShowDialog:=True
          objSession.Logoff
        End Sub
    
    
  • ReadRTF Sample.

        Sub ReadRTF()
          Dim objSession, objMessage, objMessageFilter As Object
          Dim MessageID, cRTF As String
          Dim bRet As Integer
    

          Set objSession = CreateObject("MAPI.Session")
          objSession.Logon
    

          ' Read the first message in the Inbox
          Set objMessage = objSession.Inbox.Messages(1)
          objMessage.Update  ' to get a permanent Entry ID
          MessageID = objMessage.ID
    

          ' We must initialize the string variable we are passing
          ' to a string of the maximum length we want to read
          cRTF = Space(500)
          bRet = ReadRTF(objSession.Name, objMessage.ID, _
    
                          objMessage.StoreID, cRTF)
    
          If Not bRet = 0 Then
             MsgBox "RTF Not Written Successfully"
          Else
             MsgBox "RTF Text: " & Chr(13) & cRTF
          End If
    
          Set objMessage = Nothing
          objSession.Logoff
          Set objSession = Nothing
        End Sub
    
    

REFERENCES

For additional information about Collaboration Data Objects versus Active Messaging, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q176916
   TITLE     : INFO: Active Messaging and Collaboration Data Objects (CDO)

Keywords          : kbcode ActMsg EMAPI
Version           : WINDOWS:1.0,1.1
Platform          : WINDOWS
Issue type        : kbfile
Solution Type     : kbsample


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.