---
title: "Python Ctypes 结构体指针处理(函数参数，函数返回)"
author: "holoblog"
date: "2011-09-29T11:03:00Z"
tags: []
slug: "python-ctypes"
draft: false
lastmod: "2011-11-09T12:01:15Z"
id: 1245343
url: "https://holoblog.iteye.com/blog/1245343"
---

C函数需要传递结构体指针是常事，但是和Python交互就有点麻烦事了，经过研究也可以了。

**&lt;结构体指针作为函数参数&gt;**

来看下C测试例子:

这里test里面需要传入结构体指针,函数中的实现很简单，就是改变x 和 y 的值这个函数将被python调用。

使用Python调用时，需要模拟申明个结构体(class):

Usage:

**&lt;函数返回结构体指针&gt;**

C函数测试例子改成如下:

Python程序处理如下:

关于resttype可以参见 Tutorial :By default functions are assumed to return the C`int`type. Other return types can be specified by setting the`restype`attribute of the function object.