Python Wrapper for C# Com Object

TheSeeker duane.kaufman at gmail.com
Fri Dec 29 11:00:04 EST 2006


Hi,

A question. Why in your C-version are your doing:

X_com_ptr->SetID(10);

and in the Python version:

interface.SetID()  ?

I don't know anything of your COM object, but does SetID require a
parameter?

Duane


bg_ie at yahoo.com wrote:
> bg_ie at yahoo.com skrev:
>
> > bg_ie at yahoo.com skrev:
> >
> > > Hi,
> > >
> > > I wish to write a Python wrapper for my C# COM object but am unsure
> > > where to start. I have a dll and a tlb file, and I can use this object
> > > in C via the following code -
> > >
> > > // ConsolApp.cpp : Defines the entry point for the console application.
> > > //
> > > #include "stdafx.h"
> > > #include "windows.h"
> > > #include "stdio.h"
> > > #import "C:\Documents and Settings\X\Mina dokument\Visual Studio
> > > 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb"
> > > using namespace X_COMObject;
> > >
> > > int _tmain(int argc, _TCHAR* argv[])
> > > {
> > > 	CoInitialize(NULL);
> > >
> > > 	X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class));
> > > 	XCOM_Interface *X_com_ptr ;
> > > 	X_com_ptr = p ;
> > > 	X_com_ptr->SetID(10);
> > > 	int x = X_com_ptr->GetID();
> > > 	printf("%d",x);
> > > 	getchar();
> > >
> > > 	return 0;
> > > }
> > >
> > > Can anyone offer me some tips as to how to do this in Python?
> > >
> > > Thanks very much for your help,
> > >
> > > Barry.
> >
> > This is what I've done so far, but I know I'm not doing this correctly.
> > Can anyone help me out?
> >
> > #import pythoncom
> > #pythoncom.CoInitialize()
> >
> > from comtypes.client import GetModule, CreateObject
> >
> > module = GetModule("C:\\Documents and Settings\\X\\Mina
> > dokument\\Visual Studio
> > 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb")
> >
> > dir(module)
> >
> > interface = module.XCOM_Interface()
> >
> > dir(interface)
> >
> > interface.SetID()
> >
> > #pythoncom.CoUnitialize()
> >
> >
> > Traceback (most recent call last):
> >   File "C:/Python25/test.py", line 14, in <module>
> >     interface.SetID()
> > TypeError: Expected a COM this pointer as first argument
> 
> Can anyone help me with this?
> 
> Thanks,
> 
> Barry.




More information about the Python-list mailing list