[pywin32-checkins] pywin32/win32/src _win32sysloader.cpp,NONE,1.1
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2005-10-21 02:25:57
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2524/win32/src Added Files: _win32sysloader.cpp Log Message: Give up on trying to safely import pywintypesXX.dll without help from an extension - so we have a new _win32sysloader.cpp which only claim to fame is that it does not link to pywintypes.dll. This prevents errors seen in Zope, when an (existing) pywintypesXX.dll lives in system32, and Zope installs its own next to its python.exe. In this case, importing (eg) win32api before pywintypes would cause bizarre type errors as the module was loaded twice. --- NEW FILE: _win32sysloader.cpp --- /*********************************************************************** _win32sysloader.cpp -- a helper module for loading the PyWin32 "system" modules pywintypes and pythoncom. Note that this module does (and must) *NOT* link to pywintypesXX.dll See pywintypes.py for more information. ********************************************************************/ #include "windows.h" #include "Python.h" // GetModuleHandle and GetModuleFilename rolled into 1 static PyObject *PyGetModuleFilename(PyObject *self, PyObject *args) { char *modName; if (!PyArg_ParseTuple(args, "s", &modName)) return NULL; HINSTANCE hinst = GetModuleHandle(modName); if (hinst == NULL) { Py_INCREF(Py_None); return Py_None; } char buf[_MAX_PATH]; if (GetModuleFileName(hinst, buf, sizeof(buf))==0) { Py_INCREF(Py_None); return Py_None; } return PyString_FromString(buf); } static PyObject *PyLoadModule(PyObject *self, PyObject *args) { char *modName; if (!PyArg_ParseTuple(args, "s", &modName)) return NULL; HINSTANCE hinst = LoadLibrary(modName); if (hinst == NULL) { Py_INCREF(Py_None); return Py_None; } char buf[_MAX_PATH]; if (GetModuleFileName(hinst, buf, sizeof(buf))==0) { Py_INCREF(Py_None); return Py_None; } return PyString_FromString(buf); } static struct PyMethodDef functions[] = { {"GetModuleFilename", PyGetModuleFilename,1}, {"LoadModule", PyLoadModule,1}, { NULL } }; extern "C" __declspec(dllexport) void init_win32sysloader(void) { Py_InitModule("_win32sysloader", functions); } |