Jump to content

Recommended Posts

Posted

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:
 

#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.

Posted

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

 

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Posted

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."

Posted

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.

 

 

 

 

Posted (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 :

5b8fe6f4a8ac0_objcreation-goodwithoutlast.orwith.1.jpg.4b399ef00349cfe9ef1b629bfdd194d5.jpg

What didn't work for me is all the following :

5b8fe6b8aacd9_objcreation-badwithanythingelse.jpg.4df58c396f272932dbcf81e9fbd5bca0.jpg

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 by pixelsearch

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...