---
title: "关于ctypes调用dll时的参数类型和返回值类型问题"
author: "daweibalong"
date: "2012-08-24T10:08:04Z"
tags: []
categories: ["编程语言"]
slug: "ctypes-dll"
draft: false
lastmod: "2012-08-24T10:08:04Z"
id: 1661005
url: "https://daweibalong.iteye.com/blog/1661005"
---

python 调用dll时，一般要指定参数类型和返回值类型:

```
import ctypes
ll=ctypes.CDLL("pythontest3.dll")
path= ctypes.c_char_p("C:\Users\Public\Pictures\Sample Pictures\\a.jpg")
path2= ctypes.c_char_p("C:\Users\Public\Pictures\Sample Pictures\\b.jpg")
ll.MSE.restype = ctypes.c_double#指定MSE的返回类型为double
ll.PSNR.restype=ctypes.c_double#指定PSNR的返回值为double
```

 

指定返回值类型很重要，否则得到的结果会有错误

```
ll.abc.argtypes =[ctypes.c_char_p,ctypes.c_char_p]#指定参数类型
print ll.MSE(path.value,path.value)
```