Is it possible for some one to post...
Articles and Tips: qna
01 Oct 2003
Q.
Is it possible for some one to post a code snippet to read and write to SYN_OCTET_LIST. I am after is "app:fs rights path" attribute. The Novell OCX will not read it so I will need to use the dll's.
A.
It's a linked list, so with Visual Basic you must use pointer functions. I wouldn't want you to try to write to it, since it's a proprietary field. but here's a rough sample to read a linked list syn_octet_list. I haven't tested it much, but it seems to work on my test field.
Option Explicit
Private Sub Command1_Click() Dim retCode As Long, contextHandle As Long Dim defContext As String Dim bytename(256) As Byte Dim inBuf As Buf_T, outBuf As Buf_T Dim pInBuf As Long, pOutBuf As Long Dim iterHandle As Long, totalAttrs As Long, totalValues As Long, syntaxID As Long Dim attrValSize As Long Dim i As Integer, j As Integer Dim tempStr As String Dim tempArray() As Byte Dim ptr As Long Dim lConvInfo As Llconv
Dim list As octet_list
iterHandle = NO_MORE_ITERATIONS
' initialize the library retCode = NWCallsInit(0, 0) If retCode <> 0 Then MsgBox "NWcallsInit failed: " + retCode, vbCritical GoTo done End If
' set up unicode tables Call NWLlocaleconv(lConvInfo) retCode = NWInitUnicodeTables(lConvInfo.country_id, lConvInfo.code_page) If retCode <> 0 Then MsgBox "NWcallsInit failed: " + retCode, vbCritical GoTo done End If
' create DS context handle retCode = NWDSCreateContextHandle(contextHandle) If retCode <> 0 Then MsgBox "NWDSCreateContextHandle failed: " + retCode, vbCritical GoTo done End If
defContext = ContextText.text + chr(0) Call StringToByteArray(bytename, defContext) retCode = NWDSSetContext(contextHandle, DCK_NAME_CONTEXT, VarPtr(bytename(0))) If retCode <> 0 Then MsgBox "NWDSSetContext failed: " + retCode, vbCritical GoTo done End If
pInBuf = VarPtr(inBuf) pOutBuf = VarPtr(outBuf)
retCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, pInBuf) If retCode <> 0 Then MsgBox "NWDSAllocBuf failed: " + retCode, vbCritical GoTo done End If
retCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, pOutBuf) If retCode <> 0 Then MsgBox "NWDSAllocBuf failed: " + retCode, vbCritical GoTo done End If
retCode = NWDSInitBuf(contextHandle, DSV_READ, pInBuf) If retCode <> 0 Then MsgBox "NWDSInitBuf failed: " & retCode, vbCritical GoTo done End If
retCode = NWDSPutAttrName(contextHandle, pInBuf, AttributeText.text +chr(0)) If retCode <> 0 Then MsgBox "NWDSPutAttrName failed: " & retCode, vbCritical GoTo done End If
Do
retCode = NWDSRead(contextHandle, ObjectText.text + chr(0), DS_ATTRIBUTE_VALUES, 0, pInBuf, iterHandle, pOutBuf) If retCode <> 0 Then MsgBox "NWDSRead failed: " & retCode, vbCritical GoTo done End If
retCode = NWDSGetAttrCount(contextHandle, pOutBuf, totalAttrs)
If retCode <> 0 Then MsgBox "NWDSGetAttrCount failed: " & retCode, vbCritical GoTo done End If If totalAttrs < 1 Then MsgBox "No Attributes Returned" GoTo done End If
retCode = NWDSGetAttrName(contextHandle, pOutBuf, Name, totalValues, syntaxID) If retCode <> 0 Then MsgBox "NWDSGetAttrCount failed: " & retCode, vbCritical GoTo done End If
If syntaxID <> SYN_OCTET_LIST Then MsgBox "Attribute is not of type SYN_OCTET_LIST" GoTo done End If
For i = 0 To totalValues - 1 retCode = NWDSComputeAttrValSize(contextHandle, pOutBuf, syntaxID, attrValSize) If retCode <> 0 Then MsgBox "NWDSComputeAttrValSize failed: " & retCode, vbCritical GoTo done End If
j = LenB(list)
ReDim tempArray(attrValSize - 1) retCode = NWDSGetAttrVal(contextHandle, pOutBuf, SYN_OCTET_LIST, tempArray(0)) If retCode <> 0 Then MsgBox "NWDSGetAttrVal failed: " & retCode, vbCritical GoTo done End If
ptr = VarPtr(list)
Call CopyMemory(ptr, VarPtr(tempArray(0)), j)
Do While ptr <> 0 ptr = list.next ReDim tempArray(list.Length) Call CopyMemory(VarPtr(tempArray(0)), list.data, list.Length) Call ByteArrayToHexString(tempStr, tempArray) MsgBox tempStr If list.next <> 0 Then Call CopyMemory(VarPtr(list), list.next, j) End If Loop
Next
Loop While (iterHandle <> NO_MORE_ITERATIONS) And (retCode = 0)
done: If contextHandle <> 0 Then NWDSFreeContext (contextHandle) End If
If pInBuf <> 0 Then NWDSFreeBuf (pInBuf) End If
If pInBuf <> 0 Then NWDSFreeBuf (pOutBuf) End If
NWFreeUnicodeTables
NWCallsTerm 0
MsgBox "done"
End Sub
Private Sub Form_Load() ContextText.text = "[root]" ObjectText.text = ".testclass.novell" AttributeText.text = "testOctetList" ContextText.Refresh ObjectText.Refresh AttributeText.Refresh End Sub
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.