473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

win32com extension help

(Sorry in advance for the long post.)

Hi,

I'm having a great deal of difficulty buiding a Python COM extension.
I am using the MSHTML ActiveX control in my application but I need to
interact with and implement some Custom COM interfaces. All is well
with the basic operation of the control using Python.

Basically, I want to take over the right-click (context) menu from
MSHTML. To do this (to the best of my knowledge), you must request the
ICustomDoc interface from the control and set up your own
implementation of the IDocHostUIHandler interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandler gateway.

First off, any link to HOW-TO documentation on this subject would be
greatly appreciated.

I wanted to start with something very simple, so I am trying to
implement an extension that understands only the ICustomDoc interface.
I ran makegw and hand-edited the resulting interfaces to get my .PYD
to compile and link (and even load!).

I pretty much understand the actual implementation of the COM support
generated by makegw, but I'm very hazy on the extension "wiring"
necessary to publish this COM support to Python. (i.e. the use of
PyMethodDef and PyCom_InterfaceSupportInfo etc.)

So, I thought I'd look for a working example and do a knock-off. I'm
running Python 2.3 and I've downloaded and built pywin32-203. I have
previously worked in great detail with the IFilter interface, so I
chose that win32comext project to use as a model. The problem is, when
I run the demo python code (called filterDemo.py) to exercise the
IFilter support, it fails with the following error:

C:\Joey\pywin32-203\com\win32comext\ifilter\demo>filterDemo.py
test.txt
Traceback (most recent call last):
File "C:\Joey\pywin32-203\com\win32comext\ifilter\demo\filterDemo.py",
line 4,
in ?
from win32com.ifilter import ifilter
ImportError: cannot import name ifilter

This is the same error I'm getting with my own implementation .PYD.

(BTW: Yes, I have moved ifilter.pyd into the
C:\Python23\Lib\site-packages\win32com directory.)

Can ANYONE help? Please?
Jul 18 '05 #1
3 2660

"Peter Sparago" <ps******@yahoo.com> wrote in message
news:58**************************@posting.google.c om...
(Sorry in advance for the long post.)

Hi,

I'm having a great deal of difficulty buiding a Python COM extension.
I am using the MSHTML ActiveX control in my application but I need to
interact with and implement some Custom COM interfaces. All is well
with the basic operation of the control using Python.

Basically, I want to take over the right-click (context) menu from
MSHTML. To do this (to the best of my knowledge), you must request the
ICustomDoc interface from the control and set up your own
implementation of the IDocHostUIHandler interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandler gateway.

First off, any link to HOW-TO documentation on this subject would be
greatly appreciated.

I wanted to start with something very simple, so I am trying to
implement an extension that understands only the ICustomDoc interface.
I ran makegw and hand-edited the resulting interfaces to get my .PYD
to compile and link (and even load!).

I pretty much understand the actual implementation of the COM support
generated by makegw, but I'm very hazy on the extension "wiring"
necessary to publish this COM support to Python. (i.e. the use of
PyMethodDef and PyCom_InterfaceSupportInfo etc.)
Basically, you construct an array of PyCom_InterfaceSupportInfo's
that contain the interfaces your extension module will implement.
(the PYCOM_INTERFACE_ macros require very strict naming conventions)

When you pass this array to PyCom_RegisterExtensionSupport,
it adds your interfaces to Pythoncom's internal array of supported
interfaces. This is used to lookup the type object that's used as
a constructor for the Python interface object.
So, I thought I'd look for a working example and do a knock-off. I'm
running Python 2.3 and I've downloaded and built pywin32-203. I have
previously worked in great detail with the IFilter interface, so I
chose that win32comext project to use as a model. The problem is, when
I run the demo python code (called filterDemo.py) to exercise the
IFilter support, it fails with the following error:

C:\Joey\pywin32-203\com\win32comext\ifilter\demo>filterDemo.py
test.txt


Just a guess here, do you have .py files registered to open with a debug
build of python ? If so, you'll need to have debug versions of all the
extension
modules (*_d.pyd) alongside the normal .pyd files to be able to
import them. Or vice-versa, if you only have a debug version of the
extension
built you won't be able to import it from a normal python.exe.

hth
Roger
Jul 18 '05 #2
Hi Roger,

Thanks so much for the post back. I really appreciate it.

The problem with ifilter has been corrected by uninstalling python and
all related python packages I'm using. I hate doing that, but a
colleague was able to run filterDemo.py without incident.

I'm still struggling with importing my ICustomDoc interface. Here's the
first of my issues. This is the .PYD registration function. (I didn't
include the definition of the interface itself, but it's the result of
running makegw on the MSHTML IDL include that has ICustomDoc.)

