我使用下面的代码来显示弹出消息
if platform.system() == 'Windows':
import ctypes
def message_box(title, text, style):
return ctypes.windll.user32.MessageBoxW(0, text, title, style)
if platform.system() == 'Windows':
message_box('Error', 'Phat sinh loi Unicode, kiem tra chi tiet trong %s' % common.ERR_LOG_FILE, 0)
当我的应用程序在Windows7中运行时,弹出窗口包含所有意外的中文字符,而我的原始消息(在代码片段中)只包含字母字符。这是我第一次使用ctypes,很困惑。 有人来解释一下,帮我解决。在
我猜你用的是python2。Python2的字符串是字节字符串,并被封送为字节字符串(
char*
)。python3的字符串是Unicode字符串,被封送为宽字符串(wchar_t*
)。如果不定义.argtypes
,ctypes
就不会进行错误检查,并且很乐意传递错误的类型。在要在Python 2上调用},这样
MessageBoxW
,请改为传递Unicode字符串,但最好定义.argtypes
和{ctypes
可以键入check并在参数出错时告诉您:相关问题 更多 >
编程相关推荐