Hi all,

I'm trying to call a function in the Novell client32 version 4.91.5.20080922. The dll is the "netwin32.dll". Running on WinXP.
I'm getting a ERROR_INVALID_HANDLE when I try and call NWDSList or NWDSRead.

here is the code I'm using:

It's in Autohotkey.. http://www.autohotkey.com/ , but the format is pretty simple:
http://www.autohotkey.com/docs/commands/DllCall.htm

Everything works great up until the "NWDSList" call.... Then I get a "access denied" code for the return code, and a "6" for "A_LastError", which translates to a windows system error of "ERROR_INVALID_HANDLE".


if I print the inputs to the call, they seem to be fine??
ie:
ctx, = 1
me, = .CN=USERNAME.OU=CONTEXT.O=CONTEXT
%iterread%, = NO_MORE_ITERATIONS

Which leads me to believe that my issue may be with the handling of the output buffer....
Any ideas???
Any tips/pointers on the inputs for NWDSList/NWDSRead that I should be aware of ???


************************************************** **********
; initializes NWCallsInit
nwrc :=DllCall("calwin32\NWCallsInit", UInt, 0, UInt, 0 )
If nwrc <> 0
{
MsgBox Error: NWCallsInit was not successful. That's all I know.
Exit
}


; pre-load NetWare netwin32 utility DLL
hModule := DllCall("LoadLibrary", "str", "netwin32.Dll")
if !hModule {
MsgBox Error: Can't load netwin32 DLL. are you SURE the Novell client is on this machine?
Exit
}


; Create new context handle
cCode := DllCall("netwin32.Dll\NWDSCreateContextHandle", "Int*", ctx, "Int")
if cCode <> 0
{
MsgBox Error: NWDSCreateContextHandle was not successful. %cCode%.
Exit
}

; Authenticated ??
cCode := DllCall("netwin32.Dll\NWIsDSAuthenticated", UInt, 0)
if cCode <> 1
{
MsgBox Error: you are not logged in. %cCode%.
Exit
}


; NWDSSetContext -- set context to root
retcode := DllCall("netwin32.Dll\NWDSSetContext", "Int", ctx, "Int", 3, "Int", DS_ROOT_NAME)
;msgbox, %Errorlevel%
If retcode <> 0
{
MsgBox, NWDSSetContext returned error %retcode%
}


;get default DS tree name from our context (root)
VarSetCapacity(DS_ROOT_NAME, 48)
retcode := DllCall("netwin32.Dll\NWDSGetContext", "Int", ctx, "Int", 11, "Str", DS_ROOT_NAME)
If retcode <> 0
{
MsgBox, NWDSGetContext returned error %retcode%
}
; this produces the correct tree name
;msgbox, %DS_ROOT_NAME%


; NWDS who am I.
VarSetCapacity(me, 48)
cCode2 := DllCall("netwin32.Dll\NWDSWhoAmI", "Int", ctx, "Str", me)
if cCode2 <> 0
{
MsgBox Error: NWDSWhoAmI was not successful. %cCode2%.
Exit
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
; this prints CN=USERNAME (with context)
;msgbox, %me%

;add leading "." to CN and a CR to the end
me = .%me%`n

msgbox, %me%

MAX_MESSAGE_LEN = 64512
DEFAULT_MESSAGE_LEN = 4096

iterHandle = NO_MORE_ITERATIONS
iterread = NO_MORE_ITERATIONS


; setup inbuf
retcode := DllCall("netwin32.Dll\NWDSAllocBuf", "*UShort", %DEFAULT_MESSAGE_LEN%, "*Int", inBuf)
;msgbox, %Errorlevel%
If retcode <> 0
{
MsgBox, Alloc Buffer inbuf returned error %retcode%
}


; setup outbuf
retcode := DllCall("netwin32.Dll\NWDSAllocBuf", "*UShort", %DEFAULT_MESSAGE_LEN%, "*Int", outBuf)
;msgbox, %Errorlevel%
If retcode <> 0
{
MsgBox, Alloc Buffer outbuf returned error %retcode%
}


; initialize the inBuf
retcode := DllCall("netwin32.Dll\NWDSInitBuf", "Int", ctx, "UInt", DSV_READ, "Int", inBuf)
;msgbox, %Errorlevel%
If retcode <> 0
{
MsgBox, Init Buffer inbuf returned error %retcode%
}


; Write "Group Membership" to the inbuf buffer
retcode := DllCall("netwin32.Dll\NWDSPutAttrName", "Int", ctx, "Int", inBuf, "Str", "Group Membership")
;msgbox, %Errorlevel%
If retcode <> 0
{
MsgBox, Put Attrib Name "Group Membership" returned error %retcode%
}



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
;;; all good until this call.....which produces a windows system ERROR_INVALID_HANDLE error in %A_LastError%

; NWDSlist
retcode := DllCall("netwin32.Dll\NWDSList", "Int", ctx, "Str", me, "Int", %iterread%, "*Int", outBuf)
msgbox, %Errorlevel%
msgbox, %A_LastError%
If retcode <> 0
{
MsgBox, NWDSlist returned error %retcode%
}
************************************************** ************************