【发布时间】:2018-02-28 12:49:15
【问题描述】:
此 python 代码调用一个 dll(在 LabVIEW 中创建),它返回作为参数传递的字符串的大小。 每次我尝试传递不同大小的字符串时,它都会返回大小为“1”。 我试过用 C、LabVIEW 等不同的编程语言调用 dll,效果很好。
dll文件下载链接:https://drive.google.com/open?id=1pnYI6-SfUY3Cn6EeD4mWUO6dlEBH3DmN
import ctypes
from ctypes import windll, cdll,\
c_wchar, c_size_t, c_ulonglong, c_wchar_p, c_void_p,\
sizeof,\
WinError
try:
dllhandle = ctypes.CDLL("Strlen.dll")
print("Library Loaded")
except Exception as e:
print("Can't open DLL:",e)
dllhandle.Strlen.argtypes = [ctypes.c_wchar_p]
dllhandle.Strlen.restype = ctypes.c_int32
data = "Hello"
data_ptr = ctypes.c_wchar_p(data)
print("Data Pointer:",data_ptr)
length = dllhandle.Strlen(data_ptr)
print("Data:",data)
print("String Length:",length)
谁能帮我解决这个问题?提前谢谢。
【问题讨论】:
-
SetExcursionFreeExecutionSetting是做什么的?你也有函数标题吗?我知道它为什么会这样,但我想在公开之前进行测试。虽然我有点不情愿在我的PC 上执行未知代码。其他语言怎么调用func?
标签: python pointers dll ctypes