use embedded python to build a dll

newbie zephyrwings at
Wed Dec 8 08:30:37 CET 2004

Hi all,
I got a problem using the embedded python. I'll be appreciated if some one
can show me the way.

What i want is, a dll(test.dll/test.lib) which uses the embedded python, for
example, i want to use the 're' module. a exe(usedll.exe) which uses that dll.
3.use py2exe to eliminate the dependence of the python environment.

here is the cpp file to build test.dll/test.lib

** is the python script i used. so i import the module 'query'**

#include "stdafx.h"
#include <iostream>
#pragma comment(lib, "d:\\\\sdk\\Python23\\libs\\python23.lib")
#include "d:\sdk\python23\include\python.h"

                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
    return TRUE;

__declspec(dllexport) void __stdcall DoIt()
 PyObject *pM=PyImport_ImportModuleEx("query", NULL, NULL, NULL);

here is the file to build usedll.exe

#include "stdafx.h"
#include "windows.h"

#pragma comment(lib, "..\\Release\\test.lib")

__declspec(dllimport) void __stdcall DoIt();
int main(int argc, _TCHAR* argv[])

 return 0;


i use file like this,

from distutils.core import setup
import py2exe

and then
python py2exe --includes query --packages encodings

and i got a bunch of files.

Then I put usedll.exe test.dll test.lib and all of these files
generated by py2exe in the same directory. I run the usedll.exe, then I got
a run time error 'this application has requested the runtime to terminate it
in an unusual way...'

but if i don't use those files generated by py2exe, i.e. i use the python
environment on my machine, every thing is fine.

I can not figure out where is the problem. Could anyone give me a hint?

More information about the Python-list mailing list