在 python 中加载 DLL 时出错,不是有效的 win32 应用程序 [英] Error loading DLL in python, not a valid win32 application

查看:37
本文介绍了在 python 中加载 DLL 时出错,不是有效的 win32 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 python 中加载一个 DLL 来调用函数.

I am trying to load a DLL in python to call functions.

import ctypes
from ctypes import *

dsusb = ctypes.WinDLL('c:python27dsusb.dll')

我的堆栈中出现以下错误.

I get the following error in my stack.

C:Python27>python test.py
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    dsusb = ctypes.WinDLL('c:python27dsusb.dll')
  File "C:Python27libctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application

我也用相同的代码尝试了 cdll.

I also tried cdll with the same code.

我查了一下错误,windows 说这是因为路径包含空格......我认为这不是问题......

I looked up the error and windows says it's due to a path containing spaces... which I do not think is really the problem...

我加载这个 DLL 是错误还是 dll 中可能有错误?

Am I loading this DLL wrong or is there something that might be wrong in the dll?

推荐答案

正如评论所暗示的,这可能是一个架构问题.

As the comments suggest, it could be an architecture problem.

如果您在 64 位 Python 中使用 32 位 DLL,反之亦然,那么您可能会遇到错误.

If you're using a 32bit DLL with 64bit Python, or vice-versa, then you'll probably get errors.

由于我之前遇到过您的错误,我建议您尝试使用 32 位 Python 加载您的 DLL.

Since I've had your error before, I recommend trying to load your DLL with 32bit Python.

测试 *.dll 文件是 32 位还是 64 位的一种方法是使用 dumpbin.exe,例如

One way to test if a *.dll-file is 32bit or 64bit, is to use dumpbin.exe, e.g.

dumpbin /headers dsusb.dll

...

FILE HEADER VALUES
             14C machine (x86)
...

machine (x86) 表示 32 位,machine (x64) 表示 64 位.

machine (x86) means 32bit, machine (x64) means 64bit.

这篇关于在 python 中加载 DLL 时出错,不是有效的 win32 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