=sinister= Posted December 3, 2006 Posted December 3, 2006 (edited) This is frustrating me. I have this code, and it skins my GUI using a Dll, but if it doesn't skin, I want it to show a message box and then exit. Code: Functions Needed: #Region Func BSTR($Str) $Len = StringLen($Str) $Buff = DllCall("Oleaut32.dll", "int", "SysAllocStringLen", "int", 0, "int", $Len) DllCall("Kernel32.dll", "int", "MultiByteToWideChar", "int", 0, "int", 0, "str", $Str, "int", $Len, "ptr", $Buff[0], "int", $Len) Return $Buff[0] EndFunc #EndRegion #Region Func ApplySkin($Location, $Skin) $Dll = DllOpen($Location) DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) DllCall($Dll, "int", "DefineLanguage", "int", 0) DllCall($Dll, "int", "InitDecoration", "int", 1) DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($Skin)) DllCall($Dll, "int", "ApplySkin") EndFunc #EndRegion Regular Code: $Skin = ApplySkin("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = @Error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf I don't understand the concept of the macro @Error. Any ideas would be helpful. --EDIT-- How embarassing... wrong forum =P Edited December 3, 2006 by =sinister=
Valuater Posted December 4, 2006 Posted December 4, 2006 (edited) it depends on what is returned by the function expandcollapse popup$Skin = ApplySkin ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin ($t, $r) Return SetError(-1, -1, -1) EndFunc ;==>ApplySkin $Skin = ApplySkin2 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin2 ($t, $r) Return -1 EndFunc ;==>ApplySkin $Skin = ApplySkin3 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin3 ($t, $r) Return SetError(-1) EndFunc ;==>ApplySkin $Skin = ApplySkin4 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin4 ($t, $r) Local $ret = -1 ; do your dll call ; $ret = DllCall() Return $ret EndFunc ;==>ApplySkin 8) Edited December 4, 2006 by Valuater
=sinister= Posted December 10, 2006 Author Posted December 10, 2006 I don't quite understand what to do with the functions. I did exactly what the code did, and it still said 'Error applying skin' even though it was applied!! expandcollapse popup$Skin = ApplySkin ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return SetError(-1, -1, -1) EndFunc ;==>ApplySkin $Skin = ApplySkin2 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin2 ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return -1 EndFunc ;==>ApplySkin $Skin = ApplySkin3 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin3 ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return SetError(-1) EndFunc ;==>ApplySkin $Skin = ApplySkin4 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin4 ($t, $r) Local $Ret = -1 $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return $Ret EndFunc ;==>ApplySkin
martin Posted December 10, 2006 Posted December 10, 2006 I don't quite understand what to do with the functions. I did exactly what the code did, and it still said 'Error applying skin' even though it was applied!! expandcollapse popup$Skin = ApplySkin ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return SetError(-1, -1, -1) EndFunc ;==>ApplySkin $Skin = ApplySkin2 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin2 ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return -1 EndFunc ;==>ApplySkin $Skin = ApplySkin3 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin3 ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return SetError(-1) EndFunc ;==>ApplySkin $Skin = ApplySkin4 ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf Func ApplySkin4 ($t, $r) Local $Ret = -1 $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) $Ret = DllCall($Dll, "int", "ApplySkin") Return $Ret EndFunc ;==>ApplySkin just a comment that the first few lines are a bit strange $Skin = ApplySkin ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = @error = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf If you change test to $Skin = ApplySkin ("./Data/Skin/Skin.dll", "./Data/Skin/Blue.skf") If $Skin = -1 Then MsgBox(16, "Error", "Error applying skin.") EndIf does it work? The value of $Skin is being comared to a boolean result (@error = -1) which I don't think is what you want. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
=sinister= Posted December 10, 2006 Author Posted December 10, 2006 I'm afraid not. Even if it did work, the other errors would pop in. It checks for 3 errors, so I get 3 message boxes saying "Error applying skin.".
martin Posted December 10, 2006 Posted December 10, 2006 I'm afraid not. Even if it did work, the other errors would pop in. It checks for 3 errors, so I get 3 message boxes saying "Error applying skin.".Some of the functions return -1 and set @error to -1, some retiurn -1 no matter what so checking that the return is -1 is pointless.The function should return a value that is one thing for success and another for some problem, ideally a different number for each problem.EgFunc ApplySkin ($t, $r) $Dll = DllOpen($t) $Ret = DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) $Ret = DllCall($Dll, "int", "DefineLanguage", "int", 0) if @error = -1 then return -1 $Ret = DllCall($Dll, "int", "InitDecoration", "int", 1) if @error = -1 then return -2 $Ret = DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($r)) if @error = -1 then return -3 $Ret = DllCall($Dll, "int", "ApplySkin") if @error = -1 then return -4 Return 1;successEndFunc ;==>ApplySkin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Zedna Posted December 10, 2006 Posted December 10, 2006 (edited) After your DllCall use this function: ;=============================================== ; _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) $p = 0 If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s) return $s EndFunc Edited December 10, 2006 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
=sinister= Posted December 10, 2006 Author Posted December 10, 2006 Zedna, I've tried your function, but nothing happens.... Martin, I used your idea, but how would it know if the error actually happened? Example, i've put in the code: Func ApplySkin($Location, $Skin) $Dll = DllOpen($Location) DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) DllCall($Dll, "int", "DefineLanguage", "int", 0) If @Error = -1 Then Return -1 DllCall($Dll, "int", "InitDecoration", "int", 1) If @Error = -1 Then Return -2 DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($Skin)) If @Error = -1 Then Return -3 DllCall($Dll, "int", "ApplySkin") If @Error = -1 Then Return -4 Return 1 If Return -1 Or Return -2 Or Return -3 Or Return -4 Then MsgBox(16, "Error", "Error applying skin.") EndIf EndFunc But that code doesn't work! o_O and ideas?
martin Posted December 10, 2006 Posted December 10, 2006 (edited) Zedna, I've tried your function, but nothing happens.... Martin, I used your idea, but how would it know if the error actually happened? Example, i've put in the code: Func ApplySkin($Location, $Skin) $Dll = DllOpen($Location) DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) DllCall($Dll, "int", "DefineLanguage", "int", 0) If @Error = -1 Then Return -1 DllCall($Dll, "int", "InitDecoration", "int", 1) If @Error = -1 Then Return -2 DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($Skin)) If @Error = -1 Then Return -3 DllCall($Dll, "int", "ApplySkin") If @Error = -1 Then Return -4 Return 1 If Return -1 Or Return -2 Or Return -3 Or Return -4 Then MsgBox(16, "Error", "Error applying skin.") EndIf EndFunc But that code doesn't work! o_O and ideas? You should leave the code as it was and just look at the returned value. Here it is with comments which might help Func ApplySkin($Location, $Skin) $Dll = DllOpen($Location) DllCall($Dll, "int", "InitLicenKeys", "int", BSTR("0"), "int", BSTR("SKINCRAFTER"), "int", BSTR("SKINCRAFTER.COM"), "int", BSTR("support@skincrafter.com"),"int", BSTR("DEMOSKINCRAFTERLICENCE")) DllCall($Dll, "int", "DefineLanguage", "int", 0) If @Error = -1 Then Return -1; if there was an error then the function returns with the value -1 and goes not further DllCall($Dll, "int", "InitDecoration", "int", 1);this bit won't be executed if there was an error before If @Error = -1 Then Return -2;stop the function and return with -2 DllCall($Dll, "int", "LoadSkinFromFile", "int", BSTR($Skin)) If @Error = -1 Then Return -3; etc....... DllCall($Dll, "int", "ApplySkin") If @Error = -1 Then Return -4 Return 1 EndFunc Then you can have $a = ApplySkin($l,$k) if $a <> 1then;an error ocurred msgbox(0,'the erroror was',$a) endif Sometimes it is inconvenient to return a value which might or mightt not be an error code. For example, if the functin was to find the value of something then there migt be no way to tell if the result was a true answer or an error number. In this case youcan use the @error. Instead of setting the return value to an error code, set @error to some value. Some people might say you should always use @error. Here is an example where you would need to use @error $answer = getthenextnumberforsomething($par1) if @error <> 0 then switch @error case -1:;problem 1 case -2:;problem2 endswitch endif . . . . Func getthenextnumberforsomething($input) if $input > $maxallowedvalue seterror(-1) return 0 else return -1 * $input/pi endif endfunc Edited December 10, 2006 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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