What’s wrong with this code, I can’t find an error, and a simple formula like “abc”:“def” returns only " “:” ". I’m not sure if the MoveMemory() call works like this in R6+, as R6+ uses single byte addressing:
Const TYPE_TEXT_LIST = &H501
Const OS_TRANSLATE_NATIVE_TO_LMBCS = 0
Const OS_TRANSLATE_LMBCS_TO_NATIVE = 1
Declare Function NSFFormulaCompile Lib “nnotes.dll” _
(FormulaName As Any, Byval FormulaNameLength As Integer, _
Byval FormulaText As String, Byval FormulaTextLength As Integer, _
rethFormula As Long, retFormulaLength As Integer, retCompileError As Integer, _
retCompileErrorLine As Integer, retCompileErrorColumn As Integer, _
retCompileErrorOffset As Integer, retCompileErrorLength As Integer) As Integer
Declare Function NSFComputeStart Lib “nnotes.dll” (Byval _
Flags As Integer, Byval lpCompiledFormula As Long, rethCompute _
As Long) As Integer
Declare Function NSFComputeStop Lib “nnotes.dll” (Byval hCompute As Long) As Integer
Declare Function NSFComputeEvaluate Lib “nnotes.dll” _
(Byval hCompute As Long, Byval hNote As Long, rethResult As _
Long, retResultLength As Integer, retNoteMatchesFormula As _
Boolean, retNoteShouldBeDeleted As Boolean, retNoteModified As _
Boolean) As Integer
Declare Function OSLockObject Lib “NNOTES.DLL” Alias “OSLockObject” (Byval handle As Long) As Long
Declare Sub OSUnlockObject Lib “NNOTES.DLL” Alias “OSUnlockObject” (Byval handle As Long)
Declare Sub OSMemFree Lib “NNOTES.DLL” Alias “OSMemFree” (Byval handle As Long)
Declare Sub MoveMemory Lib “kernel32.dll” Alias “RtlMoveMemory” _
(Destination As Any, Source As Any, Byval Length As Long)
Declare Function ListGetNumEntries Lib “nnotes.dll” (vList As Long, Byval NoteItem As Boolean) As Integer
Declare Function ListGetText Lib “nnotes.dll” (pList As Long, Byval fPrefixDataType As Boolean, _
Byval EntryNumber As Integer, retTextPointer As Long, retTextLength As Integer) As Integer
Dim sOutBuffer As String
Declare Function OSTranslate Lib “nnotes.dll” (Byval TranslateMode As Integer, Byval InData As String, Byval InLength As Integer, Byval OutData As String, Byval OutLength As Integer ) As Integer
Sub Initialize
v=RunFormula({@Unique("abc":"def")})
End Sub
Function RunFormula(s As String) As Variant
Redim vResult(0 To 0) As String
vResult(0) = ""
Dim p_hNote As Long, p_sFormula As String
p_sFormula = s
p_hNote = 0
Dim iReturnValue As Integer
Dim hFormula As Long
Dim iFormulaLength As Integer
Dim iCompileError As Integer
Dim iCompileErrorLine As Integer
Dim iCompileErrorColumn As Integer
Dim iCompileErrorOffset As Integer
Dim iCompileErrorLength As Integer
Dim lFormulaAddress As Long
Dim hCompute As Long
Dim hResult As Long
Dim iResultLength As Integer
Dim bNoteMatchesFormula As Boolean
Dim bNoteShouldBeDeleted As Boolean
Dim bNoteModified As Boolean
Dim lResultAddress As Long
Dim iDataType As Integer
Dim sFormulaLMBCS As String
sFormulaLMBCS = translate(OS_TRANSLATE_NATIVE_TO_LMBCS, p_sFormula)
iReturnValue = NSFFormulaCompile(Byval &H0, 0, sFormulaLMBCS, _
Len(sFormulaLMBCS), hFormula, iFormulaLength, iCompileError, _
iCompileErrorLine, iCompileErrorColumn, iCompileErrorOffset, _
iCompileErrorLength)
If (iReturnValue) Then
Msgbox "Error " & iReturnValue
RunFormula = vResult
Exit Function
End If
lFormulaAddress = OSLockObject(hFormula)
iReturnValue = NSFComputeStart(0, lFormulaAddress, hCompute)
iReturnValue = NSFComputeEvaluate(hCompute, p_hNote, hResult, _
iResultLength, bNoteMatchesFormula, bNoteShouldBeDeleted, _
bNoteModified)
If (iReturnValue) Then
Msgbox "Error " & iReturnValue
RunFormula = vResult
Exit Function
End If
lResultAddress = OSLockObject(hResult)
Call MoveMemory(iDataType, Byval lResultAddress, 2)
If (iDataType = TYPE_TEXT_LIST) Then
Dim iEntryCount As Integer
iEntryCount = ListGetNumEntries(Byval lResultAddress, True)
Redim vResult(0 To iEntryCount - 1) As String
Dim iIndex As Integer
For iIndex = 0 To (iEntryCount - 1) Step 1
Dim lTextPointer As Long
Dim iTextLength As Integer
iReturnValue = ListGetText(Byval lResultAddress, _
True, iIndex, lTextPointer, iTextLength)
If (iTextLength <> 0) Then
Dim sText As String
sText = Space$(iTextLength)
Call MoveMemory(Byval sText, Byval lTextPointer, iTextLength)
vResult(iIndex) = translate(OS_TRANSLATE_LMBCS_TO_NATIVE, sText)
Else
vResult(iIndex) = ""
End If
Next iIndex
Else
'Msgbox "Error"
End If
iReturnValue = NSFComputeStop(hCompute)
OSUnlockObject (hResult)
OSMemFree (hResult)
OSUnlockObject (hFormula)
OSMemFree (hFormula)
RunFormula = vResult
End Function
Function Translate( p_iTranslateMode As Integer, p_sInBuffer As String ) As String
sOutBuffer = Space$( 256 )
Call OSTranslate(p_iTranslateMode,p_sInBuffer,Len(p_sInBuffer),sOutBuffer,Len(sOutBuffer))
Translate = Left$( sOutBuffer, Instr( sOutBuffer, Chr$( 0 ) ) -1 )
End Function