【发布时间】:2013-05-06 17:45:32
【问题描述】:
我正在尝试在 python 中使用 C++ dll。我在 Windows server 2012 上运行 python 2.7;都是 64 位的。
要创建 dll,我按照http://msdn.microsoft.com/en-us/library/vstudio/ms235636.aspx 上的“演练:创建和使用动态链接库 (C++)”中的说明进行操作。我使用了他们的示例代码。我是 dll 和 python 的新手,所以我想我会从示例开始。
我的python代码:
from ctypes import *
hw = CDLL("Y:\dll_check\MathFuncsDll.dll")
print "HelloWorld"
我收到以下错误:
Y:\dll_check> python .\MathFuncsMain/py
Traceback (most recent call last):
File ".\MathFunsMain.py"
libimgr = CDLL("Y:\dll_check\MathFuncsDll.dll")
File "C:Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application
是什么导致了我的错误?
【问题讨论】:
-
也许您正在将 64 位 DLL 加载到 32 位进程中?
-
从命令行运行此命令时的输出是什么:
python -c 'import struct;print( 8 * struct.calcsize("P"))'? -
我该如何检查?还是改正?
-
import struct;print(8 * struct.calcsize("P")) 输出 64