handling return codes from CTYPES

Duncan Booth duncan.booth at invalid.invalid
Mon Jan 21 06:11:22 EST 2013


Steve Simmons <square.steve at gmail.com> wrote:

> >>> from ctypes import *
> >>> sLib = cdll.slib
> >>> lic_key = c_char_p("asdfghjkl".encode(encoding='utf_8', 
> errors='strict'))
> >>> initResult = sLib.InitScanLib(lic_key.value)
> >>> print("InitScanLib Result:  ", initResult)
> InitScanLib Result:   65535
> >>>
> 
> I've tried declaring initResult as c_short by: inserting...
> 
> >>> initResult = c_short(0)
> 
> ... before the call to sLib.InitScanLib but I still get the same 
> response (65535).

Tell the function what type to return before you call it:

InitScanLib = sLib.InitScanLib
InitScanLib.restype = c_short

See http://docs.python.org/2/library/ctypes.html#return-types

You can also tell it what parameter types to expect which will make calling 
it simpler.

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list