Skip to content

Instantly share code, notes, and snippets.

@mtask
Last active May 7, 2017 07:44
Show Gist options
  • Save mtask/7ee674a88a5a6108e33254ebaf6c0ea1 to your computer and use it in GitHub Desktop.
Save mtask/7ee674a88a5a6108e33254ebaf6c0ea1 to your computer and use it in GitHub Desktop.
Python Ctypes Windows examples
from ctypes import *
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
######################
# Yes/No msg box
#####################
a = windll.user32.MessageBoxW(0, "Hello\n", "The Title\n",4)
print("Return code: "+str(a))
if a == 6:
print("Yes was clicked")
elif a == 7:
print("No was clicked")
##############
# Info msg box witt ok button and info icon
##############
# Check link above for explanation to 0x40
windll.user32.MessageBoxW(0,"info icon message\n","info title\n",0 | 0x40)
#########
# printf
#########
msvcrt = CDLL('msvcrt')
message_string = b"Printing with printf function\n"
msvcrt.printf(b"Testing: %s\n", message_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment