473,589 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 IDocHostUIHandl er interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandl er 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_Interface SupportInfo 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\win32co mext\ifilter\de mo>filterDemo.p y
test.txt
Traceback (most recent call last):
File "C:\Joey\pywin3 2-203\com\win32co mext\ifilter\de mo\filterDemo.p y",
line 4,
in ?
from win32com.ifilte r 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\win32c om directory.)

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

"Peter Sparago" <ps******@yahoo .com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
(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 IDocHostUIHandl er interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandl er 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_Interface SupportInfo etc.)
Basically, you construct an array of PyCom_Interface SupportInfo'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_RegisterE xtensionSupport ,
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\win32co mext\ifilter\de mo>filterDemo.p y
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_RegisterE xtensionSupport , 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_m ethods[]=
{
//{ "SetUIHandl er", PyICustomDoc::S etUIHandler, 1 }, // @pymeth
SetUIHandler|De scription of SetUIHandler
{ NULL }
};

static const PyCom_Interface SupportInfo register_data[] =
{
PYCOM_INTERFACE _CLIENT_ONLY ( CustomDoc ),
NULL
};

extern "C" __declspec(dlle xport)
void initJoeyCustomC om(void)
{
printf("1\n");

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

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

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

// Register all of our interfaces, gateways and IIDs.
PyCom_RegisterE xtensionSupport (dict, register_data,
sizeof(register _data)/sizeof(PyCom_In terfaceSupportI nfo));
printf("5\n");

Roger Upole wrote:
"Peter Sparago" <ps******@yahoo .com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
(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 IDocHostUIHandl er interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandl er 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_Interface SupportInfo etc.)
Basically, you construct an array of PyCom_Interface SupportInfo'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_RegisterE xtensionSupport ,
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\win32co mext\ifilter\de mo>filterDemo.p y
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.goo glegroups.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_RegisterE xtensionSupport , 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_m ethods[]=
{
//{ "SetUIHandl er", PyICustomDoc::S etUIHandler, 1 }, // @pymeth
SetUIHandler|De scription of SetUIHandler
{ NULL }
};

static const PyCom_Interface SupportInfo register_data[] =
{
PYCOM_INTERFACE _CLIENT_ONLY ( CustomDoc ),
NULL
};

extern "C" __declspec(dlle xport)
void initJoeyCustomC om(void)
{
printf("1\n");

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

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

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

// Register all of our interfaces, gateways and IIDs.
PyCom_RegisterE xtensionSupport (dict, register_data,
sizeof(register _data)/sizeof(PyCom_In terfaceSupportI nfo));
printf("5\n");

Roger Upole wrote:
"Peter Sparago" <ps******@yahoo .com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
(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 IDocHostUIHandl er interface. In Python COM
extension lingo, I need an ICustomDoc interface and an
IDocHOstUIHandl er 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_Interface SupportInfo etc.)

Basically, you construct an array of PyCom_Interface SupportInfo'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_RegisterE xtensionSupport ,
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\win32co mext\ifilter\de mo>filterDemo.p y
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
5180
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 remove old version (as well as the mx libraries I had installed). I then installed the new version as a user with the Administrator role. I know I'm technically not supposed to install to a directory with a space in the name, but it worked fine for...
3
6996
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 and Word examples run fine. win32com.client.Dispatch("Excel.Application") etc., but how does one know the ("<foo>.<bar>") to type in? Excel looks only vaguely like "Excel.Application" in the com browser.
2
7046
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 now I can't _use_ win32com as a normal user, because normal users can't write there: PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond@skippinet.com.au) -
0
1325
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: ------------------------------------------------------------------------------------------------------------------------------------------ building 'win32com.client' extension.... 'Python was built with version 7.1 of Visual Studio, and extensions need to be built with the same version of the compiler,...
12
129960
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
3018
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 following code: excel = win32com.client.Dispatch("Excel.Application","Quit") workbook = excel.Workbooks.Open(xlsfile) workbook.SaveAs(csvfile, FileFormat=24) # 24 represents xlCSVMSDOS workbook.Close(False) excel.Quit()
11
7685
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 enabled me to the contacts at least list. I had to root around to discover CdoDefaultFolderContacts (though it was guessable; how could I enumerate win32com.client.constants?). I now want to work through the Contacts in Outlook patching in...
1
8185
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
2218
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 to have Word load your doc, and SaveAs it in HTML format. Advantage: it's relatively straightforward. Disadvantage:
0
7931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
7990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5731
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3849
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2374
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1461
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1198
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.