Sign in to follow this  
Followers 0
Jeffoo

Invalid class string?

5 posts in this topic

I am trying to create a COM object in my code however it can't seem to find the class path. I am using (libraryname).(classname) like I have in visual basic applications that use this same object. I am pretty sure I have the name right.

Anyways. There are actually two dll's one I believe is a com dll (since it has a LIBOCX.dll and I find it in the OLE/COM viewer) and the other is not. Now when I open the OLE/COM Object Viewer I do not see the library anywhere under Object Classes however I do see it under Type Libraries. What is the difference or is there any? Or is there any way I can specifically register this com library for my application?

Share this post


Link to post
Share on other sites



Should I have put this in a different forum category?

Share this post


Link to post
Share on other sites

$dll = DllOpen("C:\ACVSDK\ACVSDK.dll")
Global $g_eventerror = 0
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ;
$oShell = ObjCreate("ACVOCXLib.TxtrCtl")    

MsgBox(0, "", @error)

$oShell.Init
MsgBox(0, "", @error)

$oShell.Term
DllClose($dll)



Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription )

   $g_eventerror = 1 ; something to check for when this function returns
Endfunc

The first error it encounters is an invalid class string, then the next is "variable must be of type object" but I can understand that if the object is never created. I have tried putting the DLL in the same directory as the autoit script but it still does not work.

Share this post


Link to post
Share on other sites

$dll = DllOpen("C:\ACVSDK\ACVSDK.dll")
Global $g_eventerror = 0
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ;
$oShell = ObjCreate("ACVOCXLib.TxtrCtl")    

MsgBox(0, "", @error)

$oShell.Init
MsgBox(0, "", @error)

$oShell.Term
DllClose($dll)



Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription )

   $g_eventerror = 1 ; something to check for when this function returns
Endfunc

The first error it encounters is an invalid class string, then the next is "variable must be of type object" but I can understand that if the object is never created. I have tried putting the DLL in the same directory as the autoit script but it still does not work.

You have to register that server (COM server, that is). There are two ways; regsvr.exe or this function:
Func _RegisterServer($sDll)
    Local $fInit, $fError
    Local $aCall = DllCall("ole32.dll", "long", "OleInitialize", "ptr", 0)
    If Not @error Then $fInit = $aCall[0] <> 1 ; The COM library is already initialized
    $aCall = DllCall($sDll, "long", "DllRegisterServer")
    If @error Then $fError = True
    If $fInit Then DllCall("ole32.dll", "none", "OleUninitialize")
    If $fError Then Return SetError(2, 0, False)
    Return SetError($aCall[0] <> 0, $aCall[0], $aCall[0] = 0)
EndFunc

In both cases admin privileges are needed.

Another way that's much more simpler and yet much more advanced is using AutoItObject and function _AutoItObject_ObjCreateEx. In this case you don't need admin privileges. Dll is accessed just as with DllCall. Every method is exported function.

In the help file for AutoItObject you have an example for this function.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0