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