LotusScript to C API Programming Guide

rtLib Domino Rich Text Management template
Home
Show details for ContentContent
Purchase
Ready-to-use samples
Show details for Online resourcesOnline resources
Forum
Links
Happy readers

Anonymous

login


 

Hosted by Prominic.NET, Inc.
Main topic: Ls2Capi Discussion Forum

writing CD-records to item (by customerservice, 01/26/2004 02:14:22 PM)

Hi,

From what I understand the basic steps in attaching a file and creating an icon in the rich text field are as follows:

1. Call NSFNoteAttachFile to create a $FILE item. (this is working fine)

2. Create a new buffer and add the following records:

   2.1 Create a CDHOTSPOTBEGIN record with the type set to HOTSPOTREC_TYPE_FILE.

   2.2 Create a CDTEXT record that will contain the name of the attached file.

   2.3 Create a CDHOTSPOTEND record to mark the end of the hotspot.

5. Call NSFItemAppend to append the buffer to the note.

Following is the code that I have written so far:

Declarations:

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

Const LIB_W32 = "nnotes" ' Windows/32

Const COMPRESS_HUFF = 1      'huffman encoding for compression

Const HOTSPOTREC_TYPE_FILE = 4

Const HOTSPOTREC_RUNFLAG_BEGIN = &h00000001

Const HOTSPOTREC_RUNFLAG_NOBORDER = &h00000008

Const WORDRECORDLENGTH = &hff00

Const SIG_CD_HOTSPOTBEGIN = 169 Or WORDRECORDLENGTH

Const SIG_CD_HOTSPOTEND = 170 Or WORDRECORDLENGTH

Const ODS_CDHOTSPOTBEGIN = 230

Const ODS_CDHOTSPOTEND = 230

Const ODS_WORD = 0 'transfers an Integer (2-bytes)

Const ODS_DWORD = 1 'transfers long (4-bytes)

Const ODS_BYTE = 3 'transfer a byte

Const TYPE_COMPOSITE =1

Declare Function W32_NSFNoteAttachFile Lib LIB_W32 Alias "NSFNoteAttachFile" (Byval h As Long, Byval item_name As Lmbcs String, Byval item_name_length As Integer, Byval file_name As Lmbcs String, Byval orig_path_name As Lmbcs String, Byval encoding_type As Integer) As Integer

Declare Function W32_NSFNoteUpdate Lib LIB_W32 Alias "NSFNoteUpdate" (Byval note_handle As Long, Byval update_flags As Integer) As Integer

Declare Function W32_OSLockObject Lib LIB_W32 Alias "OSLockObject" (Byval handle As Long) As Long

Declare Sub W32_OSUnlockObject Lib LIB_W32 Alias "OSUnlockObject" (Byval handle As Long)

Declare Sub W32_ODSWriteMemory Lib LIB_W32 Alias "ODSWriteMemory" (pSource As Long, Byval typeODS As Integer, pDest As Any, Byval Iterations As Integer)

Declare Function W32_ODSLength Lib LIB_W32 Alias "ODSLength" (Byval odstype As Integer) As Integer

Declare Private Function W32_OSMemoryAllocate Lib LIB_W32 Alias "OSMemoryAllocate" (  Byval T As Long, Byval S As Long, hM As Long) As Integer

Declare Private Sub W32_OSMemoryFree Lib LIB_W32 Alias "OSMemoryFree" (  Byval hM As Long)

Declare Private Function W32_OSMemoryLock Lib LIB_W32 Alias "OSMemoryLock" (  Byval hM As Long) As Long

Declare Private Function W32_OSMemoryUnlock Lib LIB_W32 Alias "OSMemoryUnlock" (  Byval hM As Long) As Integer

Declare Function W32_NSFItemAppend Lib LIB_W32  Alias "NSFItemAppend" (Byval note_handle As Long, Byval item_flags As Integer, Byval item_name As String, Byval name_len As Integer, Byval item_type As Integer, Byval pItem_value As Long, Byval value_len As Long) As Integer

