Posted By

mouseroot on 01/02/11


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adkatrit
magna


Python mini Win32 Api Usage using ctypes :D


 / Published in: Python
 

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

  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  

You need to login to post a comment.