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


Groups > comp.lang.python > #61404

noobie needs help with ctypes

From "Sells, Fred" <fred.sells@adventistcare.org>
Subject noobie needs help with ctypes
Date 2013-12-09 19:24 +0000
Newsgroups comp.lang.python
Message-ID <mailman.3788.1386617113.18130.python-list@python.org> (permalink)

Show all headers | 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