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

accessing dll from python using ctypes...

P: 2
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
Share this Question
Share on Google+
1 Reply


P: 2
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

Post your reply

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