NT DLL modules and C++

Patrick J. Moran pmoran at nas.nasa.gov
Thu Nov 4 00:08:21 CET 1999

In article <002701bf2609$38622320$3acbd9c2 at peridot.optichrome.com>, "Adrian Eyre" <a.eyre at optichrome.com> writes:
|> > How do I get Python to call the initialization under NT?
|> This should do the trick (for module spam.dll):
|> ...

I should clarify a bit.  I have an initFOO() call for my FOO module, and it gets called
just fine.  I can manually call "placement new" constructors on the static data members
of my classes to initialize them, but it's awkward and a hack.  It's also not a complete
solution because there may be other static objects that belong to libraries whose
implementation I'm not familiar with, e.g., iostreams.  There's got to be a better way.

My understanding is that there is an entry point, _DllMainCRTStartup, that the linker
generates that calls the necessary C++ constructors, and then calls DllMain.  So, the
good news is that I could call _DllMinCRTStartup and the appropriate construction code
would be called, assuming I figure out the arguments required by _DllMainCRTStartup.
The bad news is that _DllMainCRTStartup calls DllMain, the entry point provided by
the user (or the Python library, I presume).  DllMain in turn calls my initFOO (again,
I presume) so I would be in an infinite loop.  Of course I could think of hacks to prevent
the infinite looping.  Still, there's got to be a better way.

The solution that I'm looking for is to get Python to call the constructor code when
it does the dynamic linking.  I think this means calling _DllMainCRTStartup rather than
DllMain.  I've tried looking through the doc in the PC directory, but it's still
unclear to me.  That's what I was looking for help with.



More information about the Python-list mailing list