From python-win32 at siteshadow.com Mon Dec 3 17:51:29 2012 From: python-win32 at siteshadow.com (Michael Wilson) Date: Mon, 3 Dec 2012 10:51:29 -0600 Subject: [python-win32] Ranges in a list of numbers Message-ID: Wow. What an amazingly helpful list. Thanks! Apologies for not fixing the subject. I was actually kicking myself right after I hit send for not personalizing that. I really like the options Tim has given me. I suppose I will try them out and see which one is most efficient for my application. Right now, I'm leaning towards the nums = [1, 3, (5,10), 18, 78] option. This is what I will be trying out: nums = [1, 3, (5,10), 18, 78] for item in nums: if isinstance(item,tuple): #Thanks Paul numHit = (newNum >= item[0]) and (newNum <= item[1]) else: numHit = newNum == item -Michael On Sat, Dec 1, 2012 at 5:00 AM, wrote: > Send python-win32 mailing list submissions to > python-win32 at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-win32 > or, via email, send a message with subject or body 'help' to > python-win32-request at python.org > > You can reach the person managing the list at > python-win32-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of python-win32 digest..." > > > Today's Topics: > > 1. Re: python-win32 Digest, Vol 116, Issue 13 (Michael Wilson) > 2. Re: python-win32 Digest, Vol 116, Issue 13 (Tim Roberts) > 3. Re: python-win32 Digest, Vol 116, Issue 13 (Paul_Koning at Dell.com) > 4. Re: python-win32 Digest, Vol 116, Issue 13 (Tim Roberts) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 30 Nov 2012 14:12:02 -0600 > From: Michael Wilson > To: python-win32 at python.org > Subject: Re: [python-win32] python-win32 Digest, Vol 116, Issue 13 > Message-ID: > pwW0QHcv_y3G7jNE7kq_n_KFTiCN9brv++Mc8ypCDA at mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > Hi everyone, > > I am new to Python. Been poking at it for about a month now. I am trying to > set up a list for information on people. > For example: > person 0's name = "Sam". li[0][0] > person 0's hoppy = "skateboarding" li[0][1] > person 0's favorite color = ["green", "red"] li[0][2] # it appears i can > put another list inside of the list, ie li[0][2]=[x,y,z] very cool! we > couldn't do that in my grandpa languages. Would that be done with a > li[0].append(['green','red']) after I'm done defining li[0][1]?? Then, I > could just do a li[0][2].extend(['purple','mauve']) if more colors were > ever needed? > person 0's favorite numbers = [1, 3, 5-10, 78] li[0][3] # ranges of > numbers? > person 1's name = "Mary" li[1][0] > etc.. > > My thought if there's not already an elegant solution in Python is to > create a flag 'r' before ranges. So, the example here would become > [1,3,'r',5,10,18,78]. Then I just do a > < query to find a match. How does > that sound? > newNum = 8 > numHit = False > for i in range(len(li[x][3])): > if li[x][3][i] == 'r': > if li[x][3][i+1] < newNum > li[x][3][i+2]: # I didn't do <= and >= > because the = parts will be evaluated in the next 2 iterations of the loop > numHit == True > else: > if newNum == li[x][3][i]: > numHit == True > if numHit: > print "You picked one of " + li[x][0] + "'s lucky numbers!" > > How does that look? Is that ~ the best way to address my problem? > > Thanks! > Michael > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/python-win32/attachments/20121130/2654d10b/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Fri, 30 Nov 2012 13:20:28 -0800 > From: Tim Roberts > To: Python-Win32 List > Subject: Re: [python-win32] python-win32 Digest, Vol 116, Issue 13 > Message-ID: <50B9231C.8090402 at probo.com> > Content-Type: text/plain; charset="ISO-8859-1" > > In the future, I'd like to suggest that you choose a genuine subject > line when you post. It makes people more inclined to read your messages. > > > Michael Wilson wrote: > > > > My thought if there's not already an elegant solution in Python is to > > create a flag 'r' before ranges. So, the example here would become > > [1,3,'r',5,10,18,78]. Then I just do a > < query to find a match. How > > does that sound? > > I can think of several approaches. For a range, you could add a > two-tuple instead of an integer: > nums = [1, 3, (5,10), 18, 78] > You can tell the difference at runtime: > for item in nums: > if type(item) == tuple: > numHit = (newNum >= item[0]) and (newNum <= item[1]) > else: > numHit = newNum == item > > To eliminate the special case, you could embed ALL of the numbers as > ranges of size one: > nums = [ (1,1), (3,3), (5,10), (18,18), (78,78) ] > > Or, unless you plan to allow numbers in the millions, just add the whole > range to the list individually: > nums = [1, 3] > nums.extend( range(5,10+1) ) > nums.append( 18 ) > nums.append( 78 ) > > > > for i in range(len(li[x][3])): > > Almost always, when you write a for loop with range(len(xxx)), you can > do the same thing without them: > for i in li[x][3]: > If you really do need the index, you can do: > for index, i in enumerate(li[x][3]): > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > > > ------------------------------ > > Message: 3 > Date: Fri, 30 Nov 2012 21:23:56 +0000 > From: > To: > Cc: python-win32 at python.org > Subject: Re: [python-win32] python-win32 Digest, Vol 116, Issue 13 > Message-ID: > > > Content-Type: text/plain; charset="us-ascii" > > > On Nov 30, 2012, at 4:20 PM, Tim Roberts wrote: > > > In the future, I'd like to suggest that you choose a genuine subject > > line when you post. It makes people more inclined to read your messages. > > > > > > Michael Wilson wrote: > >> > >> My thought if there's not already an elegant solution in Python is to > >> create a flag 'r' before ranges. So, the example here would become > >> [1,3,'r',5,10,18,78]. Then I just do a > < query to find a match. How > >> does that sound? > > > > I can think of several approaches. For a range, you could add a > > two-tuple instead of an integer: > > nums = [1, 3, (5,10), 18, 78] > > You can tell the difference at runtime: > > for item in nums: > > if type(item) == tuple: > > Nit: the Pythonic recommended way of doing this is "if isinstance (item, > tuple):" > > The difference is that this will also work if item is an instance of a > subclass of "tuple" while the original code does not handle that case. For > this code, that might not be an interesting scenario, but in other places > it might be. It's worth getting into the habit of using "isinstance". > > paul > > > > > ------------------------------ > > Message: 4 > Date: Fri, 30 Nov 2012 13:27:24 -0800 > From: Tim Roberts > To: Python-Win32 List > Subject: Re: [python-win32] python-win32 Digest, Vol 116, Issue 13 > Message-ID: <50B924BC.1010807 at probo.com> > Content-Type: text/plain; charset="ISO-8859-1" > > Paul_Koning at Dell.com wrote: > > > > Nit: the Pythonic recommended way of doing this is "if isinstance (item, > tuple):" > > > > The difference is that this will also work if item is an instance of a > subclass of "tuple" while the original code does not handle that case. For > this code, that might not be an interesting scenario, but in other places > it might be. It's worth getting into the habit of using "isinstance". > > Well said. I have several bad Python habits that I should work on > eliminating... > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > ------------------------------ > > End of python-win32 Digest, Vol 117, Issue 1 > ******************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dfh at forestfield.co.uk Wed Dec 5 13:13:30 2012 From: dfh at forestfield.co.uk (David Hughes) Date: Wed, 05 Dec 2012 12:13:30 +0000 Subject: [python-win32] com_error in win32com/client.Moniker Message-ID: <50BF3A6A.7010707@forestfield.co.uk> Originally posted in py2exe-users at lists.sourceforge.net but re-posted here at the suggestion of Mark Hammond: A customer running my software, distributed via py2exe (Python 2.7.2) is consistently getting the following error **** Mon Dec 03 13:20:25 2012 **** Traceback (most recent call last): File "__main__.py", line 838, in File "__main__.py", line 331, in bootstrap File "__main__.py", line 358, in chainload File "__main__.py", line 834, in _chainload File "dietplan6.py", line 342, in File "dietplan6.py", line 332, in main File "wx\_core.pyc", line 8631, in __init__ File "wx\_core.pyc", line 8196, in _BootstrapApp File "dietplan6.py", line 171, in OnInit File "licence_installed.pyc", line 28, in CheckLicence File "licence_installed.pyc", line 105, in InstallLicence File "licence_installed.pyc", line 252, in openmasterlicence File "licence.pyc", line 314, in IsMasterValid File "library\oslib.pyc", line 192, in get_vol_info File "wmi.pyc", line 157, in File "win32com\client\__init__.pyc", line 72, in GetObject File "win32com\client\__init__.pyc", line 87, in Moniker com_error: (-2147024770, 'The specified module could not be found.', None, None) oslib.pyc", line 192, in get_vol_info contains from wmi import WMI as WMI prior to obtaining the details of an attached USB flash drive. It has been confirmed the error is specific to that particular machine (running 32 bit Windows 7, I believe). Has anyone come across this problem or have any suggestions please as to probable cause and, of course, solution? -- Regards David Hughes Forestfield Software From mail at timgolden.me.uk Wed Dec 5 13:39:32 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 05 Dec 2012 12:39:32 +0000 Subject: [python-win32] com_error in win32com/client.Moniker In-Reply-To: <50BF3A6A.7010707@forestfield.co.uk> References: <50BF3A6A.7010707@forestfield.co.uk> Message-ID: <50BF4084.9030404@timgolden.me.uk> On 05/12/2012 12:13, David Hughes wrote: > Originally posted in py2exe-users at lists.sourceforge.net but re-posted > here at the suggestion of Mark Hammond: > > A customer running my software, distributed via py2exe (Python 2.7.2) is > consistently getting the following error > > **** Mon Dec 03 13:20:25 2012 **** > Traceback (most recent call last): > File "__main__.py", line 838, in > File "__main__.py", line 331, in bootstrap > File "__main__.py", line 358, in chainload > File "__main__.py", line 834, in _chainload > File "dietplan6.py", line 342, in > File "dietplan6.py", line 332, in main > File "wx\_core.pyc", line 8631, in __init__ > File "wx\_core.pyc", line 8196, in _BootstrapApp > File "dietplan6.py", line 171, in OnInit > File "licence_installed.pyc", line 28, in CheckLicence > File "licence_installed.pyc", line 105, in InstallLicence > File "licence_installed.pyc", line 252, in openmasterlicence > File "licence.pyc", line 314, in IsMasterValid > File "library\oslib.pyc", line 192, in get_vol_info > File "wmi.pyc", line 157, in > File "win32com\client\__init__.pyc", line 72, in GetObject > File "win32com\client\__init__.pyc", line 87, in Moniker > com_error: (-2147024770, 'The specified module could not be found.', > None, None) > > oslib.pyc", line 192, in get_vol_info contains > > from wmi import WMI as WMI > > prior to obtaining the details of an attached USB flash drive. > > It has been confirmed the error is specific to that particular machine > (running 32 bit Windows 7, I believe). Has anyone come across this > problem or have any suggestions > please as to probable cause and, of course, solution? I had someone with a very similar error contact me recently. (I'm the author of the wmi module). In that case it turned out to be a borked Windows configuration. Can you access WMI on that machine by, eg, VBS or Powershell -- ie something built-in? TJG From dfh at forestfield.co.uk Thu Dec 6 13:25:36 2012 From: dfh at forestfield.co.uk (David Hughes) Date: Thu, 06 Dec 2012 12:25:36 +0000 Subject: [python-win32] com_error in win32com/client.Moniker (2) Message-ID: <50C08EC0.3090101@forestfield.co.uk> Tim Golden wrote* * > I had someone with a very similar error contact me recently. (I'm the > author of the wmi module). In that case it turned out to be a borked > Windows configuration. Can you access WMI on that machine by, eg, VBS or > Powershell -- ie something built-in? This probably won't thread properly as I wasn't subscribed when Tim wrote the above, and I had to visit the archive. I have sent the customer a small VBS script I used when I was developing the Python WMI version and am awaiting a reply. I have also found the following resources which seem relevant: http://stackoverflow.com/questions/7078184/unable-to-get-wmi-object-via-getobjectwinmgmts?rq=1 which offers some possible reset/repair options and also leads to the Microsoft WMI Diagnosis Utility http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=7684 -- Regards David Hughes Forestfield Software -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at kinematics.com Thu Dec 13 01:36:53 2012 From: dave at kinematics.com (Dave Calkins) Date: Wed, 12 Dec 2012 19:36:53 -0500 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" Message-ID: <50C92325.4060601@kinematics.com> I'd like to be able to call an OLE Automation (IDispatch) server from python to automate an existing application. I'm not at liberty to change the existing automation interface provided by the application so I need to get it to work with what the app currently exposes. The interface I'm attempting to work with makes use of "out params". Here's an excerpt from the IDL for a small sample app I created to reproduce the issue. ========== dispinterface IMyApp { properties: methods: [id(1)] void ShowMessage(BSTR msg); [id(2)] void SetSettingValue(BSTR settingName, BSTR settingValue); [id(3)] void GetSettingValue(BSTR settingName, BSTR* settingValue); }; ========== The first two methods are straightforward and I had no problem calling them from python. The problem is the third one, GetSettingValue, since it requires you to pass in a reference to a variable which it then fills in for you. I read through CH12 of "Python Programming on Win32" by Hammond/Robinson as a guide. Based on that I installed pywin32 and then tried running MakePy. Here's an excerpt of the code generated by MakePy. ========== def GetSettingValue(self, settingName=defaultNamedNotOptArg, settingValue=defaultNamedNotOptArg): return self._oleobj_.InvokeTypes(3, LCID, 1, (24, 0), ((8, 0), (16392, 0)),settingName , settingValue) def SetSettingValue(self, settingName=defaultNamedNotOptArg, settingValue=defaultNamedNotOptArg): return self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), ((8, 0), (8, 0)),settingName , settingValue) def ShowMessage(self, msg=defaultNamedNotOptArg): return self._oleobj_.InvokeTypes(1, LCID, 1, (24, 0), ((8, 0),),msg ) ========== Comparing what it generated for GetSettingValue vs. SetSettingValue I noted the difference of 16392 vs. 8. Looking up those in the windows headers it appears those numeric constants correspond to VT_BYREF|VT_BSTR vs. VT_BSTR. So MakePy is generating something different for the "out param" and it seems to even be noticing that its by reference. I haven't figured out how to actually call this, though. In CH12 of the book I mentioned, it is noted that for such methods the params are converted to return values instead. The example given in the book is: ========== ok = GetSize( &left, &right, &top, &bottom); becomes left, right, top, bottom = GetSize() ========== It doesn't appear that this is happening with the MakePy results I'm getting. But clearly MakePy is detecting the "by reference" parameter. Here's the output I get when attempting to call this method. I just sort of guessed at how I might call that method. ========== Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> x = win32com.client.Dispatch("MyApp.Application") >>> x.ShowMessage("Hello, world") >>> x.SetSettingValue("sName","sValue") >>> sValue = "" >>> x.GetSettingValue("sName",sValue) Traceback (most recent call last): File "", line 1, in File "", line 2, in GetSettingValue pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2) >>> sValue = x.GetSettingName("sName") Traceback (most recent call last): File "", line 1, in File "C:\Users\dave\apps\Python273\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: MyApp.Application.GetSettingName >>> ========== Any advice on how I can make use of this method, which takes "out params", from python? From gilles.baggieri at gmail.com Fri Dec 14 01:04:44 2012 From: gilles.baggieri at gmail.com (Gilles Baggieri) Date: Fri, 14 Dec 2012 00:04:44 +0000 (UTC) Subject: [python-win32] a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture References: <20120325193320.20AD.AD92716B@163.com> <4F6F0F3B.4010209@gmail.com> Message-ID: Mark Hammond gmail.com> writes: > > I'm not familiar enough with ctypes to know if that makes sense, but I > doubt it - nothing would seem to know the size of the buffer pointed at > by 'x'. You probably need to stick with using a python string object - > ensure the string contains exactly the bytes of the metafile. > > Mark > > On 25/03/2012 10:33 PM, shuwj wrote: > > > >> I believe a c_void_p is a ctypes construct which aren't supported by > >> pywin32. You need to convert it to a "normal" Python type. I'm > >> guessing it is binary data, so in py2k, you should be able to simply use > >> buffer(some_string_object). The error message seems to imply you may > >> even be able to use buffer(c_void_p_object), but I don't know how they > >> work well enough to suggest that will actually work. > >> > >> Mark > >> > > > > Hi Mark, > > Thanks for your reply. I use buffer() in GetImage method and there's no > > exception now, but they don't work as expected. > > > > > > ----------------------------------------- > > class wordaddin: > > def GetImage(self,ctrl): > > from gdiplus import LoadImage > > i = LoadImage( 'c:/edit.png' ) > > i = buffer(i) > > print i, 'ddd' > > return i > > ----------------------------------------- > > > > > Hello, After spending several hours with the same problem (thanks for gdiplus.py, great job!), I've found a solution from Thomas Heller's comtypes testunits. The idea is to cast 'x' (pointer) to a comtypes POINTER(IUnknown), and then convert again to pythoncom PyIDispatch. Add this to the end of gdiplus LoadImage (but don't use buffer() as the returned object can be return as is to RibbonX callback): ... if not x.value: return None from comtypes.automation import VARIANT, IUnknown, IDispatch from ctypes import cast, POINTER, PyDLL, py_object, c_void_p, byref from ctypes.wintypes import BOOL import pythoncom # cast to comtypes IUnknown cobj = cast(x,POINTER(IUnknown)) # cast to PyIDispatch _PyCom_PyObjectFromIUnknown = PyDLL(pythoncom.__file__).PyCom_PyObjectFromIUnknown _PyCom_PyObjectFromIUnknown.restype = py_object _PyCom_PyObjectFromIUnknown.argtypes = (POINTER(IUnknown), c_void_p, BOOL) return _PyCom_PyObjectFromIUnknown(cobj, byref(IDispatch._iid_), True) Perhaps is there a shorter (and clearer!) way... Gilles From skippy.hammond at gmail.com Fri Dec 14 04:39:02 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 14 Dec 2012 14:39:02 +1100 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50C92325.4060601@kinematics.com> References: <50C92325.4060601@kinematics.com> Message-ID: <50CA9F56.4000604@gmail.com> On 13/12/2012 11:36 AM, Dave Calkins wrote: > I'd like to be able to call an OLE Automation (IDispatch) server from > python to automate an existing application. I'm not at liberty to > change the existing automation interface provided by the application so > I need to get it to work with what the app currently exposes. > > The interface I'm attempting to work with makes use of "out params". > Here's an excerpt from the IDL for a small sample app I created to > reproduce the issue. > > ========== > dispinterface IMyApp > { > properties: > > methods: > [id(1)] void ShowMessage(BSTR msg); > [id(2)] void SetSettingValue(BSTR settingName, BSTR > settingValue); > [id(3)] void GetSettingValue(BSTR settingName, BSTR* > settingValue); > }; > ========== > > The first two methods are straightforward and I had no problem calling > them from python. The problem is the third one, GetSettingValue, since > it requires you to pass in a reference to a variable which it then fills > in for you. > > I read through CH12 of "Python Programming on Win32" by Hammond/Robinson > as a guide. Based on that I installed pywin32 and then tried running > MakePy. Here's an excerpt of the code generated by MakePy. > > ========== > def GetSettingValue(self, settingName=defaultNamedNotOptArg, > settingValue=defaultNamedNotOptArg): > return self._oleobj_.InvokeTypes(3, LCID, 1, (24, 0), ((8, 0), > (16392, 0)),settingName > , settingValue) > > def SetSettingValue(self, settingName=defaultNamedNotOptArg, > settingValue=defaultNamedNotOptArg): > return self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), ((8, 0), > (8, 0)),settingName > , settingValue) > > def ShowMessage(self, msg=defaultNamedNotOptArg): > return self._oleobj_.InvokeTypes(1, LCID, 1, (24, 0), ((8, > 0),),msg > ) > ========== > > Comparing what it generated for GetSettingValue vs. SetSettingValue I > noted the difference of 16392 vs. 8. Looking up those in the windows > headers it appears those numeric constants correspond to > VT_BYREF|VT_BSTR vs. VT_BSTR. So MakePy is generating something > different for the "out param" and it seems to even be noticing that its > by reference. > > I haven't figured out how to actually call this, though. In CH12 of the > book I mentioned, it is noted that for such methods the params are > converted to return values instead. The example given in the book is: > > ========== > ok = GetSize( &left, &right, &top, &bottom); > becomes > left, right, top, bottom = GetSize() > ========== > > It doesn't appear that this is happening with the MakePy results I'm > getting. But clearly MakePy is detecting the "by reference" parameter. > > Here's the output I get when attempting to call this method. I just > sort of guessed at how I might call that method. > > ========== > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import win32com.client > >>> x = win32com.client.Dispatch("MyApp.Application") > >>> x.ShowMessage("Hello, world") > >>> x.SetSettingValue("sName","sValue") > >>> sValue = "" > >>> x.GetSettingValue("sName",sValue) > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in GetSettingValue > pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2) > >>> sValue = x.GetSettingName("sName") This is the form you should use, but the method name you are trying to call is "GetSettingValue", not "GetSettingName", hence the AttributeError. Mark > Traceback (most recent call last): > File "", line 1, in > File > "C:\Users\dave\apps\Python273\lib\site-packages\win32com\client\dynamic.py", > line 522, in __getattr__ > raise AttributeError("%s.%s" % (self._username_, attr)) > AttributeError: MyApp.Application.GetSettingName > >>> > ========== > > Any advice on how I can make use of this method, which takes "out > params", from python? > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Fri Dec 14 04:43:40 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 14 Dec 2012 14:43:40 +1100 Subject: [python-win32] a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture In-Reply-To: References: <20120325193320.20AD.AD92716B@163.com> <4F6F0F3B.4010209@gmail.com> Message-ID: <50CAA06C.4000803@gmail.com> I've lost some of the context here, but there is a pythoncom.ObjectFromAddress that looks like it does exactly what you want - check out the pywin32 docs for details... HTH, Mark On 14/12/2012 11:04 AM, Gilles Baggieri wrote: > Mark Hammond gmail.com> writes: > >> >> I'm not familiar enough with ctypes to know if that makes sense, but I >> doubt it - nothing would seem to know the size of the buffer pointed at >> by 'x'. You probably need to stick with using a python string object - >> ensure the string contains exactly the bytes of the metafile. >> >> Mark >> >> On 25/03/2012 10:33 PM, shuwj wrote: >>> >>>> I believe a c_void_p is a ctypes construct which aren't supported by >>>> pywin32. You need to convert it to a "normal" Python type. I'm >>>> guessing it is binary data, so in py2k, you should be able to simply use >>>> buffer(some_string_object). The error message seems to imply you may >>>> even be able to use buffer(c_void_p_object), but I don't know how they >>>> work well enough to suggest that will actually work. >>>> >>>> Mark >>>> >>> >>> Hi Mark, >>> Thanks for your reply. I use buffer() in GetImage method and there's no >>> exception now, but they don't work as expected. >>> >>> >>> ----------------------------------------- >>> class wordaddin: >>> def GetImage(self,ctrl): >>> from gdiplus import LoadImage >>> i = LoadImage( 'c:/edit.png' ) >>> i = buffer(i) >>> print i, 'ddd' >>> return i >>> ----------------------------------------- >>> >>> >> > Hello, > > After spending several hours with the same problem (thanks for gdiplus.py, great > job!), I've found a solution from Thomas Heller's comtypes testunits. The idea > is to cast 'x' (pointer) to a comtypes POINTER(IUnknown), and then convert again > to pythoncom PyIDispatch. > Add this to the end of gdiplus LoadImage (but don't use buffer() as the returned > object can be return as is to RibbonX callback): > > > ... > if not x.value: > return None > > from comtypes.automation import VARIANT, IUnknown, IDispatch > from ctypes import cast, POINTER, PyDLL, py_object, c_void_p, byref > from ctypes.wintypes import BOOL > import pythoncom > > # cast to comtypes IUnknown > cobj = cast(x,POINTER(IUnknown)) > > # cast to PyIDispatch > _PyCom_PyObjectFromIUnknown = > PyDLL(pythoncom.__file__).PyCom_PyObjectFromIUnknown > _PyCom_PyObjectFromIUnknown.restype = py_object > _PyCom_PyObjectFromIUnknown.argtypes = (POINTER(IUnknown), c_void_p, BOOL) > > return _PyCom_PyObjectFromIUnknown(cobj, byref(IDispatch._iid_), True) > > > Perhaps is there a shorter (and clearer!) way... > > Gilles > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From dave at kinematics.com Fri Dec 14 14:56:08 2012 From: dave at kinematics.com (Dave Calkins) Date: Fri, 14 Dec 2012 08:56:08 -0500 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CA9F56.4000604@gmail.com> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> Message-ID: <50CB2FF8.8070605@kinematics.com> On 12/13/2012 10:39 PM, Mark Hammond wrote: > This is the form you should use, but the method name you are trying to > call is "GetSettingValue", not "GetSettingName", hence the > AttributeError. > > Mark Ah, yes. Good catch! Unfortunately, correcting that typo didn't seem to fix it. Here's what I get, when using the correct method name this time. ===== Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> x = win32com.client.Dispatch("MyApp.Application") >>> x.ShowMessage("Hello World") >>> x.SetSettingValue("testName","testValue") >>> testValue = x.GetSettingValue("testName") Traceback (most recent call last): File "", line 1, in File "", line 2, in GetSettingValue pywintypes.com_error: (-2147352561, 'Parameter not optional.', None, None) ===== It appears it does want that second parameter, but passing in a variable doesn't seem to work. ===== >>> testValue = "" >>> x.GetSettingValue("testName",testValue) Traceback (most recent call last): File "", line 1, in File "", line 2, in GetSettingValue pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2) ===== From gilles.baggieri at gmail.com Sat Dec 15 19:59:04 2012 From: gilles.baggieri at gmail.com (Gilles Baggieri) Date: Sat, 15 Dec 2012 18:59:04 +0000 (UTC) Subject: [python-win32] a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture References: <20120325193320.20AD.AD92716B@163.com> <4F6F0F3B.4010209@gmail.com> <50CAA06C.4000803@gmail.com> Message-ID: Mark Hammond gmail.com> writes: > > I've lost some of the context here, but there is a > pythoncom.ObjectFromAddress that looks like it does exactly what you > want - check out the pywin32 docs for details... > > HTH, > > Mark > Thanks Mark. It works fine with only this: import pythoncom return pythoncom.ObjectFromAddress( x.value, pythoncom.IID_IDispatch ) Simplier, clearer... From skippy.hammond at gmail.com Sun Dec 16 06:46:13 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sun, 16 Dec 2012 16:46:13 +1100 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CB2FF8.8070605@kinematics.com> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> Message-ID: <50CD6025.2060704@gmail.com> On 15/12/2012 12:56 AM, Dave Calkins wrote: > > On 12/13/2012 10:39 PM, Mark Hammond wrote: >> This is the form you should use, but the method name you are trying to >> call is "GetSettingValue", not "GetSettingName", hence the >> AttributeError. >> >> Mark > > Ah, yes. Good catch! Unfortunately, correcting that typo didn't seem > to fix it. Here's what I get, when using the correct method name this > time. > > ===== > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import win32com.client > >>> x = win32com.client.Dispatch("MyApp.Application") > >>> x.ShowMessage("Hello World") > >>> x.SetSettingValue("testName","testValue") > >>> testValue = x.GetSettingValue("testName") > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in GetSettingValue > pywintypes.com_error: (-2147352561, 'Parameter not optional.', None, None) > ===== > > It appears it does want that second parameter, but passing in a variable > doesn't seem to work. That's very strange. pywin32 *will* be passing a second param - a byref bstr. byref params do work in general, so you might need to contact the vendor of the object for help. Cheers, Mark > > ===== > >>> testValue = "" > >>> x.GetSettingValue("testName",testValue) > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in GetSettingValue > pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2) > ===== > > From dave at kinematics.com Sun Dec 16 14:54:55 2012 From: dave at kinematics.com (Dave Calkins) Date: Sun, 16 Dec 2012 08:54:55 -0500 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CD6025.2060704@gmail.com> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> Message-ID: <50CDD2AF.4090106@kinematics.com> On 12/16/2012 12:46 AM, Mark Hammond wrote: > That's very strange. pywin32 *will* be passing a second param - a > byref bstr. byref params do work in general, so you might need to > contact the vendor of the object for help. > > Cheers, > > Mark I'm the vendor of the object :) As I mentioned, I just created this small test app which reproduces the issue having just those 3 simple methods. However, I'm not able to talk to it via Python. It seems to be a pretty simple interface. Any idea what else I might be missing? What do I need to do on the python side to call that method with the out params? You indicated that the out params should be converted to a return value. Why does the MakePy generated method signature not indicate this? i.e. why does it show 2 arguments? You said above that pywin32 *will* be passing a second param - a byref bstr. That suggests to me that there's some other method I need to call which internally calls the real method from pywin32. Where is the method I need to call then? I don't see any method generated there with only a single arg? Dave From mhammond at skippinet.com.au Mon Dec 17 00:17:13 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 17 Dec 2012 10:17:13 +1100 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CDD2AF.4090106@kinematics.com> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> <50CDD2AF.4090106@kinematics.com> Message-ID: <50CE5679.904@skippinet.com.au> On 17/12/2012 12:54 AM, Dave Calkins wrote: > > On 12/16/2012 12:46 AM, Mark Hammond wrote: >> That's very strange. pywin32 *will* be passing a second param - a >> byref bstr. byref params do work in general, so you might need to >> contact the vendor of the object for help. >> >> Cheers, >> >> Mark > > I'm the vendor of the object :) As I mentioned, I just created this > small test app which reproduces the issue having just those 3 simple > methods. However, I'm not able to talk to it via Python. Is the source to this available? > It seems to > be a pretty simple interface. Any idea what else I might be missing? > What do I need to do on the python side to call that method with the out > params? Nope - it should all be good. For example, check out: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/TestSources/PyCOMTest/PyCOMTest.idl#l193 http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/TestSources/PyCOMTest/PyCOMImpl.cpp#l133 and (slightly cryptic) Python code which calls it: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/win32com/test/testPyComTest.py#l225 Which shows some "out" param tests (and while there is an inout bstr test, there doesn't seem to be a specific test for an out bstr, so it's still possible you have hit a pywin32 bug) > You indicated that the out params should be converted to a return > value. Why does the MakePy generated method signature not indicate > this? i.e. why does it show 2 arguments? The makepy signature really just reflects the params passed to the interface itself - hence those params all have default values. > You said above that pywin32 *will* be passing a second param - a byref > bstr. That suggests to me that there's some other method I need to call > which internally calls the real method from pywin32. Where is the method > I need to call then? I don't see any method generated there with only a > single arg? InvokeTypes is what does all the magic - it takes the VT_* values and builds real params in C++, and also builds the tuple (if necessary) which is returned. The params mainly exist for when the interface is *implemented* by Python rather than when called by Python - the same generated classes are used in both directions. Hope this clarifies... Mark From steffen.froemer at gns-systems.de Mon Dec 17 14:30:41 2012 From: steffen.froemer at gns-systems.de (Steffen =?iso-8859-1?b?RnL2bWVy?=) Date: Mon, 17 Dec 2012 14:30:41 +0100 Subject: [python-win32] check if comserver is registered, no -> install it? In-Reply-To: <50A28BE8.1010003@probo.com> References: <50A255FE.8070108@gns-systems.de> <50A28BE8.1010003@probo.com> Message-ID: <20121217143041.14333dr0lu5esc5d@webmail.gns-systems.de> Quoting Tim Roberts : > > There is no danger in redoing a registration that has already been > done. All it does is add some registry keys. Might as well just do it > every time. Add "/s" if you don't want to see the dialog box. > > Alternatively, assuming you are running a 64-bit Python, you can just > call the registration entry point directly: > import ctypes > dll = ctypes.OleDLL('myComServer.dll') > dll.DllRegisterServer() > > That's exactly what Regsvr32 does. It is not a highly sophisticated > application. Hi i tried to do exactly this. But on executing the line dll = ctypes.OleDLL('myComServer.dll') i get following error: Traceback (most recent call last): File "C:\Temp\com_tests.py", line 21, in x = ctypes.OleDLL(os.path.realpath(local_dll)) File "C:\Python32_x86_64\lib\ctypes\__init__.py", line 353, in __init__ self._handle = _dlopen(self._name, mode) WindowsError: [Error 193] %1 ist keine zul?ssige Win32-Anwendung what's the problem? Regards, Steffen Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)] on win32 From russ at perspexis.com Mon Dec 17 18:50:21 2012 From: russ at perspexis.com (Russell Warren) Date: Mon, 17 Dec 2012 12:50:21 -0500 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch Message-ID: I'm having a really difficult time trying to get a simple COM server demo working with win32com. No matter what I do I'm getting an automation error ("The specified module could not be found.") when I try and create the object from VBA with CreateObject(). The latest COM server I'm trying to create is a tweak of some samples I've pulled together: http://pastebin.com/iiz8duCu A screenshot of the simple VBA script that fails, with the exact error is this: http://static.inky.ws/image/3521/Selection_247.png What could be causing this? Is there any way to get further details? More info: - WinXP SP3 - python version: ActivePython 2.7.2.5 - I'm using the win32com package that came with ActivePython - The COM server seems to be registering perfectly. - When I look up the progid in the registry myself the LocalServer32 key is: - C:\Python27\pythonw.exe "C:\Python27\lib\site-packages\win32com\server\localserver.py" {BC0212DE-F1AF-4626-9E35-424CC4723C02} - Running the exact cmdline above (to localserver.py) myself works perfectly. As-is it does nothing apparent, but if I strip the GUID I get the appropriate usage msgbox. - The InprocServer32 key specifies "pythoncom27.dll" which does exist in my system32 folder. (I have no idea whether COM will use LocalServer32 or InprocServer32 at this point, but both seem fine. How does it decide?) - CreateObject() is definitely picking up the registration, but it seems to be failing internally... or at least when you pass an unregistered progid like "foo.foo" to CreateObject() the error you get is different -- "ActiveX component can't create object" - Registering with debugging enabled and using PythonWin's trace collector debugging tool is showing nothing., so presumably it is failing before anything is issued - I can't figure out where to get any further debugging info... I checked the Windows Event Viewer and there is nothing showing up with these errors. Any help in resolving this would be *greatly* appreciated!!! I don't know where to go from here. I've even gone so far as to bundle this up into a standalone ActiveX exe and dll with py2exe to see if that magically resolved anything, but (unsurprisingly) I get similar errors. Help! Russ -------------- next part -------------- An HTML attachment was scrubbed... URL: From russ at perspexis.com Mon Dec 17 20:27:47 2012 From: russ at perspexis.com (Russell Warren) Date: Mon, 17 Dec 2012 14:27:47 -0500 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch In-Reply-To: References: Message-ID: Update - it seems to be the pythoncom27.dll somehow. I tried deleting the InprocServer32 key and my com server works now. I see that I can dodge this issue by specifying _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER, but I'm concerned about what the problem could be with pythoncom27.dll and whether that will bite me some other way later. Any guesses on what the problem might be? Also - what is the purpose in defaulting to use both InprocServer32 and LocalServer32? Based on my problem, the default windows choice appears to be InprocServer32. When/why would it move on to the LocalServer32 entry? It clearly does not do it on error. Russ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at kinematics.com Tue Dec 18 00:46:12 2012 From: dave at kinematics.com (Dave Calkins) Date: Mon, 17 Dec 2012 18:46:12 -0500 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CE5679.904@skippinet.com.au> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> <50CDD2AF.4090106@kinematics.com> <50CE5679.904@skippinet.com.au> Message-ID: <50CFAEC4.50902@kinematics.com> On 12/16/2012 6:17 PM, Mark Hammond wrote: > >> I'm the vendor of the object :) As I mentioned, I just created this >> small test app which reproduces the issue having just those 3 simple >> methods. However, I'm not able to talk to it via Python. > > Is the source to this available? > Yes, its just a Visual C++ app-wizard generated project. In Visual C++ 2010 I used new >> project, selected MFC application, chose a dialog app with default settings but I checked the "Automation" checkbox so it would set it up as an OLE Automation server. Once created, in the Class view I right-clicked the IMyApp interface and chose Add >> Method. I did this for each method shown earlier. When you add a method this way, it adds it to the IDL and then adds implementation methods in the DlgProxy class it creates as part of the project. Then you just fill in the implementation methods that it created for you. Here is the IDL. ===== [ uuid(E85C16AC-7936-4792-8E2A-40537D9FA02B) ] dispinterface IMyApp { properties: methods: [id(1)] void ShowMessage(BSTR msg); [id(2)] void SetSettingValue(BSTR settingName, BSTR settingValue); [id(3)] void GetSettingValue(BSTR settingName, BSTR* settingValue); }; ===== Here's the implementation methods it created for the above. For the first two I'm just showing a message box with the passed in args. For the third, with the out param, I'm sending back a dummy value to the caller. ===== void CMyAppDlgAutoProxy::ShowMessage(LPCTSTR msg) { AFX_MANAGE_STATE(AfxGetAppModuleState()); // TODO: Add your dispatch handler code here CString s; s.Format(_T("ShowMessage\n\"%s\""), msg); AfxMessageBox(s); } void CMyAppDlgAutoProxy::SetSettingValue(LPCTSTR settingName, LPCTSTR settingValue) { AFX_MANAGE_STATE(AfxGetAppModuleState()); // TODO: Add your dispatch handler code here CString s; s.Format(_T("SetSettingValue\nsettingName = \"%s\"\nsettingValue = \"%s\""), settingName, settingValue); AfxMessageBox(s); } void CMyAppDlgAutoProxy::GetSettingValue(LPCTSTR settingName, BSTR* settingValue) { AFX_MANAGE_STATE(AfxGetAppModuleState()); // TODO: Add your dispatch handler code here CString s; s.Format(_T("%s=testValue123"), settingName); *settingValue = s.AllocSysString(); } ===== The first two methods work great, I can call those from python without any problems. > > Nope - it should all be good. For example, check out: > > http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/TestSources/PyCOMTest/PyCOMTest.idl#l193 > > > http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/TestSources/PyCOMTest/PyCOMImpl.cpp#l133 > > > and (slightly cryptic) Python code which calls it: > > http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/win32com/test/testPyComTest.py#l225 > > > Which shows some "out" param tests (and while there is an inout bstr > test, there doesn't seem to be a specific test for an out bstr, so > it's still possible you have hit a pywin32 bug) Thanks for the links. I'll take a look at them as soon as I can. >> You indicated that the out params should be converted to a return >> value. Why does the MakePy generated method signature not indicate >> this? i.e. why does it show 2 arguments? > > The makepy signature really just reflects the params passed to the > interface itself - hence those params all have default values. > >> You said above that pywin32 *will* be passing a second param - a byref >> bstr. That suggests to me that there's some other method I need to call >> which internally calls the real method from pywin32. Where is the method >> I need to call then? I don't see any method generated there with only a >> single arg? > > InvokeTypes is what does all the magic - it takes the VT_* values and > builds real params in C++, and also builds the tuple (if necessary) > which is returned. The params mainly exist for when the interface is > *implemented* by Python rather than when called by Python - the same > generated classes are used in both directions. > Got it, so I shouldn't expect the actual calling convention to be bound to whats in the MakePy code. > Hope this clarifies... Yes, thanks for the continued help on this. I'd love to see this work from Python and then be able to provide that as another way to automate this app. From mhammond at skippinet.com.au Tue Dec 18 02:25:24 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 18 Dec 2012 12:25:24 +1100 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CFAEC4.50902@kinematics.com> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> <50CDD2AF.4090106@kinematics.com> <50CE5679.904@skippinet.com.au> <50CFAEC4.50902@kinematics.com> Message-ID: <50CFC604.1000905@skippinet.com.au> Dave sent me the source via email. The root problem is that the MFC project is not supporting the GetTypeInfo() and associated calls, and TBH I'm not sure how hard it would be to make it support that. The end result is that the makepy support for the object isn't being used as pywin32 can't associate the object with the typelib, and thus isn't specifying that additional second param. This is also the reason you can't automagically generate the typelib using, eg, win32com.client.gencache.EnsureDispatch() - you are forced to run makepy manually and specify the exact typelib. There is actually a deficiency in pywin32 here too - it *does* know that MyApp.Application has a generated class, but it never tries that route - instead it creates the object and tries to use the typeinfo stuff to make the association. I think a bug on sourceforge for this would be good. So after running makepy, a work-around is: >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") >>> x = klass() >>> x.GetSettingValue("foo") u'foo=testValue123' >>> If you can work out how to get the MFC app to respond to the GetTypeInfo() and associated calls, it would all "just work". ie: >>> x=win32com.client.Dispatch("MyApp.Application")._oleobj_ >>> x >>> x.GetTypeInfo() Traceback (most recent call last): File "", line 1, in pywintypes.com_error: (-2147352565, 'Invalid index.', None, None) >>> should work - eg, a similar example using a WMI object: >>> x = win32com.client.Dispatch("WbemScripting.SWbemLocator")._oleobj_ >>> x >>> x.GetTypeInfo() >>> So it kinda sucks :( Mark On 18/12/2012 10:46 AM, Dave Calkins wrote: > On 12/16/2012 6:17 PM, Mark Hammond wrote: >> >>> I'm the vendor of the object :) As I mentioned, I just created this >>> small test app which reproduces the issue having just those 3 simple >>> methods. However, I'm not able to talk to it via Python. >> >> Is the source to this available? >> > > Yes, its just a Visual C++ app-wizard generated project. In Visual C++ > 2010 I used new >> project, selected MFC application, chose a dialog app > with default settings but I checked the "Automation" checkbox so it > would set it up as an OLE Automation server. Once created, in the Class > view I right-clicked the IMyApp interface and chose Add >> Method. I > did this for each method shown earlier. When you add a method this way, > it adds it to the IDL and then adds implementation methods in the > DlgProxy class it creates as part of the project. Then you just fill in > the implementation methods that it created for you. > > Here is the IDL. > > ===== > [ uuid(E85C16AC-7936-4792-8E2A-40537D9FA02B) ] > dispinterface IMyApp > { > properties: > > methods: > [id(1)] void ShowMessage(BSTR msg); > [id(2)] void SetSettingValue(BSTR settingName, BSTR > settingValue); > [id(3)] void GetSettingValue(BSTR settingName, BSTR* > settingValue); > }; > ===== > > Here's the implementation methods it created for the above. For the > first two I'm just showing a message box with the passed in args. For > the third, with the out param, I'm sending back a dummy value to the > caller. > > ===== > void CMyAppDlgAutoProxy::ShowMessage(LPCTSTR msg) > { > AFX_MANAGE_STATE(AfxGetAppModuleState()); > > // TODO: Add your dispatch handler code here > CString s; > s.Format(_T("ShowMessage\n\"%s\""), msg); > AfxMessageBox(s); > } > > > void CMyAppDlgAutoProxy::SetSettingValue(LPCTSTR settingName, LPCTSTR > settingValue) > { > AFX_MANAGE_STATE(AfxGetAppModuleState()); > > // TODO: Add your dispatch handler code here > CString s; > s.Format(_T("SetSettingValue\nsettingName = \"%s\"\nsettingValue = > \"%s\""), settingName, settingValue); > AfxMessageBox(s); > } > > > void CMyAppDlgAutoProxy::GetSettingValue(LPCTSTR settingName, BSTR* > settingValue) > { > AFX_MANAGE_STATE(AfxGetAppModuleState()); > > // TODO: Add your dispatch handler code here > CString s; > s.Format(_T("%s=testValue123"), settingName); > *settingValue = s.AllocSysString(); > } > ===== > > The first two methods work great, I can call those from python without > any problems. > >> >> Nope - it should all be good. For example, check out: >> >> http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/TestSources/PyCOMTest/PyCOMTest.idl#l193 >> >> >> http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/TestSources/PyCOMTest/PyCOMImpl.cpp#l133 >> >> >> and (slightly cryptic) Python code which calls it: >> >> http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/8b73631eeee0/com/win32com/test/testPyComTest.py#l225 >> >> >> Which shows some "out" param tests (and while there is an inout bstr >> test, there doesn't seem to be a specific test for an out bstr, so >> it's still possible you have hit a pywin32 bug) > > Thanks for the links. I'll take a look at them as soon as I can. > >>> You indicated that the out params should be converted to a return >>> value. Why does the MakePy generated method signature not indicate >>> this? i.e. why does it show 2 arguments? >> >> The makepy signature really just reflects the params passed to the >> interface itself - hence those params all have default values. >> >>> You said above that pywin32 *will* be passing a second param - a byref >>> bstr. That suggests to me that there's some other method I need to call >>> which internally calls the real method from pywin32. Where is the method >>> I need to call then? I don't see any method generated there with only a >>> single arg? >> >> InvokeTypes is what does all the magic - it takes the VT_* values and >> builds real params in C++, and also builds the tuple (if necessary) >> which is returned. The params mainly exist for when the interface is >> *implemented* by Python rather than when called by Python - the same >> generated classes are used in both directions. >> > > Got it, so I shouldn't expect the actual calling convention to be bound > to whats in the MakePy code. > >> Hope this clarifies... > > Yes, thanks for the continued help on this. I'd love to see this work > from Python and then be able to provide that as another way to automate > this app. > From dave at kinematics.com Tue Dec 18 02:33:29 2012 From: dave at kinematics.com (Dave Calkins) Date: Mon, 17 Dec 2012 20:33:29 -0500 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CFC604.1000905@skippinet.com.au> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> <50CDD2AF.4090106@kinematics.com> <50CE5679.904@skippinet.com.au> <50CFAEC4.50902@kinematics.com> <50CFC604.1000905@skippinet.com.au> Message-ID: <50CFC7E9.9000104@kinematics.com> On 12/17/2012 8:25 PM, Mark Hammond wrote: > Dave sent me the source via email. > > The root problem is that the MFC project is not supporting the > GetTypeInfo() and associated calls, and TBH I'm not sure how hard it > would be to make it support that. The end result is that the makepy > support for the object isn't being used as pywin32 can't associate the > object with the typelib, and thus isn't specifying that additional > second param. This is also the reason you can't automagically > generate the typelib using, eg, > win32com.client.gencache.EnsureDispatch() - you are forced to run > makepy manually and specify the exact typelib. > > There is actually a deficiency in pywin32 here too - it *does* know > that MyApp.Application has a generated class, but it never tries that > route - instead it creates the object and tries to use the typeinfo > stuff to make the association. I think a bug on sourceforge for this > would be good. > > So after running makepy, a work-around is: > > >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") > >>> x = klass() > >>> x.GetSettingValue("foo") > u'foo=testValue123' > >>> > > If you can work out how to get the MFC app to respond to the > GetTypeInfo() and associated calls, it would all "just work". ie: > > >>> x=win32com.client.Dispatch("MyApp.Application")._oleobj_ > >>> x > > >>> x.GetTypeInfo() > Traceback (most recent call last): > File "", line 1, in > pywintypes.com_error: (-2147352565, 'Invalid index.', None, None) > >>> > > should work - eg, a similar example using a WMI object: > > >>> x = win32com.client.Dispatch("WbemScripting.SWbemLocator")._oleobj_ > >>> x > > >>> x.GetTypeInfo() > > >>> > > So it kinda sucks :( > > Mark > Thanks for all the help Mark! I'll look into what it would take to support the GetTypeInfo() call on the MFC side. It sounds like the work-around will do just fine even if I can't get the GetTypeInfo() thing going. Dave From skippy.hammond at gmail.com Tue Dec 18 02:29:37 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 18 Dec 2012 12:29:37 +1100 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch In-Reply-To: References: Message-ID: <50CFC701.3000109@gmail.com> On 18/12/2012 6:27 AM, Russell Warren wrote: > Update - it seems to be the pythoncom27.dll somehow. I tried deleting > the InprocServer32 key and my com server works now. Assuming you installed Python "for all users", the pythoncom27.dll being used should be the one in the system32 directory, and pythonxx.dll should be next to it. Maybe the VS2008 runtime libs aren't installed such that they are picked up from there. > > I see that I can dodge this issue by specifying _reg_clsctx_ = > pythoncom.CLSCTX_LOCAL_SERVER, but I'm concerned about what the problem > could be with pythoncom27.dll and whether that will bite me some other > way later. Any guesses on what the problem might be? > > Also - what is the purpose in defaulting to use both InprocServer32 and > LocalServer32? Based on my problem, the default windows choice appears > to be InprocServer32. When/why would it move on to the LocalServer32 > entry? It clearly does not do it on error. The point is so that code which explicitly specifies the local server version works. Cheers, Mark > > Russ > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From dave at kinematics.com Tue Dec 18 15:10:06 2012 From: dave at kinematics.com (Dave Calkins) Date: Tue, 18 Dec 2012 09:10:06 -0500 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50CFC604.1000905@skippinet.com.au> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> <50CDD2AF.4090106@kinematics.com> <50CE5679.904@skippinet.com.au> <50CFAEC4.50902@kinematics.com> <50CFC604.1000905@skippinet.com.au> Message-ID: <50D0793E.8000200@kinematics.com> On 12/17/2012 8:25 PM, Mark Hammond wrote: > So after running makepy, a work-around is: > > >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") > >>> x = klass() > >>> x.GetSettingValue("foo") > u'foo=testValue123' > >>> > I tried the work-around. I've run MakePy and then gave the above a try. The first 2 methods worked, but I'm still getting an error on the last method. I suspect I'm doing something wrong on my end, but am not sure what. ===== Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") >>> klass >>> x = klass() >>> x.ShowMessage("Hello, world") >>> x.SetSettingValue("color","blue") >>> x.GetSettingValue("color") Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\win32com\gen_py\3D28B651-27E2-4057-A0AF-1D761C2D10CCx0x1x0.py" , line 34, in GetSettingValue , settingValue) pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2) ===== From russ at perspexis.com Tue Dec 18 16:39:30 2012 From: russ at perspexis.com (Russell Warren) Date: Tue, 18 Dec 2012 10:39:30 -0500 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch In-Reply-To: <50CFE21A.90407@skippinet.com.au> References: <50CFC701.3000109@gmail.com> <50CFE21A.90407@skippinet.com.au> Message-ID: On Mon, Dec 17, 2012 at 10:25 PM, Mark Hammond wrote: > The VS2008 redistributables should probably be in the same directory (ie, > msvc*90*.dll in system32) or else they might not be loaded. If you use the > "depends" tool from MS/sysinternals, you will see both Python itself and > pythoncom depend on this. > I ran the depends tool [1] and sure enough, pythoncom27.dll has 3 missing dependencies: MSVCR90.DLL; IESHIMS.DLL; and WER.DLL Screencap with additional errors here: http://static.inky.ws/image/3530/Selection_249.png Strangely, you can see in the screencap that MSVCR90.DLL is picked up with no issues at all by python27.dll (version issues, maybe?!). Separate depends analysis of python27.dll does show the other 2 missing. Actually, assuming you are using a recent pywin32, pycomloader27.dll should > also exist in that dir and should actually be used internally to load the > COM object - this was done primarily as a work-around for exactly this > problem. Nope - no pycomloader27.dll. Possibly this has not made it into the latest ActiveState release? I'll try a full install from pip. The only other python dll was pywintypes27.dll. What matters is the complexity in how dependent DLLs are loaded - as the > DLL COM object is loaded by some other app, the rules as applied to that > app gets used for resolving DLL references. The COM object as a .exe is > its own app. Thanks - I think I get it. To paraphrase: You're saying that the dependency issues still exist in the internals of the localserver.py LocalServer32 implementation, but dependency loading is deferred and there are no pre-checks. ie: it may fall flat during runtime at some point when a dependency is truly needed. For the inproc version, the windows internals that are loading the pythoncom27.dll are pre-loading (or pre-checking) dependencies and crashing before it even gets started. Correct? Thanks very much for the tips. I'll try and chase down these weird DLL issues now. Russ [1] For anyone else landing here, 'depends' is available here (not sysinternals): www.dependencywalker.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Dec 18 18:38:10 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 18 Dec 2012 09:38:10 -0800 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch In-Reply-To: References: Message-ID: <50D0AA02.8010502@probo.com> Russell Warren wrote: > > Also - what is the purpose in defaulting to use both InprocServer32 > and LocalServer32? Based on my problem, the default windows choice > appears to be InprocServer32. When/why would it move on to the > LocalServer32 entry? It clearly does not do it on error. An application can request the type of server it wants (in-process or out-of-process). It's the third parameter to CoCreateInstance. Virtually every application in the world wants in-process, because you can communicate via function calls instead via cross-process remote procedure calls where you have to marshal the parameters across process boundaries. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Dec 18 18:46:29 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 18 Dec 2012 09:46:29 -0800 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch In-Reply-To: References: <50CFC701.3000109@gmail.com> <50CFE21A.90407@skippinet.com.au> Message-ID: <50D0ABF5.1010809@probo.com> Russell Warren wrote: > On Mon, Dec 17, 2012 at 10:25 PM, Mark Hammond > > wrote: > > The VS2008 redistributables should probably be in the same > directory (ie, msvc*90*.dll in system32) or else they might not be > loaded. If you use the "depends" tool from MS/sysinternals, you > will see both Python itself and pythoncom depend on this. > > > I ran the depends tool [1] and sure enough, pythoncom27.dll has 3 > missing dependencies: MSVCR90.DLL; IESHIMS.DLL; and WER.DLL IESHIMS.DLL and WER.DLL are "delayed dependencies" -- see the hourglass? That means they don't have to be present unless they are actually called, and the tools that need them won't call them if they aren't present. MSVCR90.DLL is a "side-by-side" DLL, which means that it is version-stamped. It is possible (although I don't know that this is the problem) that pythoncom27.dll links to a different version of it than python27.dll. You might try installing the Visual C++ 2008 SP1 runtime update to see if that helps: http://www.microsoft.com/en-us/download/details.aspx?id=5582 Fortunately for everyone involved, the Visual Studio team abandoned the side-by-side stuff in Visual Studio 2010. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Tue Dec 18 23:16:31 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 19 Dec 2012 09:16:31 +1100 Subject: [python-win32] Calling an OLE Automation (IDispatch) server which uses "out params" In-Reply-To: <50D0793E.8000200@kinematics.com> References: <50C92325.4060601@kinematics.com> <50CA9F56.4000604@gmail.com> <50CB2FF8.8070605@kinematics.com> <50CD6025.2060704@gmail.com> <50CDD2AF.4090106@kinematics.com> <50CE5679.904@skippinet.com.au> <50CFAEC4.50902@kinematics.com> <50CFC604.1000905@skippinet.com.au> <50D0793E.8000200@kinematics.com> Message-ID: <50D0EB3F.1030209@skippinet.com.au> That's very strange - is it possible you changed the source code since you sent it, or aren't using the latest pywin32? This is what I see: Python 2.7.3+ (default, May 12 2012, 13:50:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") >>> klass >>> x = klass() >>> x.ShowMessage("Hello, world") >>> x.SetSettingValue("color","blue") >>> x.GetSettingValue("color") u'color=testValue123' >>> Given the source code, that last line is expected (ie, every value will return 'testValue123'). I'm at a bit of a loss on the problem you are seeing. Mark On 19/12/2012 1:10 AM, Dave Calkins wrote: > On 12/17/2012 8:25 PM, Mark Hammond wrote: >> So after running makepy, a work-around is: >> >> >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") >> >>> x = klass() >> >>> x.GetSettingValue("foo") >> u'foo=testValue123' >> >>> >> > > I tried the work-around. I've run MakePy and then gave the above a > try. The first 2 methods worked, but I'm still getting an error on the > last method. I suspect I'm doing something wrong on my end, but am not > sure what. > > ===== > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import win32com.client > >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application") > >>> klass > at 0x02374D18> > >>> x = klass() > >>> x.ShowMessage("Hello, world") > >>> x.SetSettingValue("color","blue") > >>> x.GetSettingValue("color") > Traceback (most recent call last): > File "", line 1, in > File > "C:\Python27\lib\site-packages\win32com\gen_py\3D28B651-27E2-4057-A0AF-1D761C2D10CCx0x1x0.py" > > , line 34, in GetSettingValue > , settingValue) > pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2) > ===== > > From mhammond at skippinet.com.au Tue Dec 18 23:25:15 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 19 Dec 2012 09:25:15 +1100 Subject: [python-win32] COM server registering, but getting "The specified module could not be found" on dispatch In-Reply-To: References: <50CFC701.3000109@gmail.com> <50CFE21A.90407@skippinet.com.au> Message-ID: <50D0ED4B.20606@skippinet.com.au> On 19/12/2012 2:39 AM, Russell Warren wrote: > On Mon, Dec 17, 2012 at 10:25 PM, Mark Hammond > > wrote: > > The VS2008 redistributables should probably be in the same directory > (ie, msvc*90*.dll in system32) or else they might not be loaded. If > you use the "depends" tool from MS/sysinternals, you will see both > Python itself and pythoncom depend on this. > > > I ran the depends tool [1] and sure enough, pythoncom27.dll has 3 > missing dependencies: MSVCR90.DLL; IESHIMS.DLL; and WER.DLL > > Screencap with additional errors here: > http://static.inky.ws/image/3530/Selection_249.png > > Strangely, you can see in the screencap that MSVCR90.DLL is picked up > with no issues at all by python27.dll (version issues, maybe?!). > Separate depends analysis of python27.dll does show the other 2 missing. > > Actually, assuming you are using a recent pywin32, pycomloader27.dll > should also exist in that dir and should actually be used internally > to load the COM object - this was done primarily as a work-around > for exactly this problem. > > > Nope - no pycomloader27.dll. Possibly this has not made it into the > latest ActiveState release? I'll try a full install from pip. The only > other python dll was pywintypes27.dll. Maybe try a stand-alone pywin32 - as mentioned, pycomloader27.dll exists purely to work around this kind of problem. > What matters is the complexity in how dependent DLLs are loaded - as > the DLL COM object is loaded by some other app, the rules as applied > to that app gets used for resolving DLL references. The COM object > as a .exe is its own app. > > > Thanks - I think I get it. To paraphrase: You're saying that the > dependency issues still exist in the internals of the localserver.py > LocalServer32 implementation, but dependency loading is deferred and > there are no pre-checks. ie: it may fall flat during runtime at some > point when a dependency is truly needed. For the inproc version, the > windows internals that are loading the pythoncom27.dll are pre-loading > (or pre-checking) dependencies and crashing before it even gets started. > Correct? Sadly it is a little more complicated than that. Each .exe has its own "context" for resolving DLLs, and this context is inherited by other DLLs loaded in the process. The Python DLL (and the pycomloader DLL) jump through alot of hoops to arrange for their own context to be setup so we don't depend on the context of the loading .exe. When a inproc impl is used without pycomloader, the context of the embedding process is used (which is hard to predict). A localserver impl has its own context (as it is a .exe) so doesn't strike the same problem. Indeed, pycomloader exists purely to jump through those context hoops - all it does is setup the context appropriately then call the pythoncom DLL (and those hoops can't be put into pythoncomxx.dll or things would go pear-shaped when that DLL is loaded by python itself). Cheers, Mark > > Thanks very much for the tips. I'll try and chase down these weird DLL > issues now. > > Russ > > [1] For anyone else landing here, 'depends' is available here (not > sysinternals): www.dependencywalker.com > From Tom.Hawkins at innospecinc.com Wed Dec 19 09:36:45 2012 From: Tom.Hawkins at innospecinc.com (Tom Hawkins) Date: Wed, 19 Dec 2012 08:36:45 -0000 Subject: [python-win32] check if comserver is registered, no -> install it? Message-ID: <80EF6E679A466046BA07D071932847B377CF9A@UKEPX101.innospec.itnet.octel> Steffen Fr?mer said: >i get following error: > >Traceback (most recent call last): > File "C:\Temp\com_tests.py", line 21, in > x = ctypes.OleDLL(os.path.realpath(local_dll)) > File "C:\Python32_x86_64\lib\ctypes\__init__.py", line 353, in __init__ > self._handle = _dlopen(self._name, mode) >WindowsError: [Error 193] %1 ist keine zul?ssige Win32-Anwendung For the benefit of anyone without German the last line of that translates as '%1 is not a valid Win32 application'. Tom Hawkins Principal Scientist Innospec Inc Tel: +44 (0)151 356 6197 Fax: +44 (0)151 356 6112 From haraldarminmassa at gmail.com Wed Dec 19 10:08:37 2012 From: haraldarminmassa at gmail.com (Harald Armin Massa[legacy]) Date: Wed, 19 Dec 2012 10:08:37 +0100 Subject: [python-win32] check if comserver is registered, no -> install it? In-Reply-To: <20121217143041.14333dr0lu5esc5d@webmail.gns-systems.de> References: <50A255FE.8070108@gns-systems.de> <50A28BE8.1010003@probo.com> <20121217143041.14333dr0lu5esc5d@webmail.gns-systems.de> Message-ID: Hallo Steffen, > Hi i tried to do exactly this. But on executing the line > > > dll = ctypes.OleDLL('myComServer.dll') > > i get following error: > > Traceback (most recent call last): > File "C:\Temp\com_tests.py", line 21, in > x = ctypes.OleDLL(os.path.realpath(local_dll)) > File "C:\Python32_x86_64\lib\ctypes\__init__.py", line 353, in __init__ > self._handle = _dlopen(self._name, mode) > WindowsError: [Error 193] %1 ist keine zul?ssige Win32-Anwendung > a common cause for this error is another file with the same name in the system path. As in "python and windows try to load excel from microsoft, but there is some excel.dll from somebody who tries to excell in some area" Sysinternals diskmon is a nice tool to debug this stuff. Try to google for it, microsoft changes it's website structure faster then bing can follow. Harald -- LightningTalkMan a brand of GHUM GmbH Spielberger Stra?e 49 70435 Stuttgart 0173/9409607 From wangyonguci2012 at gmail.com Wed Dec 26 01:13:45 2012 From: wangyonguci2012 at gmail.com (wang yong) Date: Tue, 25 Dec 2012 16:13:45 -0800 Subject: [python-win32] Use python to read data from mouse but not move cursor In-Reply-To: References: Message-ID: Hi Tutors, I am new to Python. I am trying to use win32api to read out mouse movement from an additional mouse attached to my compputer. But, I do not want this mouse to move my cursor. So, do you guys have any suggestions or codes for this task! Really appreciate it! Thanks for the help. Best, Yong -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Dec 26 18:48:18 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 26 Dec 2012 09:48:18 -0800 Subject: [python-win32] Use python to read data from mouse but not move cursor In-Reply-To: References: Message-ID: <50DB3862.3010601@probo.com> wang yong wrote: > > I am new to Python. I am trying to use win32api to read out mouse > movement from an additional mouse attached to my compputer. But, I do > not want this mouse to move my cursor. So, do you guys have any > suggestions or codes for this task! Really appreciate it! Thanks for > the help. That's not possible. All HID devices (mice and keyboards) feed into the system's central input process. They will all affect the cursor. Think about it for a moment -- how would you tell the system which mouse device you wanted? Theoretically, you could replace the system's mouse driver with one of your own using something like libusb, but that's a heck of a lot of work. You'd have to understand how USB requests work, and how the USB Human Interface Device Class works. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From niki at vintech.bg Thu Dec 27 10:29:56 2012 From: niki at vintech.bg (niki) Date: Thu, 27 Dec 2012 11:29:56 +0200 Subject: [python-win32] Use python to read data from mouse but not move cursor In-Reply-To: <50DB3862.3010601@probo.com> References: <50DB3862.3010601@probo.com> Message-ID: <50DC1514.1060904@vintech.bg> On 26.12.2012 19:48, Tim Roberts wrote: > wang yong wrote: >> >> I am new to Python. I am trying to use win32api to read out mouse >> movement from an additional mouse attached to my compputer. But, I do >> not want this mouse to move my cursor. So, do you guys have any >> suggestions or codes for this task! Really appreciate it! Thanks for >> the help. > > That's not possible. All HID devices (mice and keyboards) feed into the > system's central input process. They will all affect the cursor. Think > about it for a moment -- how would you tell the system which mouse > device you wanted? IMHO this should be possible as e.g. "trine 2" game has configuration for using several (mouse + keyboard) Niki From timr at probo.com Thu Dec 27 18:36:29 2012 From: timr at probo.com (Tim Roberts) Date: Thu, 27 Dec 2012 09:36:29 -0800 Subject: [python-win32] Use python to read data from mouse but not move cursor In-Reply-To: <50DC1514.1060904@vintech.bg> References: <50DB3862.3010601@probo.com> <50DC1514.1060904@vintech.bg> Message-ID: <50DC871D.4050900@probo.com> niki wrote: > On 26.12.2012 19:48, Tim Roberts wrote: >> >> That's not possible. All HID devices (mice and keyboards) feed into the >> system's central input process. They will all affect the cursor. Think >> about it for a moment -- how would you tell the system which mouse >> device you wanted? > IMHO this should be possible as e.g. "trine 2" game has configuration > for using several (mouse + keyboard) They are installing custom drivers, as I suggested in my response. There is no way to do it from any standard API, including DirectInput. There used to be an open source driver called "CPNMouse" that could do this, but their SourceForge page no longer responds. You can give the "Windows MultiPoint Mouse SDK" a shot: http://www.microsoft.com/multipoint/mouse-sdk/ -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc.