Re: handling return codes from CTYPES
On 13-01-21 05:46 AM, Steve Simmons wrote:
> >>> from ctypes import *
> >>> sLib = cdll.slib
> >>> lic_key = c_char_p("asdfghjkl".encode(encoding='utf_8',
> >>> 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).
That's because you've just discarded the object you created.
What you wanted was, I believe:
initScanLib = sLib.InitScanLib
initScanLib.restype = c_short
initResult = initScanLib( ... )
i.e. you tell the initScanLib function how to coerce its result-type.
*Some* C functions take a pointer to a data-value to fill in their data,
but not *your* function. That pattern looks like:
result = c_short(0)
my_ctypes_function( ..., byref(result) )
i.e. you have to pass the variable into the function (as a
Mike C. Fletcher
Designer, VR Plumber, Coder
|All times are GMT. The time now is 11:39 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.