python 调用 DLL 的函数,返回的字符串数组的食用方法

来源:互联网 发布:数据库设计的四个阶段 编辑:程序博客网 时间:2024/04/29 01:55

今天需要使用python获得dll的数组,查了一个下午终于找到方法了。

dll的函数:

    extern "C" _declspec(dllexport) char*  __stdcall get_string(){        return "hello world!";    }

python代码:

    dll = ctypes.windll.LoadLibrary("get_image.dll")    dll.get_string.restype = POINTER(c_ubyte)    //让函数返回ubyte* 类型    p = dll.get_string()    list = []    for n in range(255):        if p[n] == 0:            break;        list.append(chr(p[n]))  // ascll转换    list = ''.join(list)    print(list)    quit()

“hello world!”

0 0
原创粉丝点击