Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
; Example code ; First try dllname = StrCat(DirWindows(1),"secur32.dll") NameFormat = 0 ; Force an error lpNameBufferSize = 1024 lpNameBuffer = BinaryAlloc(lpNameBufferSize) nSizeBufferSize = 4 nSizeBuffer = BinaryAlloc(nSizeBufferSize) errorvalue = 0 BinaryEodSet(lpNameBuffer,lpNameBufferSize) BinaryEodSet(nSizeBuffer,nSizeBufferSize) BinaryPoke4(nSizeBuffer,0,lpNameBufferSize) result = DllCall(dllname,long:"GetUserNameExA",long:NameFormat,lpbinary:lpNameBuffer,lpbinary:nSizeBuffer) If !result errorvalue = DllLastError() Endif ; Read info from buffers here... ; Code removed, I'm interested in the lasterror value BinaryFree(lpNameBuffer) BinaryFree(nSizeBuffer) Message("DllLastError value",errorvalue) ; Second try ; Same code, DllLastError() replaced with a DllCall dllname = StrCat(DirWindows(1),"secur32.dll") NameFormat = 0 ; Force an error lpNameBufferSize = 1024 lpNameBuffer = BinaryAlloc(lpNameBufferSize) nSizeBufferSize = 4 nSizeBuffer = BinaryAlloc(nSizeBufferSize) errorvalue = 0 BinaryEodSet(lpNameBuffer,lpNameBufferSize) BinaryEodSet(nSizeBuffer,nSizeBufferSize) BinaryPoke4(nSizeBuffer,0,lpNameBufferSize) result = DllCall(dllname,long:"GetUserNameExA",long:NameFormat,lpbinary:lpNameBuffer,lpbinary:nSizeBuffer) If !result ; GetLastError function: DWORD GetLastError(void); dllname = StrCat(DirWindows(1),"kernel32.dll") errorvalue = DllCall(dllname,long:"GetLastError") Endif ; Read info from buffers here... ; Code removed, I'm interested in the lasterror value BinaryFree(lpNameBuffer) BinaryFree(nSizeBuffer) Message("GetLastError value",errorvalue) ExitUsing Winbatch 2004D on Windows 2000 SP4
When you are using DllCall() or DllCallCDecl() in WinBatch, a lot of other Win32 API functions can be called [that will disturb the system error code] between when DllCall*() is called and when you'd be all to use DllCall() again to call GetLastError(). What WinBatch is doing is that immediately after it calls a function using DllCall*(), it then calls GetLastError() and stores the result so that DllLastError() can return it when called.
Article ID: W16431
File Created: 2005:02:18:12:20:30
Last Updated: 2005:02:18:12:20:30