I have a application written in c++ (MFC). I have included python.h and specified the lib file. With this I am able to use functions from python c api and execute python scripts.
This requires me to include python.h and specify python23.lib to the linker. Everything works fine.
What I am trying now is , to remove the static linking to python and use LoadLibrary function to load the python dll.
I have written the following code -
typedef void (pFnPyRun_SimpleString)(char *);
typedef void (pFnPy_Initialize)();
in a function the following code -
hModPython = AfxLoadLibrary("Python23.dll");
pFnPyRun_SimpleString *pFunction = NULL;
pFnPy_Initialize *pPy_Initialize = NULL;
pFunction = (pFnPyRun_SimpleString *)::GetProcAddress(hModPython, "PyRun_SimpleString");
pPy_Initialize = (pFnPy_Initialize *)::GetProcAddress(hModPython, "Py_Initialize");
if ( pFunction )
AfxMessageBox("unable to access function from python23.dll.", MB_ICONSTOP|MB_OK);
This code works fine too. I have loaded the python dll dynamically and called the functions from python c api by obtaining the function pointers using GetProcAddress.
So far good. The problem arises when i want to create a dictionary object mdict in my c++ code so that i can pass it to a
PyObject* pCodeObject =
if(pCodeObject != NULL)
PyObject* pObject = PyEval_EvalCode((PyCodeObject*)pCodeObject,mDict,mDict);
To be able to compile this i need to include python.h and link to python23.lib statically as PyObject cannot be found. Static linking was what i was trying to avoid. And therefore used loadlibrary.
How can this be handled.
Thanks in advance.