Python mini Win32 Api Usage using ctypes :D


/ Published in: Python
Save to your folder(s)

here i call some win32 api stuff using ctypes i wrote wrappers for c_char_p() and c_int aswell as c_long
as always comments and criticism is welcomed :D


Copy this code and paste it in your HTML
  1. from ctypes import *
  2.  
  3. class Win32api():
  4. def __init__(self):
  5. self.SetWindowText = windll.user32.SetWindowTextA #msdn for what dll to use
  6. self.FindWindow = windll.user32.FindWindowA # i dont use unicode(maybe i should?)
  7.  
  8. def String(self,s):
  9. return c_char_p(s)
  10.  
  11. def Int(self,i):
  12. return c_int(i)
  13.  
  14. def Long(self,l):
  15. return c_long(l)
  16.  
  17. #small test open command prompt type title lol
  18. test = Win32api()
  19.  
  20. #none in python is == NULL in C(more or less)
  21. ret = test.FindWindow(None,test.String("lol"))
  22.  
  23. #ret holds the window handle HWND(which is really a long/int)
  24. test.SetWindowText(ret,test.String("Command Prompt :D"))
  25.  
  26. print("done")
  27. #just for good measure!

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.