Dll Python ctypes:WindowsError:异常:访问冲突读取0x00000028

Dll Python ctypes:WindowsError:异常:访问冲突读取0x00000028,dll,runtime-error,ctypes,messagebox,arcgis,Dll,Runtime Error,Ctypes,Messagebox,Arcgis,我试图通过调用user32.dll中的“MessageboxA”函数来创建一个简单的MessageBox函数,类似于ESRI的“pythonaddins.MessageBox()”函数。不同之处在于,无论是否在ArcGIS环境中使用,我的函数都应该工作 我找到了这篇文章,并通过查找函数文档对其进行了扩展,当在我的IDE(PyScripter)中调用时,它可以正常工作。但是,当我通过ArcMap Python窗口进行调用时,在第一次调用函数时,我总是遇到运行时错误 def MessageBox(T

我试图通过调用user32.dll中的“MessageboxA”函数来创建一个简单的MessageBox函数,类似于ESRI的“pythonaddins.MessageBox()”函数。不同之处在于,无论是否在ArcGIS环境中使用,我的函数都应该工作

我找到了这篇文章,并通过查找函数文档对其进行了扩展,当在我的IDE(PyScripter)中调用时,它可以正常工作。但是,当我通过ArcMap Python窗口进行调用时,在第一次调用函数时,我总是遇到运行时错误

def MessageBox(Title, Message, mb_type):
"""Raises a MessageBox dialog and returns as a string the label of the button
   pressed by the user.

   'mb_type' Code          Messagebox Type
   0                                "OK" only
   1                                "OK"/"Cancel"
   2                                "Abort"/"Retry"/"Ignore"
   3                                "Yes"/"No"/"Cancel"
   4                                "Yes"/"No"
   5                                "Retry"/"Cancel"
   6                                "Cancel"/"Try Again"/"Continue"
   """
import ctypes
MB = ctypes.windll.user32.MessageBoxA
returnCode = MB(None, Message, Title, mb_type)
if returnCode == 1:
    return "OK"
elif returnCode == 2:
    return "Cancel"
elif returnCode == 3:
    return "Abort"
elif returnCode == 4:
    return "Retry"
elif returnCode == 5:
    return "Ignore"
elif returnCode == 6:
    return "Yes"
elif returnCode == 7:
    return "No"
elif returnCode == 10:
    return "Try Again"
elif returnCode == 11:
    return "Continue"
else:
    if mb_type < 0 or mb_type > 6:
        raise Exception("Parameter for argument 'mb_type' is invalid. " \
                        "Parameter must be a value in range of 0:7")
def消息框(标题、消息、mb_类型):
“”“引发MessageBox对话框,并以字符串形式返回按钮的标签。”
由用户按下。
“mb_类型”代码消息框类型
仅限0“OK”
1“确定”/“取消”
2“中止”/“重试”/“忽略”
3“是”/“否”/“取消”
4“是”/“否”
5“重试”/“取消”
6“取消”/“重试”/“继续”
"""
导入ctypes
MB=ctypes.windell.user32.MessageBoxA
returnCode=MB(无、消息、标题、MB_类型)
如果returnCode==1:
返回“OK”
elif returnCode==2:
返回“取消”
elif returnCode==3:
返回“中止”
elif returnCode==4:
返回“重试”
elif returnCode==5:
返回“忽略”
elif returnCode==6:
返回“是”
elif returnCode==7:
返回“否”
elif returnCode==10:
返回“重试”
elif returnCode==11:
返回“继续”
其他:
如果mb_类型<0或mb_类型>6:
引发异常(“参数'mb_type'的参数无效。”\
“参数必须是0:7范围内的值”
在ArcMap Python窗口内的第一次调用中,返回值为:

Runtime error 
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 16, in MessageBox
WindowsError: exception: access violation reading 0x00000028
运行时错误
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
MessageBox中第16行的文件“”
WindowsError:异常:访问冲突读取0x00000028
在第一次调用和运行时错误之后,它工作正常,并返回最初预期的纯文本按钮标签。

最近,我得到了一个类似的“访问冲突”,我可以使用str()解决它

所以,你可以试着替换

MB(None, Message, Title, mb_type)
。。。与

MB(None, str(Message), str(Title), mb_type)

定义参数类型:
ctypes.windell.user32.MessageBoxA.argtypes=[ctypes.c\u void\u p,ctypes.c\u char\u p,ctypes.c\u char\u p,ctypes.c\u uint]
。这样,如果第2个或第3个参数是0x28,您将得到一个
ArgumentError
。这是python 33吗?请参见否,它是Python 2.7,与ArcGIS 10.1一起提供