Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#613 Python Object Browser - Unable to view ActiveX CoClass

open
nobody
None
5
2012-09-11
2012-09-10
Omega Weapon
No

Full title: Python Object Browser - Unable to view ActiveX CoClass type library information

I am currently looking into the possiblity of using Python to control some VB6 ActiveX objects used at work. In order to see what COM objects were accessible, I used the combrowse script - however any attempts to browse the CoClass directory of the objects (as compared to the Dispatch directory) fail with the following error:

========================================================

(null)
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Pythonwin\pywin\tools\hierlist.py", line
39, in OnTreeItemExpanding
self.AddSubList(itemHandle, self.GetSubList(item))
File "C:\Python27\lib\site-packages\Pythonwin\pywin\tools\hierlist.py", line
86, in GetSubList
return self.DelegateCall(item.GetSubList)
File "C:\Python27\lib\site-packages\Pythonwin\pywin\tools\hierlist.py", line
73, in DelegateCall
return fn()
File "C:\Python27\Lib\site-packages\win32com\client\combrowse.py", line 239,
n GetSubList
refType = typeinfo.GetRefTypeInfo(typeinfo.GetRefTypeOfImplType(j))
pywintypes.com_error: (-2147312566, 'Error loading type library/DLL.', None, No
e)

========================================================

This is after running the makepy script for the object.

The objects are usable from Microsoft Visual basic 6 Studio (etc) - are there further steps needed to get them useable here? Unfortunately I have no experience with this detail as it basically Just Works with normal VB6 development.

Thanks

Discussion

  • Omega Weapon
    Omega Weapon
    2012-09-10

    Some more detail - using OleView to view the relevant type library, when I try to look at the CoClass, I get the following error:

    ---------------------------
    OLEViewer 2.0 Interface Viewers
    ---------------------------
    Could not decompile selected item
    Error loading type library/DLL.
    TYPE_E_CANTLOADLIBRARY ($80029C4A)
    ---------------------------
    OK
    ---------------------------

    So presumably VB6 is doing something bad, but I dont know what or why it isnt an issue for VB6 :/

     
  • Mark Hammond
    Mark Hammond
    2012-09-10

    • status: open --> pending
     
  • Mark Hammond
    Mark Hammond
    2012-09-10

    I doubt there is much pywin32 can do to resolve this, especially without more details about the objects in question.

     
  • Omega Weapon
    Omega Weapon
    2012-09-11

    • status: pending --> open
     
  • Omega Weapon
    Omega Weapon
    2012-09-11

    Right, I have found a colleague with COM/ActiveX experience - this dll implements two interfaces, IManager and ITEventStatus. Every method on the actual class is marked Private, even those implementing the interfaces. So presumably the interface methods are the only public methods available on the object.

    The two interfaces are registered via type libraries (have both the tlb and the idl), but importantly I don't have the source code to the original VB6 projects that implemented the interfaces.

    In the idl header, the source library for IManager is quoted as spIManager, and a UUID is given that does not exist in the registry of any of our machines. So presumably the failure happens when the missing dll is looked up?

    Here is the idl of one of the interfaces as an example:

    ======================================================

    // TypeLib : IManager.idl
    // TargetFile : IManager.TLB
    //
    // Version 1.0
    // Author :
    // UUID Usage:
    // ae40bf60-dd04-11d6-a558-000347d25793 : library spIManager
    // bc185b30-dd04-11d6-a558-000347d25793 : interface IManager

    [
    uuid(ae40bf60-dd04-11d6-a558-000347d25793),
    version(1.0),
    helpstring("sp Manager Interface")
    ]
    library tsIManager
    {
    // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("Stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface IManager;

    [
    uuid(bc185b30-dd04-11d6-a558-000347d25793),
    version(1.0),
    nonextensible,
    oleautomation
    ]
    interface IManager : IUnKnown {
    [id(0x60030000)]
    HRESULT Start([out, retval] VARIANT_BOOL* );
    [id(0x60030001)]
    HRESULT Halt(
    [in, optional, defaultvalue(0)] VARIANT_BOOL vbSoftStop,
    [out, retval] VARIANT_BOOL* );
    };
    };

    ======================================================

     
  • Omega Weapon
    Omega Weapon
    2012-09-11

    The OleView error about being unable to load dlls is rubbish - this was simply a case of some of the type libraries not being registered on the system... the COM browser can now cope with browsing too.

    However, I'm still not able to call the Start method (from IManager) on the 'spManagerTEvent.TEventManager' object - apparently it doesnt exist.

    I ran makepy on the object and got the attached generated code - this is my first time reading such a file, but it doesnt look like its picked up any VB6 interfaces?

     
  • Mark Hammond
    Mark Hammond
    2012-09-13

    It hasn't picked up much at all, but I can't even speculate as to why that would be. If you can use the Microsoft OLE viewer and dump the source of the typelib and attach it here I might get more clues. Note however that if VB6 is set to create IDispatch objects it generally works fine - there is one vb6 created binary used in the test suite. Sadly I haven't used VB6 for so long that the details escape me.

     
  • Omega Weapon
    Omega Weapon
    2012-09-13

     
    Attachments
  • Omega Weapon
    Omega Weapon
    2012-09-13

     
    Attachments
  • Omega Weapon
    Omega Weapon
    2012-09-13

     
    Attachments
  • Omega Weapon
    Omega Weapon
    2012-09-13

    I have attached the relevant IDL files (would be nice if OLEView allowed you just to save one file that then allowed you to browse the hierarchy like I can on this machine...).

    The test suite looks to be PyCOMVBTest, but I cant find that anywhere?

     
  • Omega Weapon
    Omega Weapon
    2012-09-14

    I have had a play around with the VB6 test project (this doesnt seem to be included with the source zip). I had to recreate the PyCOMVBTest project as Visual Studio failed to find any of the class files (even though they were in the same directory...), and when I tried to test it with the VBTest project, I get the 'Object required' error 424 on the attempt to set the value of an item of c in Sub Main, so it isnt going too well.

    I'll have another try on Monday, hopefully testing the Interface code as well. I can't comment on why the IDispatch interface is empty, beyond what Ive already said about the objects.

     
  • Omega Weapon
    Omega Weapon
    2012-09-14

    Got a chance to look some more at this. Changing c from Collection to Object gives a much better error:

    ====================

    Run-time error '451':

    Property let procedure not defined and property get procedure did not return an object

    ====================

    Tester.CollectionProperty has Set and Get - presumably VB6 is messing around with Tester.CollectionProperty rather than the underlying Collection object that is returned?

     
  • Omega Weapon
    Omega Weapon
    2012-09-14

    I have now tested the interface code - its broken (getting and setting the value returns the wrong value), but it does give me another example of an interface.

    As I said on '2012-09-11 02:55:38 PDT', all methods on spManagerTEvent.TEventManager are Private - in the example PyComTestImplementation class, the visibility of the functions isn't specified - which means they default to Public. Changing them to Private also causes an empty IDispatch.

    This still isnt the end of the story however, as I can successfully call win32com.client.Dispatch('PyCOMVBTest.PyComTestImplementation') even with the empty IDispatch...