' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ' * ' * Item information and Memory management ' * (Agent code) ' * ' * sample code from ' * LotusScript to Lotus C API Programmer Guide by Normunds Kalnberzins, (c) 2000-2003 ' * ' * http://www.ls2capi.com ' * ' * Author: Normunds Kalnberzins ' * ' * This code has been written as a sample to illustrate aspects of handling of Lotus C API from LotusScript ' * and may be reused, modified on full responsibility of the developer and provided this notice is preserved ' * ' * The author does not guaranty it to fit any particular purpose and it is up to the developer ' * to modify, test it and determine the limits of its applicability ' * ' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %Include "c:\lss\capis\samples\memoryManager" ' include class Dim s as NotesSession Dim ndb as NotesDatabase Dim doc as NotesDocument Const PLATFORM_MAC = "Macintosh" Const PLATFORM_W32 = "Windows/32" ' * * * * * * * * START (Const) [MISC] ' * * * * * * * * ' * Const ODS_WORD = 0 ' * * * * * * * * END (Const) [MISC] ' * * * * * * * * ' * * * * * * * * START (Type) [BLOCKID] ' * * * * * * * * ' * Public Type BLOCKID pool As Long block As Long End Type ' * * * * * * * * END (Type) [BLOCKID] ' * * * * * * * * ' * * * * * * * * START (Type) [BLOCKID16] ' * * * * * * * * ' * Public Type BLOCKID16 pool As Integer block As Long End Type ' * * * * * * * * END (Type) [BLOCKID16] ' * * * * * * * * ' * * * * * * * * START (Declaration) [W32_OSLOCKOBJECT] ' * * * * * * * * ' * ' * lock object (and return pointer) ' * Declare Function W32_OSLockObject Lib "nnotes" Alias "OSLockObject" ( Byval handle As Long) As Long ' * * * * * * * * END (Declaration) [W32_OSLOCKOBJECT] ' * * * * * * * * ' * * * * * * * * START (Declaration) [W32_OSUNLOCKOBJEC ' * * * * * * * * ' * ' * unlock handle ' * Declare Sub W32_OSUnlockObject Lib "nnotes" Alias "OSUnlockObject" ( Byval handle As Long) ' * * * * * * * * END (Declaration) [W32_OSUNLOCKOBJECT] ' * * * * * * * * ' * * * * * * * * START (Declaration) [MAC_OSLOCKOBJECT] ' * * * * * * * * ' * ' * lock object for Mac ' * Declare Function MAC_OSLockObject Lib "NotesLib" Alias "OSLockObject" ( Byval handle As Integer) As Long ' * * * * * * * * END (Declaration) [MAC_OSLOCKOBJECT] ' * * * * * * * * ' * * * * * * * * START (Declaration) [MAC_OSUNLOCKOBJEC ' * * * * * * * * ' * ' * unlock for Mac ' * Declare Sub MAC_OSUnlockObject Lib "NotesLib" Alias "OSUnlockObject" ( Byval handle As Integer) ' * * * * * * * * END (Declaration) [MAC_OSUNLOCKOBJECT] ' * * * * * * * * ' * * * * * * * * START (Declaration) [MAC_NSFITEMINFO] ' * * * * * * * * ' * Declare Function MAC_NSFItemInfo Lib "NotesLib" Alias "NSFItemInfo" (Byval note_handle As Integer, Byval item_name As Lmbcs String, Byval name_len As Integer, item_blockid As blockid16, value_datatype As Integer, value_blockid As blockid16, value_len As Long) As Integer ' * * * * * * * * END (Declaration) [MAC_NSFITEMINFO] ' * * * * * * * * ' * * * * * * * * START (Declaration) [W32_NSFITEMINFO] ' * * * * * * * * ' * Declare Function W32_NSFItemInfo Lib "nnotes" Alias "NSFItemInfo" (Byval note_handle As Long, Byval item_name As String, Byval name_len As Integer, item_blockid As blockid, value_datatype As Integer, value_blockid As blockid, value_len As Long) As Integer ' * * * * * * * * END (Declaration) [W32_NSFITEMINFO] ' * * * * * * * * ' * * * * * * * * START (Declaration) [W32_ODSREADMEMORY ' * * * * * * * * ' * Declare Sub W32_ODSReadMemory Lib "nnotes.dll" Alias "ODSReadMemory" (pSource As Long, Byval typeODS As Integer, pDest As Any, Byval Iterations As Integer ) ' * * * * * * * * END (Declaration) [W32_ODSREADMEMORY] ' * * * * * * * * ' * * * * * * * * START (Method) [OSUNLOCKOBJECT] ' * * * * * * * * ' * ' * unlock handle ' * Public Sub OSUnlockObject (handle) Dim s As New NotesSession Select Case s.Platform Case PLATFORM_W32 Call W32_OSUnlockObject (handle) Case PLATFORM_MAC Call MAC_OSUnlockObject (Cint(handle)) End Select End Sub ' * * * * * * * * END (Method) [OSUNLOCKOBJECT] ' * * * * * * * * ' * * * * * * * * START (Method) [INITIALIZE] ' * * * * * * * * ' * ' * run agent code ' * Sub Initialize Dim memman as New memoryManager Dim item_blockid As Blockid Dim value_blockid As Blockid Dim value_datatype As Integer Dim value_len As Long Dim p as Long Dim iType as Integer Set s = new NotesSession Set doc = s.documentContext ' get current document forall i in doc.items if NSFItemInfo (doc.handle, i.Name, len(i.Name), item_blockid, value_datatype, value_blockid, value_len) =0 then ' memory manager object does all handle/memory maintenance p = memman.lockObject (value_blockid.pool) + value_blockid.block ' don't do anything fancy - read one word - datatype of the item; in fact it must be the same as value_datatype, hence we can use the result to verify the result W32_ODSReadMemory p, ODS_WORD, iType, 1 print i.name, "type=" &iType, "length=" &value_len End if End forall End Sub ' * * * * * * * * END (Method) [INITIALIZE] ' * * * * * * * * ' * * * * * * * * START (Method) [BLOCK16TO32] ' * * * * * * * * ' * Public Sub block16to32 (b16 As Blockid16, b As Blockid) b.pool = b16.pool b.block = b16.block End Sub ' * * * * * * * * END (Method) [BLOCK16TO32] ' * * * * * * * * ' * * * * * * * * START (Method) [NSFITEMINFO] ' * * * * * * * * ' * ' * get item ' * Public Function NSFItemInfo (ByVal note_handle As Long, item_name As String, ByVal name_len As Integer, item_blockid As Blockid, value_datatype As Integer, value_blockid As Blockid, value_len As Long) As Integer Dim i_block16 As blockid16, v_block16 As blockid16 ' for 16 bit handles Dim s As New NotesSession Select Case s.platform Case PLATFORM_W32 NSFItemInfo = W32_NSFItemInfo (note_handle, item_name, name_len, item_blockid, value_datatype, value_blockid ,value_len) Case PLATFORM_MAC NSFItemInfo = MAC_NSFItemInfo (Cint(note_handle), item_name, name_len, i_block16, value_datatype, v_block16 ,value_len) ' convert return values to blocks using 32 bit handle (pool) block16to32 v_block16, value_blockid block16to32 i_block16, item_blockid End Select End Function ' * * * * * * * * END (Method) [NSFITEMINFO] ' * * * * * * * * ' * * * * * * * * START (Method) [OSLOCKOBJECT] ' * * * * * * * * ' * ' * Lock object ' * Public Function OSLockObject (handle) As Long Dim s As New NotesSession Select Case s.Platform Case PLATFORM_W32 OSLockObject = W32_OSLockObject (handle) Case PLATFORM_MAC OSLockObject = MAC_OSLockObject (Cint(handle)) End Select End Function ' * * * * * * * * END (Method) [OSLOCKOBJECT] ' * * * * * * * * ' * * * * * * * * END (Function library) [MEMORY MANAGER ' * * * * * * * *