def CoCreateInstanceFromFactory(factory_ptr, iid_interface=pythoncom.IID_IDispatch, pUnkOuter=None): """Given a factory_ptr whose interface is IClassFactory, create the instance of clsid_class with the specified interface""" ClassFactory = pythoncom.ObjectFromAddress(factory_ptr.value, pythoncom.IID_IClassFactory) i = ClassFactory.CreateInstance(pUnkOuter, iid_interface) return i
def CreateViewWindow(self, prev, settings, browser, rect): print "FileSystemView.CreateViewWindow", prev, settings, browser, rect self.cur_foldersettings = settings self.browser = browser self._CreateMainWindow(prev, settings, browser, rect) self._CreateChildWindow(prev) # This isn't part of the sample, but the most convenient place to # test/demonstrate how you can get an IShellBrowser from a HWND # (but ONLY when you are in the same process as the IShellBrowser!) # Obviously it is not necessary here - we already have the browser! browser_ad = win32gui.SendMessage(self.hwnd_parent, win32con.WM_USER+7, 0, 0) browser_ob = pythoncom.ObjectFromAddress(browser_ad, shell.IID_IShellBrowser) assert browser==browser_ob # and make a call on the object to prove it doesn't die :) assert browser.QueryActiveShellView()==browser_ob.QueryActiveShellView()
def CoCreateInstanceFromFactoryLicenced(factory_ptr, key, iid_interface=pythoncom.IID_IDispatch, pUnkOuter=None): """Given a factory_ptr whose interface is IClassFactory2, create the instance of clsid_class with the specified interface""" requested_iid = _raw_guid(iid_interface) ole_aut = WinDLL("OleAut32.dll") key_bstr = ole_aut.SysAllocString(unicode(key)) try: obj = IClassFactory2__CreateInstanceLic(factory_ptr, pUnkOuter or 0, c_char_p(requested_iid), key_bstr) disp_obj = pythoncom.ObjectFromAddress(obj, iid_interface) return disp_obj finally: if key_bstr: ole_aut.SysFreeString(key_bstr)
import pythoncom import pymod import pywintypes import win32com import win32com.client import json from ctypes import * user32 = windll.LoadLibrary('user32.dll') class EventHandler: def OnNameChanged(self, prev, cur): user32.MessageBoxW(0, prev + "->" + cur, 'OnReadRawDataComplete', 0) addr = pymod.getOcxPointer() ocx = pythoncom.ObjectFromAddress(addr, pythoncom.IID_IDispatch) idc = win32com.client.DispatchWithEvents(ocx, EventHandler) try: idc.ChangeMe("NewName", 0x335533) idc.ChangeMe("NewName2", 0x335533) except Exception as e: user32.MessageBoxW(0, str(e), 'title', 0) def func(): print("3");