PaulIA Posted September 22, 2006 Share Posted September 22, 2006 I'm trying to write some AutoIt code and I'm making a lot of calls to DllCall (followed by a lot of code for error checking). I'd like to know if there is a way to create a "wrapper" function around DllCall where I can call the wrapper with the DllCall parameters, have the wrapper make the call, check for errors and return the DllCall results. Given an example function definition: Func MyDllCall($hDLL, $sRetType, $sFunction, $sType1="", $sParam1="", $sType2="", $sParam2="", $sType3="", $sParam3="", $sType4="", $sParam4="", $sType5="", $sParam5="", $sType6="", $sParam6="", $sType7="", $sParam7="", $sType8="", $sParam8="", $sType9="", $sParam9="") and this call to the function: $aResults = MyDllCall($hKernel32, "int", "GetLastError") what would the body of MyDllCall look like? Or is there no way to do this? Any hints/suggestions would be greatly appreciated. Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
GaryFrost Posted September 22, 2006 Share Posted September 22, 2006 I'm trying to write some AutoIt code and I'm making a lot of calls to DllCall (followed by a lot of code for error checking). I'd like to know if there is a way to create a "wrapper" function around DllCall where I can call the wrapper with the DllCall parameters, have the wrapper make the call, check for errors and return the DllCall results. Given an example function definition: Func MyDllCall($hDLL, $sRetType, $sFunction, $sType1="", $sParam1="", $sType2="", $sParam2="", $sType3="", $sParam3="", $sType4="", $sParam4="", $sType5="", $sParam5="", $sType6="", $sParam6="", $sType7="", $sParam7="", $sType8="", $sParam8="", $sType9="", $sParam9="") and this call to the function: $aResults = MyDllCall($hKernel32, "int", "GetLastError") what would the body of MyDllCall look like? Or is there no way to do this? Any hints/suggestions would be greatly appreciated. If your repeatedly calling the same API it's not to hard see: http://www.autoitscript.com/forum/index.ph...st&p=227702 But to make one for All API's to me seems like more work than it would be worth. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
PaulIA Posted September 22, 2006 Author Share Posted September 22, 2006 You're probably right. It might be easier just to create a function called _MyGetLastError and be done with it. I was just wondering if anybody had done this before and come up with a clever way to do it. Thanks for the input. Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
GaryFrost Posted September 22, 2006 Share Posted September 22, 2006 You're probably right. It might be easier just to create a function called _MyGetLastError and be done with it. I was just wondering if anybody had done this before and come up with a clever way to do it. Thanks for the input. that one was created a long time ago ;=============================================== ; _GetLastErrorMessage($DisplayMsgBox="") ; Format the last windows error as a string and return it ; if $DisplayMsgBox <> "" Then it will display a message box w/ the error ; Return Window's error as a string ;=============================================== Func _GetLastErrorMessage($DisplayMsgBox="") Local $ret,$s Local $p = DllStructCreate("char[4096]") Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 If @error Then Return "" $ret = DllCall("Kernel32.dll","int","GetLastError") $ret = DllCall("kernel32.dll","int","FormatMessage", _ "int",$FORMAT_MESSAGE_FROM_SYSTEM, _ "ptr",0, _ "int",$ret[0], _ "int",0, _ "ptr",DllStructGetPtr($p), _ "int",4096, _ "ptr",0) $s = DllStructGetData($p,1) If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s) return $s EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
PaulIA Posted September 23, 2006 Author Share Posted September 23, 2006 that one was created a long time agoYes, I was trying to use a simple example. What I'm actually after is something that does a bit more error checking after the DllCalls. I know it's very rare that calls actually fail, but I'd rather spend the time putting the error checking in for that one time I need it. Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
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