Python 2.6帮助中的ctypes [英] ctypes in Python 2.6 help
本文介绍了Python 2.6帮助中的ctypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法使该代码正常工作,给我的印象是我做得正确。
I can't seem to get this code to work, I was under the impression I was doing this correctly.
from ctypes import *
kernel32 = windll.kernel32
string1 = "test"
string2 = "test2"
kernel32.MessageBox(None,
string1,
string2,
MB_OK)
**我尝试将其更改为MessageBoxA,如下所示**
**错误I获取:: **
** I tried to change it to MessageBoxA as suggested below ** ** Error I get :: **
Traceback (most recent call last):
File "C:\<string>", line 6, in <module>
File "C:\Python26\Lib\ctypes\__init__.py", line 366, in __getattr__
func = self.__getitem__(name)
File "C:\Python26\Lib\ctypes\__init__.py", line 371, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'MessageBoxA' not found
推荐答案
MessageBox是在user32中定义的,而不是kernel32,您也没有定义了MB_OK
,因此请改用此
MessageBox is defined in user32 not kernel32, you also haven't defined MB_OK so use this instead
windll.user32.MessageBoxA(None, string1, string2, 1)
我也建议使用 python win32 API 值得关注,因为它具有所有常量和命名函数
Also I recommend using python win32 API isntead of it ,as it has all constant and named functions
编辑:我的意思是使用
from ctypes import *
kernel32 = windll.kernel32
string1 = "test"
string2 = "test2"
#kernel32.MessageBox(None, string1, string2, MB_OK)
windll.user32.MessageBoxA(None, string1, string2, 1)
可以使用win32 api做同样的事情
same thing you can do using win32 api as
import win32gui
win32gui.MessageBox(0, "a", "b", 1)
这篇关于Python 2.6帮助中的ctypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文