LotusScript to C API Programming Guide

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




Hosted by Prominic.NET, Inc.
Main topic: Simulating unsigned integer arith in LS (for buffer length arguments etc)

Simulating unsigned integer arith in LS (for buffer length arguments etc) (by Geoff Moore, 05/12/2013 08:33:53 AM)

This is a subject that has come up several times over the years...

In the past I'd used various ugly schemes of hex manipulation, for example simple stuff like 'Clng(Val("&H" & srcdoc.NoteID & "&"))' in order to prevent trouble from "negative" numbers.

Just recently, I wanted to use 'NSFItemGetText' to retrieve LARGE (ie > 32k bytes) text items. The buffer size argument on the API call is unsigned 16-bit as is the returned length.

Rather than mess around with hex, I wrote a couple of wrapper functions:

Function signed(u16 As Long) As Integer

   If u16 > 32767 Then signed = -(65535 - u16 + 1) Else signed = u16

End Function

Function unsigned(s15 As Integer) As Long

   If s15 < 0 Then unsigned = 65535 + s15 + 1 Else unsigned = s15

End Function

Example usage:

Dim s_retlen as integer, retlen as long

s_retlen = NSFItemGetText(nh, "text", Buff50k, signed(BUFF50K_LEN))

retlen = unsigned(s_retlen)

These functions provide a handy way of flipping between longs and "unsigned integers".

Such arithmetic is also useful for sanely handling BLOCKIDs in LS.