473,511 Members | 10,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

use embedded python to build a dll

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?
Jul 18 '05 #1
0 1398

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3030
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
12
3066
by: Brandon | last post by:
Java seems to have taken off as the platform and language of choice for many embedded devices. Would it be feasible for Python(perhaps running on an embedded version of Linux) to act in such a...
10
2494
by: John Underwood | last post by:
Can I use python23_d and python23 to develop an extension for a commercial application uses python22.dll? (Providing that I do not use any new features found only in 2.3.) I would bulld version...
13
2774
by: Alexander May | last post by:
Hi, I love Python! I've been using it for a couple of years now and have found it to be a highly productive language. I evangelize it to my developer friends and am probably responsible for...
0
1500
by: Adam Tomjack | last post by:
I'm trying to embed Python 2.3.5 into a C++ application on Windows XP. When I build my app with debug symbols and link to a debug build of Python, then my program seems to crash most (but not all)...
8
2413
by: Brennus | last post by:
I have a dll/so which embeds python. I can verify it works by compiling it as an executable and adding an appropriate main. I tried to write unit tests for this library with ctypes and a simple...
20
22471
by: Jack | last post by:
Is there a Python packaging that is specifically for embedded systems? ie, very small and configurable so the user gets to select what modules to install? For Linux-based embedded systems in...
2
1603
by: Carl J. Van Arsdall | last post by:
I'm aware of a couple python projects for embedded systems. I am currently considering using Python on an embedded platform to develop a simple application as a personal project, mostly to see if...
3
275
by: Daniel Fetchinson | last post by:
Does Python 2.5.2's embedded SQLite support full text searching? Sqlite itself is not distributed with python. Only a python db api compliant wrapper is part of the python stdlib and as such it...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.