[python-win32] How to Impletments COM Interface:IInternetProtocol

Mark Hammond mhammond at skippinet.com.au
Thu May 24 01:29:16 CEST 2007


> 1. I need to make a COM server. In the book, it just told how to
> implements user-defined interfaces. How do I implement some system
> interfaces, like IInternetProtocol. I supposed if there is a wrap
> class of the interfaces, I can just inherit the class. The code maybe
> like this:
>
> class MyProtocol(PyIInternetProtocol, PyIClassFactory):
>     ......
>
> or like this:
>
> class MyProtocol:
>     _com_interfaces_ = ['IInternetProtocol', 'IClassFactory']
>     ......
>
> But these are not the real thing. There are no such wrap class
> PyIInternetProtocol.

What you want is the win32com.internet module.

>>> from win32com.internet import internet
>>> internet.IID_IInternetProtocol
IID('{79EAC9E4-BAF9-11CE-8C82-00AA004BA90B}')
>>>

So your code could look something like:

class MyProtocol:
    _com_interfaces_ = [internet.IID_IInternetProtocol]
    ......

> 2. Makepy can create wrap classed of a typelib. The generated wrap
> class can be used in a COM client (for early-bound and constants). Do
> I need to use it when I create a sever-side COM object? As question 1
> said , generating wrap class and inherit it?
>
> Even the answer is Yes,  I still don't know which typelib it is. I
> didn't find it in the typelib list.
> How can I know which typelib defines these interfaces?

You would need to do that if the interface you were trying to support
existed in a typelib.  As the internet module handles this, you can ignore
makepy.

> 3. This question is not about python or PythonCOM. In my opinion,
> every interface should have a entry int the registry.

Maybe I misunderstand you, but if you are stating your opinion on what
should have been done, I'm afraid that will not change reality.  If you
meant to say that it is your *understanding* that every interface gets a
registry entry, then I'm afraid you are wrong.  Note that an interface is
*not* a COM object (but even then, not all COM objects are in the registry
either - only ones that are CoCreatable are).

> But I don't find
> any information about IInternetProtocol. I found the IID of these
> interfaces by google. They are not in my registry, except the last one
> (IInternetSecurityMananer). They have similar IIDs and all implemented
> in urlmon.dll. It puzzles me.

There is no requirement that interfaces be listed in the registry.  If you
want automatic marshalling of interfaces then you probably do need some
registration for them, but in general, interfaces do not need to be in the
registry to work.  A .IDL file is usually what you are looking for.

Hope this helps,

Mark



More information about the Python-win32 mailing list