There are some tools that can recover typelib data from binaries such as
unmidle (http://www.immunitysec.com/downloads/unmidl_1_2.tgz) or muddle
(don't have a link handy).

mike

-----Original Message-----
From: Jason R. Coombs [mailto:jar...@jaraco.com] 
Sent: Wednesday, May 27, 2009 4:12 AM
To: comtypes-users@lists.sourceforge.net
Subject: Re: [comtypes-users] How to generate Interface when no typelib or
idl?

Thanks very much.  I struggled with this for a long time, but my lack of
experience with COM left me searching for the wrong things.

For the sake of completeness, I went ahead and tried compiling the .idl you
supplied.  Sure enough, just compiling it with midl produced a .tlb that I
could then call with comtypes GetModule... though I'll be using the first
approach and using the typelib already generated by another.

Thanks for the thorough answer, and for ctypes.

Jason

> -----Original Message-----
> From: Thomas Heller [mailto:thel...@ctypes.org]
> Sent: Wednesday, 27 May, 2009 04:00
> To: comtypes-users@lists.sourceforge.net
> Subject: Re: [comtypes-users] How to generate Interface when no typelib
> or idl?
> 
> Jason R. Coombs schrieb:
> > I'm trying to port VideoCapture from an extension module to a pure-
> python
> > module based on comtypes.
> >
> > I've started by converting the following:
> >
> >     hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,
> CLSCTX_INPROC,
> >
> >                           IID_ICaptureGraphBuilder2, (void **)&self-
> >ob_pBuilder);
> >
> >     hr = self->ob_pBuilder->SetFiltergraph(self->ob_pGraph);
> >
> >
> > to the following using comtypes:
> >
> >                                 self.graph_builder =
> > CreateObject(CLSID_CaptureGraphBuilder2, CLSCTX_INPROC)
> >
> > self.graph_builder.SetFiltergraph(self.filter_graph)
> >
> > The problem I encounter is the creation of the graph_builder doesn't
> have
> > any type information, so SetFiltergraph fails.  It has no interface,
> so gets
> > created as an IUnknown.
> >
> > I can find in the SDK the .idl that contains the definition for
> > ICaptureGraphBuilder2 (axextend.idl) and other interfaces I'll need.
> The
> > docs indicate that the best way to generate the Interface classes is
> to
> > create a temporary type lib from the IDL. Can you describe or point
> me to a
> > description of how one would go about creating a temporary type lib?
> Is it
> > possible that there's already a type lib created for some other
> purpose
> > lying around, and if so, how would I locate it?
> 
> Often, this has already been done.  A little googling found this page
> which has a DirectShow.tlb type library:
> 
> http://www.kohsuke.org/dotnet/directshowTypelib/
> 
> And it seems to work:
> 
> Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from comtypes.client import GetModule
> >>> GetModule("DirectShow.tlb")
> # Generating comtypes.gen._24BC6711_3881_420F_8299_34DA1026D31E_0_1_0
> # Generating comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0
> # Generating comtypes.gen.stdole
> # Generating comtypes.gen.DirectShowLib
> <module 'comtypes.gen.DirectShowLib' from
> 'comtypes\gen\_24BC6711_3881_420F_8299_34DA1026D31E_0_1_0.py'>
> >>> from comtypes.client import CreateObject
> >>> from comtypes.gen import DirectShowLib
> >>> builder = CreateObject(DirectShowLib.CaptureGraphBuilder2)
> >>> print builder
> <POINTER(ICaptureGraphBuilder2) ptr=0x927294 at a939e0>
> >>> builder.SetFilterGraph
> <bound method POINTER(ICaptureGraphBuilder2).SetFiltergraph of
> <POINTER(ICaptureGraphBuilder2) ptr=0x927294 at a939e0>>
> >>> help(builder.SetFilterGraph)
> Help on method SetFiltergraph in module ctypes:
> 
> SetFiltergraph(...) method of comtypes.POINTER(ICaptureGraphBuilder2)
> instance
> 
> >>>
> 
> 
> If you really want to compile your own type library, here's a simple
> idl file
> that should get you started.  I constructed this by little
> experimentation:
> 
> """
> import "oaidl.idl";
> import "ocidl.idl";
> 
> import "axcore.idl";
> interface ICreateDevEnum;
> import "axextend.idl";
> 
> [
>     // TODO: Use a real clsid and helpstring
>     uuid(00000000-0000-0000-0000-000000000000),
>     version(1.0),
>     helpstring("Type Library")
> ]
> library MyTypeLib
> {
>       interface ICaptureGraphBuilder2;
>       // TODO: Add more interfaces from axextend.idl that we need
> }
> """
> 
> Thomas
> 
> 
> -----------------------------------------------------------------------
> -------
> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
> is a gathering of tech-side developers & brand creativity
> professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity, Processing, &
> iPhoneDevCamp as they present alongside digital heavyweights like
> Barbarian
> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
> _______________________________________________
> comtypes-users mailing list
> comtypes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/comtypes-users

----------------------------------------------------------------------------
--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals.
Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Attachment: PGP.sig
Description: PGP signature

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to