V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
19930618
V2EX  ›  Python

ctypes 怎么获取参数返回值?

  •  
  •   19930618 · 2021-12-25 11:49:05 +08:00 · 1837 次点击
    这是一个创建于 845 天前的主题,其中的信息可能已经有所发展或是发生改变。

    图为 C 的接口 API
    按照我的理解,nHandle 值传过去后,nHandle 值应该会改变。是这样理解吗?


    nHandle=1
    callFunc =CFUNCTYPE(c_long,c_long)
    cb=callFunc(nHandle)
    res=pDll.P2PAPI_CreateInstance(byref(cb))
    print (res)

    我写的 python,请问如何获取他改变后的 nHandle 值
    3 条回复    2021-12-25 20:55:51 +08:00
    wwqgtxx
        1
    wwqgtxx  
       2021-12-25 12:22:19 +08:00
    你需要的是 pointer 而不是 byref
    https://docs.python.org/3/library/ctypes.html#pointers
    19930618
        2
    19930618  
    OP
       2021-12-25 13:20:28 +08:00
    @wwqgtxx 改成 pointer 了,但请问如何获取改变后的 nHandle 值呢
    wwqgtxx
        3
    wwqgtxx  
       2021-12-25 20:55:51 +08:00
    @19930618 人家就是个指针,你接着把这个 pointer 传给别的需要这个 nHandle 的函数不就行了,真的想拿到值就调用 .contents 呗,文档写的不是够清楚的了,还是说你需要看一份中文文档?
    https://docs.python.org/zh-cn/3/library/ctypes.html#pointers
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3512 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 68ms · UTC 00:42 · PVG 08:42 · LAX 17:42 · JFK 20:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.