By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

use embedded python to build a dll

P: n/a
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?
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.