Type OBJECT_DESCRIPTOR

   ObjectType As Integer

   RRV As Long

End Type

Type FILEOBJECT

   Header As OBJECT_DESCRIPTOR '/*object header */

   FileNameLength As Integer 'HostType as Integer CompressionType as Integer 'FileAttributes as Integer 'Flags as Integer FileSize as Long FileCreated as TIMEDATE FileModified as TIMEDATE

End Type

Type WSIG

   Signature As Integer

   Length As Integer

End Type

Type BSIG

   Signature As Integer

   Length As Integer

End Type

Type CDHOTSPOTBEGIN

   Header As WSIG

   Type As Integer

   Flags As Long

   DataLength As Integer

End Type

Type CDHOTSPOTEND

   Header As BSIG

End Type

Type CDTEXT

   Header As WSIG

   FontID As Long

End Type

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

I have also imported the classes MemoryManager and MemoryManagerExt classes in the Declaration section.

Here is relevant parts of the code in the click event of the Action:

Note: I have not implement the CDTEXT part yet... First I wanted to make sure the CDHOTSPOTBEGIN and CDHOTSPOTEND are working properly.

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

   Dim memMan As New memoryManagerExt, pBuff As Long

   Dim p As Long, p0 As Long 'buffer pointers

   Dim buffLength As Long

   Dim hotspot As CDHOTSPOTBEGIN

   Dim hotspotend As CDHOTSPOTEND

   Dim attText As CDTEXT

   Dim hNT As Long

   hNT = uidoc.Document.Handle

   result = W32_NSFNoteAttachFile (hNT, "$File", Len("$File"), fileLoc$ & fname$, fname$, COMPRESS_HUFF)         

            

   Msgbox result 'I get a zero meaning the file is attached successfully

   

   result = W32_NSFNoteUpdate(hNT, 0)

   

   Msgbox result 'I get a value zero here too

            

   'Set various flags

   hotspot.Type = HOTSPOTREC_TYPE_FILE

   hotspot.Flags = HOTSPOTREC_RUNFLAG_BEGIN Or HOTSPOTREC_RUNFLAG_NOBORDER

   'Set data length

   hotspot.DataLength = Len("File$")   Len(fname$) 'Not sure if I need to do   2 here

   'Set the header info

   hotspot.Header.Signature = SIG_CD_HOTSPOTBEGIN

   hotspot.Header.Length = W32_ODSLength(ODS_CDHOTSPOTBEGIN)   hotspot.DataLength

            

   buffLength = hotspot.Header.Length

   If (buffLength Mod 2) = 1 Then

      buffLength = buffLength   1 'padding to even boundary

   End If

   

   'Create a neww buffer      

   p = memman.newBuffer (buffLength)

   p0 =p 'save the original buffer location

            

        'Write the first three ODS_WORDs

   Call W32_ODSWriteMemory (p, ODS_WORD, hotspot.header.signature,3) '3 first words

   

        Call W32_ODSWriteMemory (p, ODS_DWORD, hotspot.Flags,1) 'Flags

   

   Call W32_ODSWriteMemory (p, ODS_WORD, hotspot.Datalength,1) 'last word

   

        'I have not implemented the CDTEXT Part here.......

   'Set the values of the CDHOTSPOTEND      

   hotspotend.Header.Signature = SIG_CD_HOTSPOTEND

   hotspotend.Header.Length = W32_ODSLength(ODS_CDHOTSPOTEND)

            

   Call W32_ODSWriteMemory (p, ODS_BYTE, hotspotend.header.signature, 1) '1 byte

   Call W32_ODSWriteMemory (p, ODS_BYTE, hotspotend.header.length,1)

            

   'Append the Item to the Note                     

   result = W32_NSFItemAppend(hNT, 0, "Body", Len("Body"), TYPE_COMPOSITE, p0, buffLength)

   

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