C0sgar Posted September 4, 2018 Posted September 4, 2018 Hello, I try to create a simple autoit picture viewer that loads a picture (or multiple in the future) from a selcted path and displays it in a small gui. I have taken a script from this forum that another User posted and modified it slightly. The GUI works fine, but when i load a picture i get the following error message: "33) : ==> Variable must be of type "Object".: $oPreview.ShowFile ($sFile, 1)". Here is the code: expandcollapse popup#include <GUIConstants.au3> Opt("GUIOnEventMode", True) $oPreview = ObjCreate("Preview.Preview.0") $GUI = GUICreate("Preview Test 2") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $test2=IsObj($oPreview) ConsoleWrite($test2) $Button1 = GUICtrlCreateButton("Bild öffnen", 50, 355, 60, 20) GUICtrlSetOnEvent(-1, "_LoadPicture") $Button2 = GUICtrlCreateButton("-", 150, 355, 20, 20) GUICtrlSetOnEvent(-1, "_Zoom") $Button3 = GUICtrlCreateButton("+", 280, 355, 20, 20) GUICtrlSetOnEvent(-1, "_Zoom") $GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380) GUICtrlSetState($GUI_OBJ, $GUI_NOFOCUS) GUISetState() While 1 Sleep(100) WEnd Func _LoadPicture() $sFile = FileOpenDialog("Bild öffnen", @ScriptDir , "Image files (*.bmp;*.jpg;*.jpeg;*.tif)", 1) If @error Then Return $oPreview.ShowFile ($sFile, 1) EndFunc ;==>_LoadPicture Func _Zoom() Switch @GUI_CtrlId Case $Button2 $oPreview.Zoom (-1) Case $Button3 $oPreview.Zoom (1) EndSwitch EndFunc ;==>_Zoom Func _Exit() Exit EndFunc ;==>_Exit Any idea? I am new to AutoIt so I might understand something wrong here.
ajag Posted September 4, 2018 Posted September 4, 2018 That means, that $oPreview isn't an object. You have to do some error checking when creating an object like $oPreview = ObjCreate("Preview.Preview.0") If Not @error Then MsgBox(0, "OK", "ObjCreate successful !") Else MsgBox(0, "ERROR ", "Failed to create Object. Error code: " & Hex(@error, 8)) EndIf pixelsearch 1 Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1)
pixelsearch Posted September 4, 2018 Posted September 4, 2018 Thanks to ajag, the error returned is : 0x800401F3, which means "Invalid class string" The ObjCreate help file states : classname => The class of the object in the following format: "appname.objectype" So Just drop ".0" from $oPreview = ObjCreate("Preview.Preview.0"), ending with ObjCreate("Preview.Preview") Now all works fine, no more error, happy pictures viewing "I think you are searching a bug where there is no bug... don't listen to bad advice."
C0sgar Posted September 5, 2018 Author Posted September 5, 2018 Hello, thanks for your replys and the help! Sadly your solution does not work for me. At first I implemented the error checking and got the aforementioned error code 800401F3. A little researched told me that this is most likey a DLL register issue because the script cant find the class name in the dll. So I tried to find the associated dll and it seems to be "shimgvw.dll". But regsvr32 does not work. Error Message: "The module "shimgvw.dll" was loaded but the entry-point DllRegisterServer was not found. Make sure that "shimgvw.dll" is a valid DLL or OCX file adn then try again." I replaced the dll in case it was corrupted but to no avail. Just dropping the .0 also yielded no results and i still get the same error message. On the plus side I slowly begin to understand how this works.
pixelsearch Posted September 5, 2018 Posted September 5, 2018 (edited) @C0sgar : this is weird, i wish someone explains why it works on my XP computer. Just try something else, a ".1" extension as shown in the following pic, because strangely ".1" works too for me : What didn't work for me is all the following : PS: $obj comes from here : $Sobj = "Preview.Preview.1" $oPreview = ObjCreate($Sobj) If Not @error Then MsgBox(0, "OK", "ObjCreate successful !" & @CRLF & _ "$Sobj = " & $Sobj) Else MsgBox(0, "ERROR ", "Failed to create Object." & @CRLF & _ "Error code: " & Hex(@error, 8) & @CRLF & _ "$Sobj = " & $Sobj) EndIf Edited September 5, 2018 by pixelsearch "I think you are searching a bug where there is no bug... don't listen to bad advice."
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