title: Python ctypes: WindowsError: exception: access violation reading 0x00000028
body: <p>I'm trying to create a simple MessageBox function, similar to ESRI's 'pythonaddins.MessageBox()' function by invoking the 'MessageboxA' function in the user32.dll. The difference is that my function should work regardless of whether or not it's being leveraged inside of the ArcGIS environment. </p>
  
  <p>I found this post and just expanded on it by looking up the function documentation and it works just fine when invoked in my IDE (PyScripter). However, I keep getting a Runtime error on the first function invocation when I invoke through the ArcMap Python Window.</p>
  
  <pre><code>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 &lt; 0 or mb_type &gt; 6:
          raise Exception("Parameter for argument 'mb_type' is invalid. " \
                          "Parameter must be a value in range of 0:7")
  </code></pre>
  
  <p>On the first invocation inside of the ArcMap Python Window, the return is:</p>
  
  <pre><code>Runtime error 
  Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "&lt;string&gt;", line 16, in MessageBox
  WindowsError: exception: access violation reading 0x00000028
  </code></pre>
  
  <p>After the first invocation and runtime error, it works just fine afterwards and returns the plain text button label as originally intended.</p>