在python里调用c++的DLL出现Windows Error -529697949

我是用VS2013写的DLL,在python2.7里调用。
项目在我和同事的电脑上都能跑,可在另一台工作电脑中出现Windows Error -529697949.
在这台电脑中,写的简单用来找问题的DLL也能跑。


于是工作陷入不断找问题排除问题的循环。/(ㄒoㄒ)/~~


最后我在VS里调试了调用DLL的这个py文件:test.py
参考了:https://blog.csdn.net/sagittarius_warrior/article/details/72832696

大概内容如下:


from ctypes import *
dll = cdll.LoadLibrary('HEELO_API.dll')
height = 480
width = 640
count = width*height
data_3D_x = (c_float*count)()
data_3D_y = (c_float*count)()
data_3D_z = (c_float*count)()
data_Intensity = (c_uint16*count)()
dll.save.restype = POINTER(c_ubyte)
ret = dll.save(data_3D_x, data_3D_y, data_3D_z, data_Intensity)
list = []
for n in range(255):
    if ret[n] == 0:
        break;
    list.append(chr(ret[n]))
list = ''.join(list)
print list


解决步骤:首先配置DLL这个工程的属性:
第二步:将test.py放到上述工作目录中(工作目录的位置你可以自己修改)

第三步:调试->启动调试F5 ,这样就会启动cmd.exe,然后你在cmd上输入python test.py(前提是你设置过环境变量,要不然它运行不了)
我的项目显示:

File "C:\Python27\lib\ctypes\__init__.py", line 444, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)

WindowsError: [Error 126]

这个时候我才发现是VC++运行库缺失了。

然后我去下载了64位的2013版本的VC++运行库,下载地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=40784,安装之后运行就成功了。
o(* ̄▽ ̄*)ブ万岁
 
 


猜你喜欢

转载自blog.csdn.net/spy14414/article/details/80088590
今日推荐