欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python ctypes庫2_指定參數(shù)類型和返回類型詳解

 更新時間:2019年11月19日 10:03:55   作者:inch2006  
今天小編就為大家分享一篇python ctypes庫2_指定參數(shù)類型和返回類型詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

python函數(shù)的參數(shù)類型和返回類型默認為int。

如果需要傳遞一個float值給dll,那么需要指定參數(shù)的類型。

如果需要返回一個flaot值到python中,那么需要指定返回數(shù)據(jù)的類型。

數(shù)據(jù)類型參考python文檔:

https://docs.python.org/3.6/library/ctypes.html#fundamental-data-types

import ctypes
path = r'E:\01_Lab\VisualStudioLab\cpp_dll\cpp_dll\Debug\cpp_dll.dll'
dll = ctypes.WinDLL(path)
 
dll.add_float.argtypes = [ctypes.c_float,ctypes.c_float]
dll.add_float.restype = ctypes.c_float
 
data_float = dll.add_float(7,10) # (ctypes.c_float(7.0),ctypes.c_float(10.0))

c++中函數(shù)如下:

DLLEXPORT float __stdcall add_float(float a,float b)
{
 float sum = a + b;
 return sum;
}

以上這篇python ctypes庫2_指定參數(shù)類型和返回類型詳解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論