If I try to call PyCom_RegisterExtensionSupport, the python executor
crashes. OK, I know it's me, but I'm having trouble tracking the
problem down.

If I try to build a debug version of my stuff, it complains that i
don't have a debug version of python (something I'm trying to avoid).
If I could use a debugger, I'd be much more independent about figuring
out what is wrong. Any hints on debugging something like this without
using a debug build of Python? (I'm on Windows.)

Here's the code that fails. Any thoughts would be most appreciated.

static struct PyMethodDef JoeyCustomCom_methods[]=
{
//{ "SetUIHandler", PyICustomDoc::SetUIHandler, 1 }, // @pymeth
SetUIHandler|Description of SetUIHandler
{ NULL }
};

static const PyCom_InterfaceSupportInfo register_data[] =
{
PYCOM_INTERFACE_CLIENT_ONLY ( CustomDoc ),
NULL
};

extern "C" __declspec(dllexport)
void initJoeyCustomCom(void)
{
printf("1\n");

// Initialize PyWin32 globals (such as error objects etc)
PyWinGlobals_Ensure();
printf("2\n");

PyObject *module = Py_InitModule("JoeyCustomCom",
JoeyCustomCom_methods);
if (module==NULL)
return;
printf("3\n");

PyObject *dict = PyModule_GetDict(module);
if (dict==NULL)
return;
printf("4\n");

// Register all of our interfaces, gateways and IIDs.
PyCom_RegisterExtensionSupport(dict, register_data,
sizeof(register_data)/sizeof(PyCom_InterfaceSupportInfo));
printf("5\n");

Roger Upole wrote:
"Peter Sparago" <ps******@yahoo.com> wrote in message
news:58**************************@posting.google.c om...
(Sorry in advance for the long post.)

Hi,

I'm having a great deal of difficulty buiding a Python COM extension. I am using the MSHTML ActiveX control in my application but I need to interact with and implement some Custom COM interfaces. All is well
with the basic operation of the control using Python.

Basically, I want to take over the right-click (context) menu from
MSHTML. To do this (to the best of my knowledge), you must request the ICustomDoc interface from the control and set up your own
implementation of the IDocHostUIHandler interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandler gateway.

First off, any link to HOW-TO documentation on this subject would be greatly appreciated.

I wanted to start with something very simple, so I am trying to
implement an extension that understands only the ICustomDoc interface. I ran makegw and hand-edited the resulting interfaces to get my ..PYD to compile and link (and even load!).

I pretty much understand the actual implementation of the COM support generated by makegw, but I'm very hazy on the extension "wiring"
necessary to publish this COM support to Python. (i.e. the use of
PyMethodDef and PyCom_InterfaceSupportInfo etc.)
Basically, you construct an array of PyCom_InterfaceSupportInfo's
that contain the interfaces your extension module will implement.
(the PYCOM_INTERFACE_ macros require very strict naming conventions)

When you pass this array to PyCom_RegisterExtensionSupport,
it adds your interfaces to Pythoncom's internal array of supported
interfaces. This is used to lookup the type object that's used as
a constructor for the Python interface object.
So, I thought I'd look for a working example and do a knock-off. I'm running Python 2.3 and I've downloaded and built pywin32-203. I have previously worked in great detail with the IFilter interface, so I
chose that win32comext project to use as a model. The problem is, when I run the demo python code (called filterDemo.py) to exercise the
IFilter support, it fails with the following error:

C:\Joey\pywin32-203\com\win32comext\ifilter\demo>filterDemo.py
test.txt


Just a guess here, do you have .py files registered to open with a

debug build of python ? If so, you'll need to have debug versions of all the extension
modules (*_d.pyd) alongside the normal .pyd files to be able to
import them. Or vice-versa, if you only have a debug version of the
extension
built you won't be able to import it from a normal python.exe.

hth
Roger


Jul 18 '05 #3
You can do a release build of your extention that contains
debugging information, and use it with a normal python installation.
Roger
<ps******@yahoo.com> wrote in message
news:10**********************@z14g2000cwz.googlegr oups.com...
Hi Roger,

Thanks so much for the post back. I really appreciate it.

The problem with ifilter has been corrected by uninstalling python and
all related python packages I'm using. I hate doing that, but a
colleague was able to run filterDemo.py without incident.

I'm still struggling with importing my ICustomDoc interface. Here's the
first of my issues. This is the .PYD registration function. (I didn't
include the definition of the interface itself, but it's the result of
running makegw on the MSHTML IDL include that has ICustomDoc.)

If I try to call PyCom_RegisterExtensionSupport, the python executor
crashes. OK, I know it's me, but I'm having trouble tracking the
problem down.

If I try to build a debug version of my stuff, it complains that i
don't have a debug version of python (something I'm trying to avoid).
If I could use a debugger, I'd be much more independent about figuring
out what is wrong. Any hints on debugging something like this without
using a debug build of Python? (I'm on Windows.)

Here's the code that fails. Any thoughts would be most appreciated.

static struct PyMethodDef JoeyCustomCom_methods[]=
{
//{ "SetUIHandler", PyICustomDoc::SetUIHandler, 1 }, // @pymeth
SetUIHandler|Description of SetUIHandler
{ NULL }
};

static const PyCom_InterfaceSupportInfo register_data[] =
{
PYCOM_INTERFACE_CLIENT_ONLY ( CustomDoc ),
NULL
};

extern "C" __declspec(dllexport)
void initJoeyCustomCom(void)
{
printf("1\n");

// Initialize PyWin32 globals (such as error objects etc)
PyWinGlobals_Ensure();
printf("2\n");

PyObject *module = Py_InitModule("JoeyCustomCom",
JoeyCustomCom_methods);
if (module==NULL)
return;
printf("3\n");

PyObject *dict = PyModule_GetDict(module);
if (dict==NULL)
return;
printf("4\n");

// Register all of our interfaces, gateways and IIDs.
PyCom_RegisterExtensionSupport(dict, register_data,
sizeof(register_data)/sizeof(PyCom_InterfaceSupportInfo));
printf("5\n");

Roger Upole wrote:
"Peter Sparago" <ps******@yahoo.com> wrote in message
news:58**************************@posting.google.c om...
(Sorry in advance for the long post.)

Hi,

I'm having a great deal of difficulty buiding a Python COM extension. I am using the MSHTML ActiveX control in my application but I need to interact with and implement some Custom COM interfaces. All is well
with the basic operation of the control using Python.

Basically, I want to take over the right-click (context) menu from
MSHTML. To do this (to the best of my knowledge), you must request the ICustomDoc interface from the control and set up your own
implementation of the IDocHostUIHandler interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandler gateway.

First off, any link to HOW-TO documentation on this subject would be greatly appreciated.

I wanted to start with something very simple, so I am trying to
implement an extension that understands only the ICustomDoc interface. I ran makegw and hand-edited the resulting interfaces to get my .PYD to compile and link (and even load!).

I pretty much understand the actual implementation of the COM support generated by makegw, but I'm very hazy on the extension "wiring"
necessary to publish this COM support to Python. (i.e. the use of
PyMethodDef and PyCom_InterfaceSupportInfo etc.)

Basically, you construct an array of PyCom_InterfaceSupportInfo's
that contain the interfaces your extension module will implement.
(the PYCOM_INTERFACE_ macros require very strict naming conventions)

When you pass this array to PyCom_RegisterExtensionSupport,
it adds your interfaces to Pythoncom's internal array of supported
interfaces. This is used to lookup the type object that's used as
a constructor for the Python interface object.
So, I thought I'd look for a working example and do a knock-off. I'm running Python 2.3 and I've downloaded and built pywin32-203. I have previously worked in great detail with the IFilter interface, so I
chose that win32comext project to use as a model. The problem is, when I run the demo python code (called filterDemo.py) to exercise the
IFilter support, it fails with the following error:

C:\Joey\pywin32-203\com\win32comext\ifilter\demo>filterDemo.py
test.txt


Just a guess here, do you have .py files registered to open with a

debug
build of python ? If so, you'll need to have debug versions of all

the
extension
modules (*_d.pyd) alongside the normal .pyd files to be able to
import them. Or vice-versa, if you only have a debug version of the
extension
built you won't be able to import it from a normal python.exe.

hth
Roger

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
3
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
2
by: Sibylle Koczian | last post by:
Hello, I've installed Python 2.4 and the win32 extensions, using administrator rights, under Windows XP in "C:\Programme". As this is a directory without spaces I didn't expect any problems. But...
0
by: Math | last post by:
Hello python people, Can you help me out please. I get the folllowing Error while trying to build a installer with the Distutils module:...
12
by: vithi | last post by:
Hi Any one tell me where I can get (or download) python modules win32com or win32com.client because I have to use "Dispatch" thanks
1
by: SPJ | last post by:
Sorry, forgot to mention Subject in my earlier post, hence reposting. ------------ I am writing a script which need's to convert an excel file to csv (text) format. For that I am using the...
11
by: Bill Davy | last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers from my address book which is an Excel spreadsheet to my mobile phone. I came across the following snippet of code which...
1
by: korean_dave | last post by:
Hi. Where can i find the API for this extension? Sourceforge only has downloads. Python has stopped supporting the upkeep of the versions. Thanks.
0
by: Tim Golden | last post by:
Lave wrote: You have broadly two approaches here, both involving automating Word (ie using the COM object model it exposes, referred to in another post in this thread). 1) Use the COM model...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.