473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

accessing dll from python using ctypes...

Hi,

I know that to access any dll from python one should use ctypes. Till now I haven't been able to get it working (I tried both declarations to initialize). Problem that I think is that the dll uses a lot of #define and its own custom structures, of which I couldn't find the definition in ctypes.

I can't see how to go exactly using ctypes, is my problem justified or I missed to see something really important. Also if anybody can guide me about what documentation or book to refer to, it would be great.

While going through some forum I also came across idea of building my own modules in C/C++ for python, will it be a good idea for my displayed algorithm (this is what I use in my C++ code).

Expand|Select|Wrap|Line Numbers
  1.  
  2. #define important_parameter MODULE_NUM
  3. custom_struct *mystruct;
  4.  
  5. mythread(threadid,.. etc)
  6. {
  7.     custom_class::update_data_to_external_device(mystruct, ..);
  8. }
  9.  
  10. int main (void)
  11. {
  12.     custom_class::initialize(important_parameter, *custom_struct);
  13.     do
  14.     {
  15.         key = my_key_detect_func();
  16.         switch (key)
  17.         {
  18.             case 1:
  19.                 //update struct for condition 1;
  20.                 break;
  21.             case 2:
  22.                 //update struct for condition 2;
  23.          }
  24.     }while(key!=quit)
  25.     custom_class::shutdown(important_parameter, *custom_struct);
  26. }
  27.  
answer about any of my questions will be great.
thanks for replying in advance
Feb 23 '11 #1
1 2506
a more rewarding solution was to use SWIG, which is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. The list of supported languages also includes non-scripting languages such as C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), D, Go language, Java, Lua, Modula-3, OCAML, Octave and R. Also several interpreted and compiled Scheme implementations (Guile, MzScheme/Racket, Chicken) are supported.

So eventually I wrote a code in cpp and compiled with SWIG, and app is running flawlessly. :)
Jun 26 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Harish | last post by:
I am using Python2.3 version with SWIG-1.3.19 to access C++ interface provided by a DLL. Some of its function returns MFC class objects like CString , CMap. I tried to generate wrapper for these...
0
by: Helmut Zeisel | last post by:
I want to build a static extension of Python using SWIG and VC++ 6.0 as described in http://www.swig.org/Doc1.3/Python.html#n8 for gcc. My file is testerl.i: ========================= %module...
2
by: Podi | last post by:
I have ctypes version 0.9.6 and Python 2.4.2 running on Windows XP Professional. When I tried to use some functions in the Advapi32.dll, some functions are available and some are not. Is this a...
5
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL=...
1
by: geskerrett | last post by:
I was wondering if a ctypes expert could point me in the right direction. I am using the wrapper for the "freeimage" library to create multipage TIFF files from a group of png images. The...
1
by: mmacrobert | last post by:
Hi Everyone, I've created a 'C' dll that is accessed via ctypes library containing a bunch of functions. I've successfully been able to use the functions. However, I would like to throw python...
4
by: digitnctu | last post by:
Dear all: I am coming with problem, to apply ctypes under interactive mode in python. libdll.dll is a third-party library. The below code segment will run well under the batch mode(ie. python...
2
by: Robert Kern | last post by:
dcharno wrote: Well, stack alignment would be a problem with how the shared library gets compiled, nothing to do with ctypes (I think). However, if you are passing in arrays from ctypes, *they*...
0
by: cnivas | last post by:
Hi, I'm doing a small application in python using mac os x. Now, I want to insert an image in the web application. I have given the image path also... but it shows "?" this symbol.... If the...
3
by: patelss23 | last post by:
Hello All, I am dealing with this weird bug. I have a function in C and I have written python bindings for it using ctypes. I can call this function for couple of times and then suddenly it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
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...

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.