Private Type timeDateTYPE
innards(0 To 1) As Long
End Type
Declare Function W32OSLoadString Lib "nnotes" Alias "OSLoadString" ( _
Byval hMod As Long, _
Byval stringCode As Integer, _
Byval retBuff As Lmbcs String, _
Byval buffLen As Integer _
) As Integer
Declare Private Function W32NSFNoteOpen Lib "nnotes" Alias "NSFNoteOpen" ( _
Byval hDb As Long, _
Byval noteID As Long, _
Byval openFlags As Integer, _
hNote As Long _
) As Integer
Declare Private Function W32NSFNoteClose Lib "nnotes" Alias "NSFNoteClose" ( _
Byval hNote As Long _
) As Integer
Declare Private Function W32NSFNoteGetInfo Lib "nnotes" Alias "NSFNoteGetInfo" ( _
Byval hNote As Long, _
Byval noteMember As Integer, _
retValu As Any _
) As Integer
Declare Private Function W32ConvertTIMEDATEToText Lib "nnotes" Alias "ConvertTIMEDATEToText" ( _
Byval intlFmt As Long, _
Byval txtFmt As Long, _
timeDate As timeDateTYPE, _
Byval retBuff As Lmbcs String, _
Byval maxBuffLen As Integer, _
actBuffLen As Integer _
) As Integer
Public Function getAddedToFileDate(pndtAddedInThisFile As NotesDateTime, plngHDb As Long, Byval pstrNoteID As String) As Boolean
'// +++ GLOBAL VARIABLES +++
'// Constants:
'// none
'//
'// Class instances:
'// none
'//
'// 09/23/2004 - Dallas Gimpel
'//
'// DESCRIPTION:
'// This function serves as a wrapper for obtaining the date/time a given Note was added to
'// to its parent database via calls to the C API. The date/time "added" may be the same as
'// the date the note was created but it can also be the date/time the note was received by
'// way of replication. Once value is retrieved, the date/time value is written out to the
'// NotesDateTime object passed. If an API error is encountered, the function attempts to
'// re-throw the error in a more friendly manner via the "getAPIErrorDesc" function.
'//
'// INPUT:
'// plngHDb - Long, an API handle to the target document's parent database
'// pstrNoteID - String, the Note ID of the target document
'//
'// OUTPUT:
'// pndtAddedInThisFile - NotesDateTime, receives date/time the given note was added to its database
'// Function returns a boolean - true unless an error is encountered, otherwise false
On Error Goto errorHandler
Const NOTE_ADDED_TO_FILE% = 13
Const BUFF_LENGTH% = 32 * 3
Dim lngHNote As Long
Dim tdStruct As timeDateTYPE
Dim intRetCode As Integer
Dim intStringLength As Integer
Dim strErrTxt As String
Dim strRetBuff As String * BUFF_LENGTH
getAddedToFileDate = False
pstrNoteID$ = "&H" & pstrNoteID$
intRetCode% = W32NSFNoteOpen(plngHDb&, Clng(pstrNoteID$), 0, lngHNote&)
If Not(intRetCode% = 0) Then
Call getAPIErrorDesc(intRetCode%, strErrTxt$)
Error intRetCode%, strErrTxt$
End If
intRetCode% = W32NSFNoteGetInfo(lngHNote&, NOTE_ADDED_TO_FILE, tdStruct)
If Not(intRetCode% = 0) Then
Call getAPIErrorDesc(intRetCode%, strErrTxt$)
Error intRetCode%, strErrTxt$
End If
intRetCode% = W32ConvertTIMEDATEToText(0&, 0&, tdStruct, strRetBuff$, BUFF_LENGTH, intStringLength%)
If Not(intRetCode% = 0) Then
Call getAPIErrorDesc(intRetCode%, strErrTxt$)
Error intRetCode%, strErrTxt$
End If
Set pndtAddedInThisFile = New NotesDateTime(Left$(strRetBuff$, intStringLength%))
getAddedToFileDate = pndtAddedInThisFile.IsValidDate
functionExit:
If lngHNote& > 0 Then
Call W32NSFNoteClose(lngHNote&)
End If
Exit Function
errorHandler:
Msgbox "Error " & Err & ": " & Error & " encountered at line " & Erl & " of " & Getthreadinfo(1) & ".", , "Error encountered . . ."
Print "Error " & Err & ": " & Error & " encountered at line " & Erl & " . . ."
Resume functionExit
End Function
Private Sub getAPIErrorDesc(pintRetCode As Integer, pstrErrMsg As String)
'// +++ GLOBAL VARIABLES +++
'// Constants:
'//
'//
'// Class instances:
'//
'//
'// 08/09/2002 - Dallas Gimpel
'//
'// DESCRIPTION:
'// This sub takes the unmodified return code returned by an api call and "decodes" it
'// into a less cryptic error number. It then returns the text associated with the given
'// error number by making an api call which loads the text into a string variable. If
'// no text is returned for the given error, it defaults to "unknown error".
'//
'// INPUT:
'// pintRetCode - Integer, the original return code as returned from the api call
'//
'// OUTPUT:
'// pintRetCode - Integer, modified by "Anding" the error mask to it to produce a "kinder & gentler" error
'// pstrErrMsg - String, the text of the error message as returned by the api
Const NULL_HANDLE = 0&
Const ERROR_MASK = &H3fff '// see globerr.h
Const BUFFER_SIZE% = 255
Const UNKOWN_ERR_DESC$ = "unknown error"
Dim intLength As Integer
pstrErrMsg$ = String$(BUFFER_SIZE + 1, 0)
pintRetCode% = pintRetCode% And ERROR_MASK
intLength% = W32OSLoadString(NULL_HANDLE, pintRetCode%, pstrErrMsg$, BUFFER_SIZE)
If intLength% > 0 Then '// if we got a valid error description back, use it
pstrErrMsg$ = Fulltrim(pstrErrMsg$)
Else
pstrErrMsg$ = UNKOWN_ERR_DESC
End If
End Sub