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: Problems with memory management and NSFItemAppend

Problems with memory management and NSFItemAppend (by Kenneth Haggman, 11/21/2004 05:14:51 PM)

I am having some problems and I hope you can help me.

I have developed a tool that can be used to re-order the subs and functions in a LotusScript Script Library.

It works in this manner:

1. NSFItemInfo and NSFItemInfoNext is used to get the contents of the $ScriptLib item and dumps it to a plain text file.

2. Standard LotusScript is used to re-order the contents into a new text file.

3. I now need to write the new content to the $ScriptLib item, sign the item and recompile the Script Library.

As long as the amount of text to put into the $ScriptLib item is less than an LotusScript Integer size (appr. 32000), my code works fine.

In those cases, I use NSFItemSetText and simply has a LotusScript string containing the complete text to use.

My problems come when the text is more than 32000. The NSFItemSetText API uses an Integer as size-parameter, and I can't really store strings that large in LotusScript anyway. As far as I understand I now must use a memory buffer, write to it, and then set the item using NSFItemAppend with the content in the buffer.

Question 1: Is this a correct assumption?

I allocate a buffer that is as big as the number of characters is the text that I want to write.

Question 2: Is this correct? Should I perhaps allocate a buffer that is twice the size, since LotusScript uses 2 bytes per character?

In my code, I read my text file line by line and writes to the memory buffer using ODSWriteMemory. My buffer pointer is increased for each iteration.

Question 3: What type should be used as 2nd parameter here? ODS_BYTE or TYPE_TEXT?

Question 4: Should the buffer-pointer be increased with the size of the LotusScript string just written, or perhaps with twice that size?

When I use the NSFItemAppend API, what should the 4th parameter be? ODS_BYTE or TYPE_TEXT?

As you see, I have many questions and I am feeling very insecure here.

I can get the code to run using the sample below, but then I can't sign the item and the item is never updated properly.

Please help me out here.

=== Sample ===

Note that this is not the complete code, just some extracts.

1. Read textfile line by line to calculate size of buffer needed. This includes the LF characters needed. Size is stored in (Long) variable lngBuffSize. Lets say I get a total size here of 48000.

2. Allocate buffer.

p = memman.newBuffer(lngBuffSize)

pBuff = p

pCurr = p

3. Read textfile line by line and copy to buffer.

Do While Not Eof(fileNum)

Line Input #fileNum, strLine

W32_ODSWriteMemory pCurr, ODS_BYTE, strLine, Len(strLine)

pCurr = pCurr + Len(strLine)

Loop

4. Open database and Script Library document.

5. Write using

iStatus = W32_NSFItemAppend (hNote, 0, "$ScriptLib", Len("$ScriptLib"), TYPE_TEXT, pBuff, lngBuffSize)