Matt Herbert schrieb:
> Hello,
>
> <long_winded_explanation>
>
> So I've spent the last couple of days trying to figure out how I can
> change the bindings on a network adapter. All of my research has lead me
> to the INetCfg interface
> (http://msdn2.microsoft.com/en-us/library/ms805265.aspx). It seems as
> though nobody out there has actually used this interface with python yet
> (or at least I can't find anything with google).
I think there should be other ways to change the bindings of a network adapter,
although I cannot tell which you should use. Try asking on the python-win32
mailing
list, maybe?
If you indeed want to use the INetCfg interface, see below.
> So according to the MSDN docs, the interface is already implemented in
> netcfgx.dll. So I thought I would just use ctypes, and access it that
> way. But I took a look at the netcfgx.h file and got scared. I'm not a
> very competent C/C++ programmer (only dable here and there) and that
> header file has things I don't understand.
>
> Next I realized that INetCfg is a COM interface (I don't understand COM
> that well either). So I dug through google, and found the CLSID for it,
> and the IID for INetCfg class, and tried to CoCreateInstance() it (as I
> saw in several C/C++ examples). I kept getting an error about there
> being no interface object registered that supports this IID. So I
> re-read chapter 12 of Mark Hammond's Book and found this gem:
>
> "A final note on native interfaces: Python can't support arbitrary COM
> interfaces; the pythoncom module (or a pythoncom extension) must have
> built-in support for the interface. Fortunately, there are tools
> pythoncom developers use that largely automate the process of supporting
> new interfaces."
>
> Ok, clearly pythoncom has no built-in support for this interface. Dooh.
> So I spend a day digging through google and reading anything I can find.
> Finally I found a couple of threads somewhere that talk about comtypes.
> So I am trying to generate a python class that "wraps" the INetCfg
> interface using comtypes.
>
> I found the comtypes pages on the ctypes wiki, and read through that
> (several times). It suggests the easiest thing to do is generate a type
> library from the IDL, and use comtypes.client.GetModule() to create the
> interface automatically. Sweet. So I try to compile the IDL into a TLB
> using MIDL. oops, can't be done because the IDL does not contain any
> "library" declarations. Ugggh.
>
> </long_winded_explanation>
All this seems basically correct.
Actually, it is quite simple to create a type library from the NetCFGX.idl file,
you just have to write a library statement yourself. I was able to create a
typelib
by compiling this file with the midl compiler:
"""
import "netcfgx.idl";
[
uuid(d99085ff-c5d7-4a4c-a987-91a513e268a9),
version(1.0),
helpstring("NetCfgX 1.0 Type Library")
]
library NetCFGLib
{
interface IEnumNetCfgBindingInterface;
interface IEnumNetCfgBindingPath;
interface IEnumNetCfgComponent;
interface INetCfg;
interface INetCfgProperties;
interface INetCfgLock;
interface INetCfgBindingInterface;
interface INetCfgBindingPath;
interface INetCfgComponentBindings;
interface INetCfgBindingPath;
interface INetCfgClass;
interface INetCfgComponent;
interface INetCfgIdentification;
interface INetCfgClassSetup;
};
"""
The 'interface ...' lines are copied and pasted from the netcfgx.idl file,
the guid in uuid(...) I did create myself.
Thomas
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
comtypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/comtypes-users