469,325 Members | 1,404 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

accessing dll from python using ctypes...


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
  2. #define important_parameter MODULE_NUM
  3. custom_struct *mystruct;
  5. mythread(threadid,.. etc)
  6. {
  7.     custom_class::update_data_to_external_device(mystruct, ..);
  8. }
  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. }
answer about any of my questions will be great.
thanks for replying in advance
Feb 23 '11 #1
1 2391
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.

Similar topics

reply views Thread by Helmut Zeisel | last post: by
1 post views Thread by geskerrett | last post: by
1 post views Thread by mmacrobert | last post: by
4 posts views Thread by digitnctu | last post: by
2 posts views Thread by Robert Kern | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.