您的位置:首页 > 编程语言 > Python开发

Python ctypes.string_at

2018-02-13 09:26 453 查看
Python ctypes.string_at

#ifdef __cplusplus
extern "C"
{
#endif
__declspec(dllexport) char * WINAPI get_str()
{
int str_len = ... // figure out how long it is gonna be and set it here
char *ary = (char *)malloc(sizeof(char) * str_len);

// populate the array
...

ary[str_len - 1] = '\0';

return ary;
}

#ifdef __cplusplus
}
#endif
mport ctypes

my_dll = ctypes.WinDLL("MyDLLName.dll")

some_str = ctypes.string_at(my_dll.get_str())

print some_str


pointer = my_dll.get_str()
some_str = ctypes.string_at(pointer)
# This is windows specific -
# on Posix, one have to load "libc.so" and use "free" from there:
ctypes.cdll.msvcrt.free(pointer)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