Option Public
Option Explicit
Declare Function OSPathNetConstruct Lib "NNOTES" Alias "OSPathNetConstruct" _
( Byval NullPort As Long, Byval Server As String, Byval FIle As String, _
Byval PathNet As String) As Integer
Declare Function NSFDbOpen Lib "NNOTES" Alias "NSFDbOpen" _
( Byval PathName As String, DbHandle As Long) As Integer
Declare Function NSFDbClose Lib "NNOTES" Alias "NSFDbClose" _
( Byval DbHandle As Long) As Integer
Declare Function HTMLCreateConverter Lib "NNOTES" Alias "HTMLCreateConverter" _
( HtmlHandle As Long) As Integer
Declare Function HTMLDestroyConverter Lib "NNOTES" Alias "HTMLDestroyConverter" _
( Byval HtmlHandle As Long) As Integer
Declare Function HTMLConvertNote Lib "NNOTES" Alias "HTMLConvertNote" _
( Byval HtmlHandle As Long, Byval DbHandle As Long, Byval NoteHandle As Long, _
Byval UrlArgsCount As Long, Byval NullUrlArgs As Long) As Integer
Declare Function HTMLGetPropertyLong Lib "NNOTES" Alias "HTMLGetProperty" _
( Byval HtmlHandle As Long, Byval PropertyType As Long, RetVal As Long) As Integer
Declare Function HTMLGetText Lib "NNOTES" Alias "HTMLGetText" _
( Byval HtmlHandle As Long, Byval StartingOffset As Long, TextLength As Long, _
Byval RetVal As Lmbcs String) As Integer
Const ERR_MASK = &H3fff
Const PKG_MASK = &H3f00
Const ERRNUM_MASK = &H00ff
Declare Function OSLoadString Lib "nnotes.dll" (Byval hModule As Long, Byval stringCode As Integer, _
Byval retBuffer As String, Byval bufferLength As Integer) As Integer
Function ConvertDocToHtml (doc As NotesDocument) As String
Dim db As NotesDatabase
Dim hDb As Long
Dim pathName As String
Set db = doc.ParentDatabase
pathName = String(256, " ")
Call OSPathNetConstruct(0, db.Server, db.FilePath, pathName)
Dim result As Integer
result = NSFDbOpen(pathName, hDb)
If result <> 0 Then
Messagebox "Cannot open database " & db.FilePath & " on server " & db.Server & _
". Error was " & Cstr(result) & ": " & GetAPIError(result)
Exit Function
End If
Dim converter As Long
result = HtmlCreateConverter(converter)
If result <> 0 Then
Messagebox "Cannot create HTML Converter" & _
". Error was " & Cstr(result) & ": " & GetAPIError(result)
Goto closeDb
End If
result = HtmlConvertNote(converter, hDB, doc.Handle, 0, 0)
If result <> 0 Then
Messagebox "Cannot convert note " & doc.UniversalID & " to HTML" & _
". Error was " & Cstr(result) & ": " & GetAPIError(result)
Goto destroyConverter
End If
Dim textLength As Long
result = HtmlGetPropertyLong(converter, 0, textLength)
If result <> 0 Then
Messagebox "Cannot determine HTML Converter text length" & _
". Error was " & Cstr(result) & ": " & GetAPIError(result)
Goto destroyConverter
End If
Dim finalString As String
Dim chunk As String
Dim chunkSize As Long
Dim startPos As Long
chunkSize = 1024
Do While (startPos < textLength)
If ((textLength - startPos) < chunkSize) Then
chunkSize = textLength - startPos
End If
chunk = String(chunkSize, " ")
result = HtmlGetText(converter, startPos, chunkSize, chunk)
If result <> 0 Then
Messagebox "Cannot get HTML text between " & startPos & " and " & (startPos + chunkSize) & _
". Error was " & Cstr(result) & ": " & GetAPIError(result)
Goto destroyConverter
End If
finalString = finalString & Left(chunk, chunkSize)
startPos = startPos + chunkSize
Loop
ConvertDocToHtml = finalString
destroyConverter:
Call HTMLDestroyConverter(converter)
closeDb:
Call NSFDbClose(hDb)
endOfFunction:
Exit Function
End Function
Sub Initialize
Dim session As New NotesSession
Dim doc As NotesDocument
Dim html As String
Set doc = session.CurrentDatabase.AllDocuments.GetFirstDocument
html = ConvertDocToHtml(doc)
Print html
End Sub
Function GetAPIError (errorCode As Integer) As String
Dim errorString As String*256
Dim returnErrorString As String
Dim resultStringLength As Long
Dim errorCodeTranslated As Integer
errorCodeTranslated = (errorCode And ERR_MASK)
resultStringLength = OSLoadString(0, errorCodeTranslated, errorString, Len(errorString) - 1)
If (Instr(errorString, Chr(0)) > 0) Then
returnErrorString = Left$(errorString, Instr(errorString, Chr(0)) - 1)
Else
returnErrorString = errorString
End If
GetAPIError = returnErrorString
End Function
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.