VicTT Posted June 14, 2011 Posted June 14, 2011 (edited) My code is the following: expandcollapse popup#include <Array.au3> Global $dllhandle=DllOpen("kernel32.dll") Func DebugDllCall($cstring) $parameter_arr=StringSplit($cstring,";",1) $parameter_arr[0]="CallArgArray" _ArrayDisplay($parameter_arr) Local $ret=Call("DllCall",$parameter_arr) if @error then Local $errorcode=@error ConsoleWrite(DllCallErrorTranslate($errorcode)) Return SetError(1,$errorcode,0) ;DllCall error endif if $ret[0]=0 then ConsoleWrite(_WinAPI_GetLastErrorMessage()) Return SetError(2,-1,0) endif Return $ret EndFunc Func DllCallErrorTranslate($errorcode) Select Case $errorcode=1 Return "Unable to use the DLL file" Case $errorcode=2 Return "Unknown return type" Case $errorcode=3 Return "Function not found in DLL file" Case $errorcode=4 Return "Bad number of parameters" EndSelect EndFunc Func API_GlobalAlloc($nrbytes,$movable=1,$zinit=1) Local $flags=0 if $zinit then $flags=BitOR($flags,0x0040) if $movable then $flags=BitOR($flags,0x0002) $ret=DebugDllCall($dllhandle&";ptr;GlobalAlloc;uint;"&$flags&";dword;"&$nrbytes) ;MsgBox(0,"",$ret) Return $ret[0] EndFunc Func API_GlobalSize($ptr) $ret=DebugDllCall($dllhandle&";dword;GlobalSize;ptr;"&$ptr) Return $ret[0] EndFunc $h=API_GlobalAlloc(1024) ConsoleWrite(API_GlobalSize($h)) I'm running this on Vista, latest official AutoIt version. The problem occurs when API_GlobalAlloc calls DebugDllCall, which takes the ";"-delimited string and makes a parameter array for the call function from it. It works when I just DllCall and supply all of the parameters. Otherwise I get "Bad Number Of Parameters". _ArrayDisplay within DebugDllCall looks good. What am I doing wrong? EDIT: Error in my code: "Case $errorcode" should have been "Case $errorcode=4", which is the reason I was getting "Bad number of parameters". EDIT2: By adding MsgBox(0,"",@extended) after $ret=DebugDllCall($dllhandle&";ptr;GlobalAlloc;uint;"&$flags&";dword;"&$nrbytes) I get @extended=57005 (which is the @error returned by DllCall), and the documentation only provides an explanation for errors 1,2,3 and 4.What the heck does that mean? EDIT3: Apparently, I'm getting an errorcode from the call function, @error=0xDEAD=57005, saying that either "DllCall" isn't a valid function name, or I'm calling it with the wrong number of parameters. Still, from the _ArrayDisplay, that doesn't seem to be the case. EDIT4: Conclusion: I'm just an idiot that didn't rtfm. "Call" can't call "DllCall" because it can't call built-in AutoIt functions as mentioned in the Call Function Reference: "The function cannot be a built-in AutoIt function or plug-in function.". I was about to file a bug report. Meh.. Edited June 14, 2011 by VicTT Quote Together we might liveDivided we must fall
VicTT Posted June 14, 2011 Author Posted June 14, 2011 Just in case anyone cares, or needs the working code: This works after refactoring: expandcollapse popup#include <Array.au3> Global $dllhandle=DllOpen("kernel32.dll") Func DebugDllCall($ret,$error,$extended) if $error then ConsoleWrite("DllCall error: "&DllCallErrorTranslate($error)) Return SetError(1,$error,0) ;DllCall error endif if $ret[0]=0 then ConsoleWrite("API error: "&_WinAPI_GetLastErrorMessage()) Return SetError(2,-1,0) endif Return $ret EndFunc Func DllCallErrorTranslate($errorcode) Select Case $errorcode=1 Return "Unable to use the DLL file" Case $errorcode=2 Return "Unknown return type" Case $errorcode=3 Return "Function not found in DLL file" Case $errorcode=4 Return "Bad number of parameters" Case Else Return $errorcode EndSelect EndFunc Func API_GlobalAlloc($nrbytes,$movable=1,$zinit=1) Local $flags=0 if $zinit then $flags=BitOR($flags,0x0040) if $movable then $flags=BitOR($flags,0x0002) $ret=DllCall($dllhandle,"ptr","GlobalAlloc","uint",$flags,"dword",$nrbytes) DebugDllCall($ret,@error,@extended) Return $ret[0] EndFunc Func API_GlobalSize($ptr) $ret=DllCall($dllhandle,"dword","GlobalSize","ptr",$ptr) DebugDllCall($ret,@error,@extended) Return $ret[0] EndFunc $h=API_GlobalAlloc(1028) ConsoleWrite(API_GlobalSize($h)) Quote Together we might liveDivided we must fall
veryBeginner Posted February 29, 2012 Posted February 29, 2012 Hi. Could you exactly outline the refactory you done to resolve "@extended=57005".
Moderators Melba23 Posted February 29, 2012 Moderators Posted February 29, 2012 veryBeginner,Read the "Call" page in the Help file - it explains why you get @error = 0xDEAD (= 57005) and @extended = 0xBEEF (= 48879) in certain cases. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now