win32com support
Mark Hammond
mhammond at skippinet.com.au
Fri Jan 30 18:53:41 EST 2004
Crawley wrote:
> Im trying to produce a small Visual Studio Addin. Taking the
> OutlookAddin example and changing the registry place it installs too,
> everything works ok.
>
> Examples in C++ show that in the OnConnection method I have to registry
> my commands and also pass an instance of my sub class of ICommands.
>
> The C code looks like this:
>
> IApplication* pApplication = NULL;
> pApp->QueryInterface(IID_IApplication, (void**) &pApplication)
>
> CCommandsObj::CreateInstance(&m_pCommands);
> m_pCommands->AddRef();
> m_pCommands->SetApplicationObject(pApplication);
>
> pApplication->SetAddInInfo((long) AfxGetInstanceHandle(),
> (LPDISPATCH) m_pCommands, -1, -1, m_dwAddin));
>
>
> So far Im trying something like this:
>
> self._command = VCCmd(application)
> application.SetAddInInfo(AfxGetInstanceHandle(), self._command, -
> 1, -1, addin )
>
>
> with VCCmd defined like:
>
> class VCCmd:
> _com_interfaces_ = ['_ICommands']
> _public_methods_ = []
>
> _application = None
>
> def __init__( self, app ):
> self._application = app
> print "VCCmd __init__"
>
>
> Needless to say, its not working, so questions.
>
> 1) AfxGetInstanceHandle dosent appear to exist in the win32api... so how
> do I call it.
AfxGetInstanceHandle returns the handle to your MFC built DLL. The
assumption is that your object is built into a nice, single little DLL.
This doesn't make sense for Python. Your code is not implemented in a
DLL at all, but in a .py file. There are a few DLLs involved
(pythonxx.dll, pythoncomxx.dll), and the handles to these can be found
pretty easily - but it is unclear if that helps you.
You really need to determine *why* SetAddInInfo() wants a DLL handle and
what the implications are. My guess is that it expects to be able to
pull Win32 resources (such as bitmaps, menus, etc) from that DLL, which
may be a problem.
> 2) am I defining VCCmd correctly to be a subclass of ICommands
That looks OK, assuming that the type library where ICommands is defined
has been registered for universal support. You will note the Outlook
addin sample specifies the generic IDTExtensibility interface - if
ICommands is VS specific (and therefore in a different typelib), then it
is likely you also need to specify that additional typelib.
>
> 3) am I correct in thinking i dont have to explicitly 'cast' application
> into an IApplication instance
Correct - the framework will automatically perform a QI in most cases.
Of course, if your object is not implemented correctly, this QI will fail.
>
> Many thanks for any light you may be able to shed on the subject
Register your addin with "--debug" on the command-line. Then use the
Pythonwin "Remote Trace Collector" tool, and you should see lots of
output as your object is instantiated and used. You should also be able
to see most exceptions raised by your object, which are generally
invisible without this debugging technique.
When you get it working, consider contributing it back as a sample I can
put next to the Outlook one ;)
Mark.
More information about the Python-list
mailing list