if i insert a printf("fooo"); before return, the function will work normally, so i guess it's neither passing nor returning is the issue.
 
2013-08-16

张琛
tel:13575752056

发件人:"Diez B. Roggisch" <deets@web.de>
发送时间:2013-08-16 16:48
主题:Re: [ctypes-users] Why ctypes always returns True?
收件人:"ctypes-users"<ctypes-users@lists.sourceforge.net>
抄送:
 
Have you tried setting an explicit return value on the function object? Also, I would try & hard-code the return value to False so that you can be sure that the returning is the issue, not the passing.

And one last note: I *think* ctypes.cdll is wrong, it uses the wrong calling convention, that might lead to the passing of a wrong param. I'm no windows expert though, but make sure the library uses cdecl, not stdcall. Or use ctypes.windll

http://docs.python.org/2/library/ctypes.html#loading-dynamic-link-libraries

Diez


On Aug 15, 2013, at 1:26 PM, zhangxaochen wrote:

My c code is:
    extern "C" __declspec(dllexport) bool isTrue( bool b){ return b; }
py code is:
    lib=ctypes.cdll.LoadLibrary('xx.dll') #dll generated from the c code above
    b=lib.isTrue(False) 
    print c_bool(b).value

no matter i call lib.isTrue() with True or False, the output is always 'True'.....
could someone explain?





发件人:张琛
联系电话:13575752056(杭州)
联系地址:浙江省杭州市西湖区浙大路38号  浙大玉泉校区32舍203       邮编:310027
MOTTO:There is no secret ingredient...



------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk_______________________________________________
ctypes-users mailing list
ctypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ctypes-users