[python-win32] Communicating symbols between extension modules

Mark English Mark.English at liffe.com
Tue Jan 13 04:36:06 EST 2004


Hi,
I'm still on the beginners slope writing Python extensions, and this may
be stuff you already knew, but here's what came to mind:
1) Can't you use "PyImport_ImportModule()" if you need to call python
code in another module from C ? Then lookup the appropriate python
function object in the module dictionary, and call it ? This should be
platform independent if a little clunky (I'm guessing this is what you
meant by magic C code).

2) Many windows programs employ the trick of writing intermediary
wrapper functions for the functions they're interested in from external
dlls (including MFC). So if you want to call "Foo()" from 3rdParty.dll,
you access it through a (module local) function pointer, which initially
points at your own function "MyLoadFoo()". When first called, this loads
the actual required function from 3rdParty.dll, points the global
function pointer at that instead, and then calls the function.

3) An even more common windows trick is to use some module-specific
definition when writing a module (e.g. FOO_PORTING) which under windows
gets defined to either export symbols (when building the module), or
import them (when importing as in your case). In this case, if the code
you need is in 3rd party libraries with the appropriate header files
(and .lib files have been provided), you can avoid Python entirely and
just link to the code which will be loaded at runtime. From what I
remember, a lot of the Python for windows code seems to be available as
a plain dll...

Hope that helps,
Cheers,
mE

> -----Original Message-----
> Message: 2
> Date: Fri, 9 Jan 2004 22:27:43 +0100
> From: Jack Jansen <Jack.Jansen at cwi.nl>
> Subject: [python-win32] Communicating symbols between extension
> 	modules
> 
> Greetings,
> as I'm finally going to put some work again into porting the 
> QuickTime 
> package to Windows (at least: assuming no urgent matters turn up) I 
> need a bit of help.
> 
> The quicktime package will consist of a couple of extension 
> modules and 
> some Python modules, all nicely wrapped up in a package. The 
> problem is 
> that the extension modules need access to some symbols from other 
> extension modules (within the same package). Specifically, the O& 
> object encode/decode routines need to be available in other modules.
> 


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies.
-----------------------------------------------------------------------




More information about the Python-win32 mailing list