use embedded python to build a dll

N

newbie

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,
1.build a dll(test.dll/test.lib) which uses the embedded python, for
example, i want to use the 're' module.
2.build 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

**query.py 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"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}


__declspec(dllexport) void __stdcall DoIt()
{
Py_Initialize();
PyObject *pM=PyImport_ImportModuleEx("query", NULL, NULL, NULL);
Py_XDECREF(pM);
std::cout<<"ok";
Py_Finalize();
}
====

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[])
{
DoIt();

return 0;
}


----

i use setup.py file like this,

from distutils.core import setup
import py2exe
setup()

and then
python setup.py py2exe --includes query --packages encodings

and i got a bunch of files.

Then I put usedll.exe test.dll test.lib query.py 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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,247
Latest member
crypto tax software1

Latest Threads

Top