Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61404

noobie needs help with ctypes

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <fred.sells@adventistcare.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'c++,': 0.07; 'definitions': 0.07; 'subject:help': 0.08; '"c"': 0.09; 'correspond': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; "'convert": 0.16; '6.x': 0.16; 'extern': 0.16; 'subject:ctypes': 0.16; 'code.': 0.18; '3.0': 0.19; 'work,': 0.20; 'input': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'char': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; '2.0': 0.26; 'define': 0.26; 'point': 0.28; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'ctypes': 0.31; 'figure': 0.32; 'skip:c 30': 0.32; 'skip:- 30': 0.32; 'subject:with': 0.35; 'skip:- 50': 0.35; 'but': 0.35; 'version': 0.36; '2.6': 0.36; 'c++': 0.36; 'received:org': 0.40; 'how': 0.40; 'flat': 0.60; 'success': 0.61; 'first': 0.61; 'different': 0.65; 'success,': 0.65; 'here': 0.66; 'to:none': 0.92; 'subject:needs': 0.93
From "Sells, Fred" <fred.sells@adventistcare.org>
CC "python-list@python.org" <python-list@python.org>
Subject noobie needs help with ctypes
Thread-Topic noobie needs help with ctypes
Thread-Index Ac71E2LJXxzQMCs0SyKEjMPQgR+/aQ==
Date Mon, 9 Dec 2013 19:24:22 +0000
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [192.168.218.38]
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
MIME-Version 1.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3788.1386617113.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386617113 news.xs4all.nl 2978 [2001:888:2000:d::a6]:51316
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61404

Show key headers only | View raw


I'm using python 2.6 on Linux/CentOs 6.x

I'm getting ctypes to work, but getting stuck on the use of  .argtypes.  Can someone point out what I'm doing.  This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python.

Here is my code.  Without the restype/argtypes it works, but I cannot figure out how to define argtypes to match the data.  
mylibrary     = ctypes.CDLL(LIBRARY_PATH)
mdsconvert = mylibrary.RugVersionConverter
mdsconvert.restype = ctypes.c_int
mdsconvert.argtypes = [ charptr, #flat buffer of mds 3.0 data
                        ctypes.c_buffer, #computed flat buffer of mds 2.0 data
                        ctypes.c_buffer  #version set to "1.00.4" in c++, never used
                        ]

def convertMds2to3(mds30buffer):
    mds20 = ctypes.create_string_buffer('\000'*3000)
    t = ctypes.create_string_buffer('\000'*30)
    success = mdsconvert(mds30buffer,  ctypes.byref(mds20), ctypes.byref(t) )
    print 'convert %s to %s success=%s version=%s' % (len(mds30buffer), len(mds20.value), success, t.value)
    return mds20.value

------------------------------- C++ code looks like this -------------------------------------------------------
extern "C"
   int RugVersionConverter( char * sInputRecord, char * MDS2_Rec, char * Version );

where sInputRecord is input and MDS2_Rec and Version are output.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

noobie needs help with ctypes "Sells, Fred" <fred.sells@adventistcare.org> - 2013-12-09 19:24 +0000

csiph-web