Hi dear community,
I am trying to use INetCfg from python using comtypes
http://msdn.microsoft.com/en-us/library/ff547694(v=vs.85).aspx
After hours of research, finally I am able to create its TLB file and use
it in the following unittest code.
import unittest
from comtypes import GUID
from comtypes.client import GetModule, CreateObject, CoGetObject
GetModule('netcfg.tlb')
from comtypes.gen._D99085FF_C5D7_4A4C_A987_91A513E268A9_0_1_0 import *
CLSID_CNetCfg = GUID('{5B035261-40F9-11D1-AAEC-00805FC1270E}')
IID_INetCfg = GUID('{C0E8AE93-306E-11D1-AACF-00805FC1270E}')
IID_DevClassNet = GUID('{4d36e972-e325-11ce-bfc1-08002be10318}')
IID_INetCfgClass = GUID('{C0E8AE97-306E-11D1-AACF-00805FC1270E}')
class TestNetinf(unittest.TestCase):
def test_comtypes(self):
netcfg = CreateObject(CLSID_CNetCfg, None, None, INetCfg)
netcfg.Initialize(None)
netcfgclass = netcfg.QueryNetCfgClass(IID_DevClassNet,
IID_INetCfgClass)
But I still unable to instantiate netcfgclass. It only a function return
value, not a pointer as I expected it to be
This is the INetCfgClass implementation automatically created by comtypes:
class INetCfg(IUnknown):
_case_insensitive_ = True
_iid_ = GUID('{C0E8AE93-306E-11D1-AACF-00805FC1270E}')
_idlflags_ = []
INetCfg._methods_ = [
COMMETHOD([], HRESULT, 'Initialize',
( ['in'], c_void_p, 'pvReserved' )),
COMMETHOD([], HRESULT, 'Uninitialize'),
COMMETHOD([], HRESULT, 'Apply'),
COMMETHOD([], HRESULT, 'Cancel'),
COMMETHOD([], HRESULT, 'EnumComponents',
( ['in'], POINTER(GUID), 'pguidClass' ),
( ['out'], POINTER(POINTER(IEnumNetCfgComponent)),
'ppenumComponent' )),
COMMETHOD([], HRESULT, 'FindComponent',
( ['in'], WSTRING, 'pszwInfId' ),
( ['out'], POINTER(POINTER(INetCfgComponent)), 'pComponent'
)),
COMMETHOD([], HRESULT, 'QueryNetCfgClass',
( ['in'], POINTER(GUID), 'pguidClass' ),
( ['in'], POINTER(GUID), 'riid' ),
( ['out'], POINTER(c_void_p), 'ppvObject' )),
]
How do I properly call QueryNetCfgClass ?
Actually, I am trying to translate the following C# code :
object objINetCfg = null;
int nRet = 0;
nRet = Ole32Methods.CoCreateInstance(ref
INetCfg_Guid.CLSID_CNetCfg, null, Ole32Methods.CLSCTX_INPROC_SERVER, ref
INetCfg_Guid.IID_INetCfg, out objINetCfg);
INetCfg netCfg = objINetCfg as INetCfg;
nRet = netCfg.Initialize(IntPtr.Zero);
object componet = new object();
nRet = netCfg.QueryNetCfgClass(ref
INetCfg_Guid.IID_DevClassNet, ref INetCfg_Guid.IID_INetCfgClass, out
componet);
INetCfgClass NetCfgClass = componet as INetCfgClass;
That's why I know that QueryNetCfgClass return a long value, together with
that out arguments.
In case you were wondering the *.idl file, here it is. I got it also from
this mailing list:
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;
};
Thanks in advance for your respond!
--
Eko S. Wibowo
----------------------
http://about.me/ekowibowo
* A capoeira a day can make the doctor away *
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users