我试图在64位python应用程序中使用来自kernel32的kernel32。
这是我理想中希望工作的代码:
import ctypes
from ctypes import *
interlockedValue = ctypes.c_long(5)
print(interlockedValue.value)
locked = ctypes.c_long(68)
print(windll.kernel32.InterlockedExchange(byref(interlockedValue),locked))
print(interlockedValue.value)不过,这是我的64位python 3.5.2的输出:
C:\Users\Douglas Sexton\Source\Repos\SharedMemory\SharedMemory\Python>python interlocked3.py
5
Traceback (most recent call last):
File "interlocked3.py", line 10, in <module>
print(windll.kernel32.InterlockedExchange(byref(interlockedValue), locked))
File "C:\Program Files (x86)\Python35\lib\ctypes\__init__.py", line 360, in __getattr__
func = self.__getitem__(name)
File "C:\Program Files (x86)\Python35\lib\ctypes\__init__.py", line 365, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'InterlockedExchange' not found不过,32位的工作原理与我所期望的一样:
C:\Users\Douglas Sexton\Source\Repos\SharedMemory\SharedMemory\Python>"C:\Program Files (x86)\Python36\python.exe" interlocked3.py
5
5
68我还试着从顺序访问:
import ctypes
from ctypes import *
interlockedValue = ctypes.c_long(5)
print(interlockedValue.value)
locked = ctypes.c_long(68)
print(windll.kernel32[868](byref(interlockedValue), locked))
print(interlockedValue.value)这对于32位有相同的输出,但是对于64位,这是输出:
C:\Users\Douglas Sexton\Source\Repos\SharedMemory\SharedMemory\Python>python interlocked.py
5
0
0现在,我尝试了几种不同的方式从python 64访问InterlockedExchange,似乎都遇到了相同的问题。我已经能够使用python64中的其他kernel32函数。快把我逼疯了。
发布于 2017-10-09 18:31:39
我现在不需要这个了,但是我能够为InterlockedExchange创建一个包装器dll,并从64个进程中成功地使用它。
https://stackoverflow.com/questions/46339154
复制相似问题