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

Reply via email to