<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7036.0">
<TITLE>PythonWin COM Client Problem Accessing Methods in C++ MFC COM Server</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT COLOR="#000080" SIZE=2 FACE="Arial">First, a little background to help explain the problem. I have a C++ MFC application configured as an Automation COM server. It has a dual interface defined in a type library embedded as a resource in the executable. The dual interface has been been implemented according to the Microsoft help article "</FONT><FONT SIZE=2 FACE="Arial">TN065: Dual-Interface Support for OLE Automation Servers</FONT><FONT COLOR="#000080" SIZE=2 FACE="Arial">". The application also has dispinterface which implements only a small subset of the properties and methods contained in the dual interface. The BASIC scripts in Excel can successfully invoke methods in the dual interface as long as I "</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Dim myobject As mydualinterface</FONT><FONT COLOR="#000080" SIZE=2 FACE="Arial">" instead of "</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Dim myobject As Object</FONT><FONT COLOR="#000080" SIZE=2 FACE="Arial">".</FONT></P>
<P><FONT COLOR="#000080" SIZE=2 FACE="Arial">OK, now here is the problem. Python seems to be able to invoke the properties and methods in the dispinterface, but is completely unable to invoke anything in the dual interface. I have run MakePy and it seems to generate the proper py file. PythonWin definitely "understands" the type library and all of its methods and properties. As I type a method name in the editor, the entire list of methods in the dual interface pops up in the help list. Also, the type library defines a number of structures that I can successfully access and use as Python records.</FONT></P>
<P><FONT COLOR="#000080" SIZE=2 FACE="Arial">Here is an example from the PythonWin Interactive Window.</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Arial">PythonWin 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32.<BR>
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.<BR>
>>> import win32com.client<BR>
>>> app = win32com.client.Dispatch("FRED.Application") #### Success!<BR>
>>> app.Visible = True #### Success because "Visible" is a property in the dispinterface.<BR>
>>> y = app.Acos(0.5) #### Interactive editor lists this method in the popup window as I type, but Invoke fails during execution!<BR>
Traceback (most recent call last):<BR>
File "<interactive input>", line 1, in <module><BR>
File "C:\Python26\lib\site-packages\win32com\gen_py\D604334A-6198-4BEC-9AE9-6038B7352C9Ax0x2x24\IDualFREDApp.py", line 33, in Acos<BR>
return self._oleobj_.InvokeTypes(20, LCID, 1, (5, 0), ((5, 1),),x<BR>
com_error: (-2147352573, 'Member not found.', None, None)<BR>
>>> </FONT>
</P>
<P><FONT COLOR="#000080" SIZE=2 FACE="Arial">I see the same error if I attempt to Invoke any method in the dual interface.</FONT>
</P>
<P><FONT COLOR="#000080" SIZE=2 FACE="Arial">Is there anyone who can offer some insight into the problem? Any thoughts would be greatly appreciated!</FONT>
</P>
<P><FONT COLOR="#333399" SIZE=2 FACE="Arial">Regards,<BR>
SCJ</FONT>
</P>
</BODY>
</HTML>