Re: [python-win32] Context menu handler as executable

2016-08-04 Thread Thomas Heller

Am 26.07.2016 um 19:35 schrieb Gertjan Klein:

Tim Roberts wrote:

Gertjan Klein wrote:

I am working on a Windows Explorer context menu handler; Windows 10,
Python 3.4 (both 64 bit), pywin32 version 219 installed (no virtual
environment).

The handler is working fine when running it as a Python source file.
However, I would like to create an executable containing all the
dependencies, so it can be run on PCs that don't have Python installed.
I can't get this to work. I have tried using py2exe and pyinstaller,
with various setup.py and spec file examples, and nothing seems to work.


Are you testing this on a 64-bit system?  Remember that your 64-bit
process will only work on 64-bit systems.


Yes, Windows and Python are both 64 bit. Note that the handler works
fine as a python file, just not as an executable.


What actually happens when you try to run it?


I guess I should have been more specific there... ;-)  I have py2exe or
pyinstaller create an executable; this registers itself without any
error messages, and registry entries do appear in the registry. However,
no context menu item appears, and nothing I tried showed any evidence of
my code being run.


AFAIK, Shell extensions must be inproc servers, not local servers.  In 
other words, they must be DLLs not EXEs.


Thomas


___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] extension modules and msvc version

2015-02-20 Thread Thomas Heller

Am 20.02.2015 um 17:41 schrieb Zachary Turner:

Does anyone understand the technical reasons why an extension module
must be compiled with the same version of msvc as python itself? Are
there any workarounds? It's really quite an inconvenience.

If the reason is because python27.dll and the extension module free each
others' memory, then it seems like this could be solved by having each
supply the other with an alloc and free function pointer, and using the
correct allocator on each side.

Is the situation better in python 3 than it is in 2.7? And is anyone
aware of any ways to get around this restriction so that i can write an
extension module that will work with a binary release of python?


pep 384 solves this problem.


___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using pip to install pywin32

2015-02-20 Thread Thomas Heller

Am 20.02.2015 um 17:58 schrieb Preston Landers:

Actually that gist wouldn't help much since it uses pywin32, the thing
we're trying to install. (derp!) There may be another way though.


Sure, you could port the gist to ctypes instead of pywin32.

However, the problem is that pip doesn't run postinstall scripts
(or that the wheel format does not include them).  Something like that.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] python 3.4 and pywin32

2014-03-25 Thread Thomas Heller

Am 24.03.2014 21:25, schrieb Vernon D. Cole:

So why is _mine_ broken, too?


No idea.


 What exactly did you clean up?


I ran the bdist_wininst uninstaller, then ran 'pip uninstall pywin32'
and installed the bdist_wininst installer again then it worked.

Previously I probably had a mess of installed versions, from the
original bdist_wininst installer that I downloaded from sourceforge,
plus a wheel package that I built myself with
'wheel convert pywin32-218.win32-py3.4.exe' and then installed with pip.

It seems I cannot reproduce now the problem that I had then.
Note: all this is with 32-bit python, on win7 64-bit.




On Mon, Mar 24, 2014 at 10:38 AM, Thomas Heller thel...@ctypes.org
mailto:thel...@ctypes.org wrote:

Am 21.03.2014 21 tel:21.03.2014%2021:22, schrieb Thomas Heller:

[this has also been sent to the python-dev mailing list]

With python 3.4 and pywin32 version 218 it is only possible
to import win32com or win32api when pywintypes has been imported
before.


False alarm: after cleaning everything up and installing again this
works now. Sorry for the noise.


Thomas


_
python-win32 mailing list
python-win32@python.org mailto:python-win32@python.org
https://mail.python.org/__mailman/listinfo/python-win32
https://mail.python.org/mailman/listinfo/python-win32




___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] python 3.4 and pywin32

2014-03-24 Thread Thomas Heller

Am 21.03.2014 22:18, schrieb Vernon D. Cole:

Mark  Crew:
   We have a serious problem with the Python 3.4 64-bit release.  This
is not just a weird adodbapi bug.  The IDE will not run, either.


I have created http://bugs.python.org/issue21050 in the python bug tracker.

Thomas


--
Vernon
Inline image 1


On Fri, Mar 21, 2014 at 2:22 PM, Thomas Heller thel...@ctypes.org
mailto:thel...@ctypes.org wrote:

[this has also been sent to the python-dev mailing list]

With python 3.4 and pywin32 version 218 it is only possible
to import win32com or win32api when pywintypes has been imported before.

I have no idea if this is a bug in pywin32 or in Python 3.4.
Does anyone know more?

Thanks,
Thomas

_
python-win32 mailing list
python-win32@python.org mailto:python-win32@python.org
https://mail.python.org/__mailman/listinfo/python-win32
https://mail.python.org/mailman/listinfo/python-win32




___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32




___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] python 3.4 and pywin32

2014-03-24 Thread Thomas Heller

Am 21.03.2014 21:22, schrieb Thomas Heller:

[this has also been sent to the python-dev mailing list]

With python 3.4 and pywin32 version 218 it is only possible
to import win32com or win32api when pywintypes has been imported before.


False alarm: after cleaning everything up and installing again this
works now. Sorry for the noise.

Thomas


___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Programmatically turn off mouse auto-positioning

2014-02-04 Thread Thomas Heller

Am 04.02.2014 19:51, schrieb reckoner:

Hi,

In the control panel, under mouse settings, there is a checkbox to
automatically move the mouse to the default button in a dialog box.

Is there a way to programmatically turn this off/on using Python? I'm
referring to windows 7/8.

Thanks!


SystemParametersInfo with the SPI_SETSNAPTODEFBUTTON parameter.
No idea if pywin32 exposes this but there's always ctypes.

Thomas

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Access coclass interface?

2014-01-10 Thread Thomas Heller

Am 10.01.2014 15:26, schrieb Khoroshyy Petro:

Hi list,
I try to control a setup which consist of a  monochromator and a CCD camera.

[...]


Now if I try to access a monochromator coclass from another libray in
the same way I get com_error: (-2147221005.
instrument =  win32com.client.Dispatch(JYMONOLib.IJYMonoReqd)
or
instrument =  win32com.client.Dispatch(JYMONOLib.Monochromator)



You can use ctypes.WinError to look up the error code if it known
to windows:

 from ctypes import *
 raise WinError(-2147221005)
Traceback (most recent call last):
  File stdin, line 1, in module
WindowsError: [Error -2147221005] Ungültige Klassenzeichenfolge


In english this would read: 'Invalid class string'.

This means that the COM runtime does not know about the
JYMONOLib.IJYMonoReqd and JYMONOLib.Monochromator names.

Thomas

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Several, totally isolated Python interpreters in the same process

2011-12-19 Thread Thomas Heller

I made an experiment that I wanted to share because it is imo kind of cool:

I managed to embed a second Python interpreter in a Python process, with
help of WinSxS (WinSxS is a Microsoft technology that allows to isolate
plugins from other plugins, or from the calling process).

The second interpreter is totally isolated from the calling process.

The idea is to use this technology to decouple COM extensions 
implemented in Python from the caller and from other COM extensions.

But there may be other uses as well...

The code is here:

http://code.google.com/p/ctypes-stuff/source/browse/trunk/winsxs


Information I found useful about WinSxS and assemblies:

http://msdn.microsoft.com/en-us/library/dd408052%28v=VS.85%29.aspx

http://omnicognate.wordpress.com/2009/10/05/winsxs/


Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] setting title bar of cmd.exe

2011-07-31 Thread Thomas Heller

Am 30.07.2011 17:56, schrieb Ethan Furman:

Thomas Heller wrote:

windll.kernel32.SetConsoleTitleA(foobar)
-or-
windll.kernel32.SetConsoleTitleW(uspam)


Thanks again for the help. I used this to help answer a Stack Overflow
question: http://stackoverflow.com/questions/6485678/

Thomas, do you mind if I use your name for attribution? Right now it
just says the folks on python-win32 mailing list because I wasn't sure.

~Ethan~


Whatever you want.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] setting title bar of cmd.exe

2011-07-29 Thread Thomas Heller

Am 29.07.2011 19:15, schrieb Ethan Furman:

When running commands from cmd the title bar will update to relect the
currently running command. Is there a way to have python scripts run
from cmd.exe to update the cmd title bar?

~Ethan~


from ctypes import windll

windll.kernel32.SetConsoleTitleA(foobar)
-or-
windll.kernel32.SetConsoleTitleA(uspam)

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] setting title bar of cmd.exe

2011-07-29 Thread Thomas Heller

Am 29.07.2011 19:19, schrieb Thomas Heller:

Am 29.07.2011 19:15, schrieb Ethan Furman:

When running commands from cmd the title bar will update to relect the
currently running command. Is there a way to have python scripts run
from cmd.exe to update the cmd title bar?

~Ethan~


from ctypes import windll

windll.kernel32.SetConsoleTitleA(foobar)
-or-
windll.kernel32.SetConsoleTitleA(uspam)


Sorry, the last one should read (note the 'W' instead of 'A'):

windll.kernel32.SetConsoleTitleW(uspam)



Thomas



___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Threads, COM, gc

2011-05-26 Thread Thomas Heller

I have to fix a tricky problem that we recently discovered in our
software.

We have a multithreading Python program that uses a lot of COM objects.
COM objects have the requirement that they must only be used in
the COM apartment where they have been created.  Different threads often
or even most of the time run in different apartments.

This requirement is easy to fulfill (if the programmer is careful),
but there is one exception:

If the COM object is part of a reference cycle of some other Python
objects, then it is not destroyed when it goes out of scope, instead
it is destroyed when the Python cycle gc runs.

The garbage collector can run in any thread; so the cleanup of the
COM object may happen in some arbitrary thread.  This is not allowed,
and in some circumstances the program hangs or maybe it even crashes.

So, it must be ensured that the cleanup of the COM objects happen
in the same thread where they have been created.

Does anyone have some ideas how this could be approached?

Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the shell namespace in Python

2010-05-07 Thread Thomas Heller
Tim Golden schrieb:
 On 05/05/2010 20:33, Thomas Heller wrote:
 Does someone have example code snippets how to walk the shell namespace in 
 Python?
 I'm lost in all these pidls and folders.
 
 The code below uses the pywin32 functions to walk. Because there's all
 sorts of things which can happen, I've implemented a v. broad except:
 clause just to keep things going. Since this uses the pywin32 wrappers,
 it's hiding a certain amount of the PIDL/SHITEM stuff, but the functions
 are pretty much the underlying win32 ones.
 
 One thing I don't know how to do without using comtypes is to find the parent.
 the SHBindToParent function would be the way to go but it's not exposed and
 I don't have the energy to set up all the comtypes boilerplate to make it 
 happen:
 I'm sure you can manage, though :)
 
http://msdn.microsoft.com/en-us/library/bb762114%28VS.85%29.aspx

Thanks Tim, your script gave me a good start.

It seems that pywin32 wraps pidls as list of strings, so getting the parent
is as simple as removing the last part:

 from win32com.shell.shell import *
 from win32com.shell.shellcon import *
 desktop = SHGetDesktopFolder()
 desktop.ParseDisplayName(0, None, rc:\python26\lib\site-packages)
(0, ['\x1fP\xe0O\xd0 \xea:i\x10\xa2\xd8\x08\x00+00\x9d', 
'/C:\\\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00', 
'1\x00\x00\x00\x00\x00\x9c\xb82\x10\x00Python26\x00\x00(\x00\x03\x00\x04\x00\xef\xbe\x97:\x108\x9c\xb82\x14\x00\x00\
x00P\x00y\x00t\x00h\x00o\x00n\x002\x006\x00\x00\x00\x18\x00', 
'1\x00\x00\x00\x00\x00\x9d\x02D\x10\x00Lib\x00\x1e\x00\x03\x00\x04\
x00\xef\xbe\xfb:eQ\x9d\x02D\x14\x00\x00\x00L\x00i\x00b\x00\x00\x00\x12\x00', 
'1\x00\x00\x00\x00\x00\x9c\xafD\x10\x00SITE-P~1\x00
\x002\x00\x03\x00\x04\x00\xef\xbe\xfb:uQ\x9c\xafD\x14\x00\x00\x00s\x00i\x00t\x00e\x00-\x00p\x00a\x00c\x00k\x00a\x00g\x00e\x00s\x0
0\x00\x00\x18\x00'], 0)
 eaten, pidl, attr = desktop.ParseDisplayName(0, None, 
 rc:\python26\lib\site-packages)
 desktop.GetDisplayNameOf(pidl, SHGDN_FORPARSING)
u'C:\\Python26\\Lib\\site-packages'
 desktop.GetDisplayNameOf(pidl[:-1], SHGDN_FORPARSING)
u'C:\\Python26\\Lib'
 desktop.GetDisplayNameOf(pidl[:-2], SHGDN_FORPARSING)
u'C:\\Python26'
 desktop.GetDisplayNameOf(pidl[:-3], SHGDN_FORPARSING)
u'C:\\'
 desktop.GetDisplayNameOf(pidl[:-4], SHGDN_FORPARSING)
u'::{20D04FE0-3AEA-1069-A2D8-08002B30309D}'


What I find strange if this:

 desktop.GetDisplayNameOf(pidl, SHGDN_FORPARSING)
u'C:\\Python26\\Lib\\site-packages'
 desktop.GetDisplayNameOf(pidl, SHGDN_NORMAL)
u'Python26'


I would have expected that the last command would have returned
'site-packages' instead of 'Python26'.  But I can probably work around
it by doing a little parsing on the output of SHGDN_FORPARSING myself.

-- 
Thanks again,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the shell namespace in Python

2010-05-07 Thread Thomas Heller
Thomas Heller schrieb:
[...]
 
 What I find strange if this:
What I fond strange is this:
 
 desktop.GetDisplayNameOf(pidl, SHGDN_FORPARSING)
 u'C:\\Python26\\Lib\\site-packages'
 desktop.GetDisplayNameOf(pidl, SHGDN_NORMAL)
 u'Python26'

 
 I would have expected that the last command would have returned
 'site-packages' instead of 'Python26'.  But I can probably work around
 it by doing a little parsing on the output of SHGDN_FORPARSING myself.
 

Addendum:

SHGetFileInfo() is able to retrive the string that I expected:

 name = desktop.GetDisplayNameOf(pidl, SHGDN_FORPARSING)
 SHGetFileInfo(name, 0, SHGFI_DISPLAYNAME)
(1L, (0, 0, 0, 'site-packages', ''))


-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Walking the shell namespace in Python

2010-05-05 Thread Thomas Heller
Does someone have example code snippets how to walk the shell namespace in 
Python?
I'm lost in all these pidls and folders.

Basically I want to implement a combobox similar to the 'explorer bar' in 
Windows explorer;
given a certain directory - say 'c:\Python26\lib\site-packages' I want to find 
the names
(and laster also the icons) for the files and folders in it, and (more 
important) the anchestor
names and icons like this (using a german windows):

Desktop
 Eigene Dateien
 Arbeitsplatz
  WD320 (C:)
   Python26
Lib
 site-packages
  DVD-RAM Laufwerk (D:)
  ...
 Netzwerk
 Papierkorb
 ...
  
-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] finding pythonXX.dll?

2010-05-04 Thread Thomas Heller
Bill Janssen schrieb:
 Roger Upole rwup...@msn.com wrote:
 
 Bill Janssen wrote:
  Is there anyway to tell, from inside Python, where the python26.dll file
  is?  I've got to install the win32 dlls in the same directory.
 
  I see that sys contains a symbol dllhandle, but that's just a
  numeric handle.
 
  Bill
 
 win32api.GetModuleFileName(sys.dllhandle)
 
  Roger
 
 Sorry, I wasn't clear enough.  I'm trying to figure out where to install
 the win32 dlls, so I can't use them in that determination.

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 from ctypes import *
 buf = create_string_buffer(256)
 windll.kernel32.GetModuleFileNameA
_FuncPtr object at 0x00B44B70
 import sys
 windll.kernel32.GetModuleFileNameA(sys.dllhandle, byref(buf), 256)
32
 buf.value
'C:\\WINDOWS\\system32\\python26.dll'


-- 
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] pywintypes.com_error: -2147417846 Application busy

2009-11-25 Thread Thomas Heller
Alexander Eisenhuth schrieb:
 Hello list,
 
 I'm having a problem with a python COM Excel client that rarely gets the 
 exception pywintypes.com_error with the error code -2147417846. (means Excel 
 is 
 busy) Here the python code of the exception handling:
 
 [...]
 try:
   # write a excel cell
 [...]
 except pywintypes.com_error, ex:
   if ex[0] == -2147417846:
   time.sleep(1.0)
   # retry write?
 [...]
 
 My first approach was to retry the writing to the excel cell. But that ends 
 in a 
 hanging Excel application (probably a deadlock).
 
 After a little research I found this post:
 
 http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/70ef972b-51b6-4ece-a4af-d6b4e111eea5
 
 [...] If you don't register a MessageFilter yourself (by calling 
 CoRegisterMessageFilter), you will get default behavior which will be to fail 
 the call if it gets rejected.  .Net converts the failure HRESULT to an 
 exception.  To deal with the possibility of the server being busy when you 
 try 
 to call, you need to implement IMessageFilter::RetryRejectedCall in your 
 client 
 code and also register the message filter.  In most cases, you will just need 
 to 
 wait for a few seconds and then retry the call--generally that will be 
 sufficient time to enable Word to finish whatever it is doing so it can 
 handle 
 your call.  However, if the instance of Word that you are controlling could 
 possibly visible, you might want to add additional logic to display the 
 OLEUIBUSY dialog after some amount of time has passed to notify the user that 
 you are waiting on Word to do something and give them the opportunity to help 
 the process.  For example, as Misha mentions, Word will reject all incoming 
 calls if a modal dialog box is up.  Therefore, in that situation, you would 
 be 
 blocked indefinitely until the dialog is dismissed. [...]
 
 As this part of the COM API (IMessageFilter, CoRegisterMessageFilter) isn't 
 included in pywin32 I don't see a possibility to do that, or?

If it is really possible to do this on the client side, you can try
to implement the message filter and call CoRegisterMessageFilter
with comtypes.

 Did anybody else have to deal with that problem?

Yes, we had this in our company with MFC applications.  Fortunately, these
were our own and we 'fixed' them by implementing a message filter inside
the applications, on the server side.


-- 
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ANN: PyGUI Mailing List

2009-11-21 Thread Thomas Heller
Gregory Ewing schrieb:
 There is now a mailing list for discussion of PyGUI:
 
http://mail.python.org/mailman/listinfo/pygui

Is the list available on gmane?

-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Unable to build against debug Python

2009-11-19 Thread Thomas Heller
Arve Knudsen schrieb:
 On Thu, Nov 19, 2009 at 8:01 AM, Thomas Heller thel...@ctypes.org wrote:
 
 Arve Knudsen schrieb:
  Hi
 
  I'm trying to install Python-Win32 from source in a debug-build of Python
  2.6.4, by issuing this command: python_d .\setup.py install. It fails
  however, with this error: LINK : fatal error LNK1104: cannot open file
  'python26.lib'. Is this due to a bug in the Python-Win32 distribution?

 No.  You must create a debug build by giving the '-g' or '--debug'
 flag to the build step, like this:

 python_d setup.py build -g install

 
 Thanks. Now I get another type of error:
 
 mt.exe : general error c101008d: Failed to write the updated manifest to the
 resource of file build\lib.win32-2.6-pydebug\win32\odbc_d.pyd. The process
 cannot access the file because it is being used by another process.

I cannot help with this error since I don't build pywin32 myself
from source anymore.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Unable to build against debug Python

2009-11-18 Thread Thomas Heller
Arve Knudsen schrieb:
 Hi
 
 I'm trying to install Python-Win32 from source in a debug-build of Python
 2.6.4, by issuing this command: python_d .\setup.py install. It fails
 however, with this error: LINK : fatal error LNK1104: cannot open file
 'python26.lib'. Is this due to a bug in the Python-Win32 distribution?

No.  You must create a debug build by giving the '-g' or '--debug'
flag to the build step, like this:

python_d setup.py build -g install


Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] WinINet Http*Request?

2009-11-10 Thread Thomas Heller
Dolf Michielsen schrieb:
 Hi,
 
 I am using win32inet for retreiving web pages via InternetOpenUrl / 
 InternetReadFile. Now I would like to extend the functionality to also 
 POST data. However, it seems the WinINet functions HttpOpenRequest, 
 HttpAddRequestHeaders, HttpEndRequest and HttpSendRequest not available 
 in win32inet?
 
 Is there a way to send HTTP POST messages through the WinINet API using 
 pywin32?
 
 I would like to go through the WinINet API because it transparantly 
 handles the proxy settings if set correctly in IE; without bothering 
 with retreiving/setting the proxy handlers with e.g. urllib2

You could try to use the WinHTTP.WinHTTPRequest.5.1 COM object,
with pywin32 or comtypes.


Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Compiling Python code to DLLs: Any way to do this

2009-11-08 Thread Thomas Heller
Ti Crossman schrieb:
 Hello, all.  I have a need to create application extensions for ESRI
 ArcGIS geographic information system software.  ArcGIS is built from
 the ground up using COM technology.  Supposedly, one can program
 against the (absolutely enormous) ArcObjects object model with any
 COM-compliant language.  From what I understand, that includes Python
 -- with the pywin32 extensions, of course.  Now, the real trick here
 is that the extension must be compiled into a DLL (and must implement
 the IExension interface) for ArcGIS to recognize it as an extension.
 
 So, making the whopping assumption that I can pull off such a coding
 feat with Python (2.5.1 in this case), I have one main question:  is
 there a way to compile my Python code into a DLL that will work for
 me?

When you implement a COM object in Python then it IS a DLL.
If you use pywin32 then it is pythoncom.dll is it, if you
use comtypes then _ctypes.pyd is it.  These DLLs have the standard
COM entry points DllGetClassObject and DllCanUnloadNow.

 I did some reading up on py2exe and gather that it will compile
 Pyhton modules to DLLs; however, I also saw a reference to COM DLLs
 vs. C-type DLLs and whether or not they have random entry points.

py2exe can create 'standalone' DLLs from Python COM servers; it can NOT
create DLLs with custom entry points.

-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Passing Nothing into ReferencesEvents - resolved, however can't bind events [SEC=PERSONAL]

2009-10-19 Thread Thomas Heller
Zev Spitz schrieb:
 I am coming from VBA, and my understanding of COM internals is very weak.
 
 2 questions:
 1) What do I replace IWhatever with, and how do I find that out? (The 
 argument is supposed to be of type VBProject)
 2) How do I get an instance of IWhatever?
 

From your original post:
 # Code
 from win32com.client import Dispatch, DispatchWithEvents, getevents
 
 class RefEvents:
 def OnItemAdded(self,ref):
 print '--Event - Reference added'
 def OnItemRemoved(self,ref):
 print '--Event - Reference removed'
 
 acc=Dispatch('Access.Application')
 acc.Visible=True
 refsEvents=DispatchWithEvents(acc.VBE.Events.ReferencesEvents(None),RefEvents)

I don't have Access installed, but I assume Word is somewhat similar.
So, here we go:

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 from comtypes.client import CreateObject, ShowEvents
 acc = CreateObject(Word.Application)
# Generating comtypes.gen._00020905___C000_0046_0_8_3
# Generating comtypes.gen._00020430___C000_0046_0_2_0
# Generating comtypes.gen.stdole
# Generating comtypes.gen._2DF8D04C_5BFA_101B_BDE5_00AA0044DE52_0_2_3
# Generating comtypes.gen.Office
# Generating comtypes.gen._0002E157___C000_0046_0_5_3
# Generating comtypes.gen._2DF8D04C_5BFA_101B_BDE5_00AA0044DE52_0_2_4
# Generating comtypes.gen.VBIDE
# Generating comtypes.gen.Word
 acc.Visible = True
 acc.VBE.Events
Traceback (most recent call last):
  File stdin, line 1, in module
_ctypes.COMError: (-214680, None, (u'Dem programmatischen Zugriff auf das 
Visual Basic-Projekt wird nicht vertraut.'
, u'Microsoft Word', u'C:\\Programme\\Microsoft 
Office\\OFFICE11\\1031\\wdmain11.chm', 25548, None))


(The error message means somewhat like 'The programmatic access to the visual 
basic project is not trusted.
I use the 'Extras' menu in Word to change the macro security settings andtry 
again:)

 acc.VBE.Events
POINTER(Events) ptr=0x2929bc at 1224170


(Ah, some progress)

 acc.VBE.Events.ReferencesEvents(None)
Traceback (most recent call last):
  File stdin, line 1, in module
  File c:\sf\comtypes\comtypes\__init__.py, line 795, in __call__
return self.getter(self.im_inst, *args)
ctypes.ArgumentError: argument 1: type 'exceptions.TypeError': None


Ok, None is not accepted.  Grepping in the comtypes\gen directory for 
'ReferencesEvents'
I find this code snippet in file 
'_0002E157___C000_0046_0_5_3.py':

Events._methods_ = [
COMMETHOD([dispid(202), 'propget'], HRESULT, 'ReferencesEvents',
  ( ['in'], POINTER(VBProject), 'VBProject' ),
  ( ['retval', 'out'], POINTER(POINTER(ReferencesEvents)), 
'prceNew' )),
COMMETHOD([dispid(205), 'propget'], HRESULT, 'CommandBarEvents',
  ( ['in'], POINTER(IDispatch), 'CommandBarControl' ),
  ( ['retval', 'out'], POINTER(POINTER(CommandBarEvents)), 
'prceNew' )),
]

So, it seems we need a POINTER(VBProject).  VBProject is a CoClass, 
implementing the
_VBProject COM interface.

Further grepping shows the comtypes\gen\VBIDE.py is an alias module for
comtypes\gen\_0002E157___C000_0046_0_5_3.py, so we use the
former because it is much easier to type:

 from comtypes.gen import VBIDE
 from ctypes import POINTER

 acc.VBE.Events.ReferencesEvents(POINTER(VBIDE._VBProject)())
POINTER(_ReferencesEvents) ptr=0x274f2c at 11c7490


(The idiom 'POINTER(VBIDE._VBProject)()' creates a NULL-pointer to _VBProject)

And finally we try to find some events:

 ShowEvents(acc.VBE.Events.ReferencesEvents(POINTER(VBIDE._VBProject)()))
# event found: _dispReferencesEvents_ItemAdded
# event found: _dispReferencesEvents_ItemRemoved
comtypes.client._events._AdviseConnection object at 0x011BACB0


Now, I do not know what I have to do to trigger these events, but
it looks like the code could possibly work.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to use COM when there isn't a type library or IDL file

2009-10-09 Thread Thomas Heller
Mark Hammond schrieb:
 This is very tricky to do in pure-python.  Other interfaces with this 
 issue (eg, the shell interfaces) tend to use custom c++ code (often 
 generated by the 'makegw' package then heavily edited) to implement a 
 win32com 'sub-module'.  The best alternative for you may be to 
 investigate how comtypes might help...

comtypes: If neither a type library nor an idl file is available,
then you can still create the interface definition manually.
You can probably, given some experience, define the interface
by looking at the header file.  I started this for the first few
methods of the IRealTimeStylus interface:


# module realtimestylus.py
from ctypes import *
from ctypes.wintypes import *
from comtypes import IUnknown
from comtypes import GUID
from comtypes import COMMETHOD

class IRealTimeStylus(IUnknown):
_iid_ = GUID('{A8BB5D22-3144-4A7B-93CD-F34A16BE513A}')

IRealTimeStylus._methods_ = [
COMMETHOD(['propget'], HRESULT, 'Enabled',
  ( ['retval', 'out'], POINTER(c_int), 'pfEnable' )),
COMMETHOD(['propput'], HRESULT, 'Enabled',
  ( ['in'], c_int, 'pfEnable' )),

COMMETHOD(['propget'], HRESULT, 'HWND',
  ( ['retval', 'out'], POINTER(c_int), 'phwnd' )),
COMMETHOD(['propput'], HRESULT, 'HWND',
  ( ['in'], c_int, 'phwnd' )),

COMMETHOD(['propget'], HRESULT, 'WindowInputRectangle',
  ( ['retval', 'out'], POINTER(RECT), 'prcWndInputRect' )),
COMMETHOD(['propput'], HRESULT, 'WindowInputRectangle',
  ( ['in'], c_int, 'prcWndInputRect' )),

# here are quite some methods missing...
]


Then you can create such an object, QI for the interface, and try to use it.
I had to look up the CLSID for the RealTimeStylus class in the registry.

 p = CreateObject({E26B366D-F998-43CE-836F-CB6D904432B0})
 print p
POINTER(IUnknown) ptr=0x12e0848 at 1bfa3a0
 p.QueryInterface(IRealTimeStylus)
POINTER(IRealTimeStylus) ptr=0x12e0848 at 189e120
 s = p.QueryInterface(IRealTimeStylus)
 s.Enabled
0
 s.Enabled = 1
Traceback (most recent call last):
  File stdin, line 1, in module
  File comtypes\__init__.py, line 278, in __setattr__
value)
_ctypes.COMError: (-2144862203, 'The clear disable flag is set and all clear 
operations now require physical access.', (None, None, None, 0, None))



However, I would only recommend this approach to an experienced
COM developer.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Windows 7 taskbar api

2009-09-28 Thread Thomas Heller
Gerdus van Zyl schrieb:
 Thanks to this post
 http://www.neowin.net/forum/index.php?s=6352ade29ce66f2b51506c64e455d2f4showtopic=716968st=0p=590434472#entry590434472
 
 I got the idl that I could convert to a typelib and then use
 cc.GetModule(taskbar.tlb);
 
 The only trouble is you have to specify the
 import comtypes.gen.TaskbarLib as tbl
 taskbar 
 =cc.CreateObject({56FDF344-FD6D-11d0-958A-006097C9A090},interface=tbl.ITaskbarList3)
 
 instead of just:
 taskbar = tbl.TaskbarList()

 because the typelib from the IDL is missing, I am assuming it comes
 with the Win7 SDK. This is a problem since I would have to ship the
 generated interface if I decide to use this code.

It should not be a problem if you ship the generated file, as long
as the ITaskbarList* interfaces do not change (they should never change).

You would probably rename the 
comtypes.gen._683BF642_E9CA_4124_BE43_67065B2FA653_0_1_0
to something more sensible, and move out of the comtypes\gen directory
so that it doesn't get replaced or deleted by accident.

Creating an instance would be easier if you use code like
this which uses the _reg_clsid_ attribute from the generated CoClass:

from somewhere import ITaskbarList3, TaskbarList
taskbar = CreateObject(TaskbarList._reg_clsid_, interface=ITaskbarList3)

-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Shell extension debugging

2009-06-30 Thread Thomas Heller
Gertjan Klein schrieb:
 2) I see print statements in the source code, but I have no idea where
 they go; I checked the event log, but they are not there. Are they
 logged anywhere? If not, why are they there to begin with?

 Any other tip on how to effectively debug this stuff would be most
 welcome as well.

The print statements go into empty space because there is no stdout for
that process.  You can try using the logging module to log to a file, or
you can use ctypes to write to kernel32.OutputDebugString and using a
kernel debug log monitor to read them.
 
 The logging module reminds me of Java too much. :(  I think I'll try to
 write to a file, I have no idea if I have a kernel debug log monitor.

For stuff like this you should look around at the sysinternals site.  They have
a DebugView utility that displays these log strings.  ProcessExplorer is also
a very nice and useful replacement or addition for the task manager.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] dde trouble

2009-06-19 Thread Thomas Heller
Patrick Janssen schrieb:
 Hi all,
 I am having some trouble with controlling a Windows application through dde
[...]
 Does anyone know how I might be able to see the dde command strings that Lua
 is sending to Ecotect (which all seem to work - I am thinking that there may
 be an error in the documentation).

The old DDESpy tool comes to mind.

-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] AutoCAD automation with COM.

2009-04-28 Thread Thomas Heller
Costin Gamenţ schrieb:
 Hi, everybody!
 
 I'm trying to automate some tasks in AutoCAD (version 16.2 -- 2006) with  
 Python and COM. Apparently there is a long standind bug with either  
 win32com or AutoCAD:  
 http://mail.python.org/pipermail/python-win32/2005-December/004075.html  
 and I am having the same problem. Does anybody know a solution for this  
 problem?
 
 I must specify that this is my first time doing anything COM-related (and,  
 in fact, coding in windows).

You could try comtypes, it allows to specify the exact parameters that
are passed as VARIANTs.  There is even a sample snippet for autocad
in the docs:

http://starship.python.net/crew/theller/comtypes/

 
 Thanks,
 Costin

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] OnCtlColor not working?

2009-03-03 Thread Thomas Heller
Greg Ewing schrieb:
 Vernon Cole wrote:
 
 So, Greg, can we anticipate a python_gui flavor for Windows in native mode?
 
 Yes, it looks like there's a reasonable chance of that
 happening fairly soon.
 
 There are actually two possible ways it could go. I
 have a partial implementation contributed by one of
 my users based on ctypes, but it has some issues,
 and programming at the raw win32api level is a bit
 much for me to cope with just yet.

While I have promised writing one based on ctypes myself I never
got around for that.  But I would be interested in helping out
to fix the remaining issues.  Is the ctypes implementation
available somewhere?

-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Error with VixCom operation; TypeError: The VARIANT type is unknown (0x00000015)

2009-02-19 Thread Thomas Heller
Tim Roberts schrieb:
 Vinay Anantharaman wrote:
 Hi,

 I am trying to translate an error into text by using a library function in 
 vix com:

 http://www.vmware.com/products/beta/vmware_server/vix_api/ReferenceGuide/lang/com/functions/GetErrorText.html

 My code is as follows:
  vixLib = win32com.client.gencache.EnsureDispatch('VixCom.VixLib') 
  vixLib.GetErrorText(4, None)
  
 Instead of getting some explanation that a file was not found I get an 
 exception:
  File 
 C:\Users\vinaya\AppData\Local\Temp\gen_py\2.4\7A474EE3-0062-4239-AE91-134AC9BD5FD3x0x1x0.py,
  line 1316, in GetErrorText
 , locale)
 TypeError: The VARIANT type is unknown (0x0015)
   
 
 It's ironic that you posted this the same day as the other recent COM
 question, because it is exactly the same problem.  VARIANT type 0x15 is
 VT_UI8 -- a 64-bit integer.  It's kind of loony for an API to use a
 64-bit integer as an error number, but that's what they're doing.
 
 As Mark said, pywin32 doesn't support VT_UI8 at all.  There may be a
 hacky way to do this with comtypes.

I don't see anything hacky here; but ymmv:

c:\sf\comtypespy25
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 from comtypes.client import CreateObject
 d = CreateObject(VixCom.VixLib)
# Generating comtypes.gen._7A474EE3_0062_4239_AE91_134AC9BD5FD3_0_1_0
# Generating comtypes.gen._00020430___C000_0046_0_2_0
# Generating comtypes.gen.stdole
# Generating comtypes.gen.VixCOM
 from comtypes.gen import VixCOM
 d.GetErrorText(4, None)
Traceback (most recent call last):
  File stdin, line 1, in module
_ctypes.COMError: (-2147417851, 'Ausnahmefehler des Servers.', (None, None, 
None, 0, None))
 d.Connect(1, VixCOM.VIX_SERVICEPROVIDER_VMWARE_SERVER, , 0, , , 0, 
 None, None)
POINTER(IJob) ptr=0x292da4 at aebb70
 d.GetErrorText(4, None)
u'A file was not found'


The first d.GetErrorText call fails because not all libraries are loaded when
Connect has not yet been executed; according to this thread:
http://communities.vmware.com/message/650022


-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Looking for python-win32 version of EasyGUI

2009-02-07 Thread Thomas Heller
Robin Becker schrieb:
 Chaim Krause wrote:
 I have an very small application that uses a single multichoicebox from 
 EasyGUI. Because of the limitations of tkinter, I cannot get a single 
 exe file using py2exe.
 
 I was wondering if anybody had created something similar to EasyGUI, but 
 using python-win32. The idea being that I could replace the 
 multichoicebox from EasyGUI with one that uses the win32 API instead so 
 that I could get a single exe from py2exe.
 
 Can anybody point me in the right direction where I might find such a 
 thing?
 
 Thank you,
 Chaim
 ..
 some info here might be of use
 
 http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/#Win32

Or this one, by Jimmy Retzlaff?

http://www.averdevelopment.com/python/EasyDialogs.html

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] comtypes 0.5.3 released

2008-12-12 Thread Thomas Heller
I just released comtypes-0.5.3.

comtypes is a lightweight Python COM package, based on the ctypes
FFI library, in less than 1 lines of code (not counting the
tests).

comtypes allows to define, call, and implement custom and
dispatch-based COM interfaces in pure Python.  It works on Windows,
64-bit Windows, and Windows CE.

Download location:
http://sourceforge.net/project/showfiles.php?group_id=115265

Homepage:
http://starship.python.net/crew/theller/comtypes/


This is a maintainance release of the current repository state, before
I merged the dynamic-dispatch branch (which will be released as
comtypes-0.6.0 within the next few days).

Summary of important changes:

- Compatible with Python 3.0
- Added comtypes.shelllink module; this allows to manage shortcuts
- Various smaller improvements

Detailed changes since version 0.5.2:

2008-12-12  Thomas Heller  thel...@python.net

* Bumped version number to 0.5.3.

* Added VARIANT support for VT_I8 and VT_UI8 typecodes.

2008-12-11  Thomas Heller  thel...@python.net

* Workaround for Python bug: Python 3 cannot handle a distutils
installscript in the setup script

* Merged the py3-branch:

Various changes for py3 compatibility.  The setup script now uses
distutils.command.build_py.build_py_2to3 when run with Python 3.x,
and converts the sources into py3 syntax on the fly (in the build
directory).

2008-11-26  Thomas Heller  thel...@python.net

* Added untested code to comtypes.server: RegisterActiveObject()
and RevokeActiveObject(), plus some flags.

* Applied a patch from Torbjørn Tyridal.  This allows to
high-level implement methods in COM servers, and event handler
methods that have [in] and [out] arguments in mixed order.

2008-11-05  Thomas Heller  thel...@python.net

* Add the IPersistFile interface to the comtypes.persist module.
Add comtypes.shelllink module which contains IShellLinkA and
IShellLinkW interfaces, plus the ShellLink coclass.

2008-10-29  Thomas Heller  thel...@python.net

* Handle coclass pointers as arguments in com interface methods
correctly.  Method calls will now accept pointers to the default
interface of this coclass.

* The Fire_Event() method in comtypes.server.connectionpoints now
returns a list of results.

2008-10-10  Thomas Heller  thel...@python.net

* Import cStringIO, which should always be available on Windows,
instead of first trying cStringIO and then StringIO.

* Python 2.6 compatibility: use 'types.MethodType' instead of
'new.instancemethod' to fix a -3 warning.

Use 'raise Exception(details)' instead of
'raise Exception, details'.

Don't use tuple unpacking in exception handlers:
  'except COMError, err:
  (hresult, text, details) = err'
instead of
  'except COMError, (hresult, text, details)'

* Python 2.4 compatibility: os.stat() raises OSError instead of
WindowsError when a file is not found.


-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Passing data in a windows message

2008-12-10 Thread Thomas Heller
Tim Golden schrieb:
 I'm using win32gui.PyGetBufferAddressAndLen to pass the address  length 
 of a marshalled object as the wparam / lparam of a windows message. 
 Something like this:
 
 address, length = \
   win32gui.PyGetBufferAddressAndLen (buffer (marshal.dumps (message)))

I guess that the argument to PyGetBufferAddressAndLen() go out of scope
here, so they may already be invalid BEFORE you call PostMessage.

 PostMessage (self.hwnd, self.WM_PROGRESS_MESSAGE, length, address)
 
 where message here is actually a unicode object. At the other end, I'm 
 unpacking the message with PyGetString:
 
 message = marshal.loads (win32gui.PyGetString (lparam, wparam))
 

Since you used PostMessage, the message is simply posted to the thread's
message queue. You have no control when it is processed; so I fear you
must keep the posted 'object' alive even longer.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Does Python need a native Windows GUI toolkit?

2008-12-03 Thread Thomas Heller
Thomas Heller schrieb:
 Does Python need a native, pure Python, Windows GUI toolkit, one that uses
 win32 api calls directly to use native windows controls?

Ok, the answer to this question, for the 'community', is a clear No!

Understood,

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Does Python need a native Windows GUI toolkit?

2008-11-28 Thread Thomas Heller
Does Python need a native, pure Python, Windows GUI toolkit, one that uses
win32 api calls directly to use native windows controls?

Or would that development be a waste of resources, in these days of
of Python.NET, Windows forms, IronPython, (and last, not least, wxPython
and all these other toolkits)?  Or are desktop applications too rare now?


Several years ago I started using wxPython (it is probably a lot more
mature now) to write some simple programs and was not really pleased.
It looked too much like MFC to me.  I know that there are now several
wrappers over wxPython (althogh I have not used them) like Pythoncard
or newer ones like dabo (from what I hear). There have also been other
attempts to make nicer interfaces for wxPython which have vanished nowadays.
Somehow I have the impression that the approach to put layer over layer over 
layer
is wrong (wxWindows C++ layer, wxPython SWIG layer, Pythoncard/Dabo/whatever
python layer).

So, I started writing my own framework, also several years ago.  I used
ctypes (early versions) to call the win32 api directly, and it was fun
and it worked out great.
I have my own form editor, I can also construct windows, dialogs,
menus, and so on with simple high level code. But also it is possible
even at the 'highest level' to directly reach out to the win32 api, or
to handle WM_xxx messages directly if the need arises.

However, this framework is showing its age because during all this time
I developed some new approaches to make the work easier (for example first
I wrote the win32 plumbing code manually, now I have tools that automatically
generate the code to access constants, define structure definitions, or generate
function prototypes from the windows header files.  Also the framework too much
relies on manual conversions between byte and unicode strings.

So, the question is:  Are there people that share these ideas?
Are they willing to join a coordinated effort to develop a framework
like this, using the current and future Python versions, and all the fancy
new features of Python?

No promises, but I'm curious for the thoughts on this.

-- 
Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Does Python need a native Windows GUI toolkit?

2008-11-28 Thread Thomas Heller
Stef Mientki schrieb:
 Don't most people nowadays wants, and maybe even needs, OS-independant 
 applications ?

Sure.  But I assume that still quite a lot of people do NOT care
about x-platform compatibility for their applications.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com and DispatchWithEvents()

2008-11-15 Thread Thomas Heller
Ryan Neve schrieb:
  I posted this on comp.lang.python. but it has been pointed out to me that
 this is a better place to ask.
 
 I'm trying to get DispatchWithEvents() to work with HyperAccess (terminal
 program) without much success.

My apologies for (again) advertising comtypes on this list - if this is
inappropriate please tell me and I'll stop.

So, I suggest you try out comtypes:
http://starship.python.net/crew/theller/comtypes/

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ByRef params not working with PythonCOM

2008-10-22 Thread Thomas Heller
Greg Antal schrieb:
 Hi everybody.
 
 It's been nearly 2 weeks since I posted this, and nobody has responded.  If 
 anybody has any ideas, I'd be glad to hear them.  I'll provide more info on 
 anything anybody thinks is relevant.

Well, a totally different idea would be to try out comtypes with your objects.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ctypes and DLL

2008-07-24 Thread Thomas Heller
Marcus.CM schrieb:
 Hi
 
 On Windows/Vista :-
 
   vr = ctypes.CDLL(str)   
 
 When loading a DLL that is corrupted using cytpes,  i get a bombed out 
 box with python.exe - bad image as the message box title instead of 
 handling it at my exception handler.
 How do i do this without the ugly messagebox from python ?
 
 Marcus.CM.

You could try changing the process error-mode flags by calling the
Windows SetErrorMode() function before loading the dll.

Probably ctypes.windll.kernel32.SetErrorMode(0x8007) will help.
See http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx
-- 
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] FireEvent : comtypes work but win32com fails, why?

2008-06-25 Thread Thomas Heller
Mark Hammond schrieb:
  In summary, there are one big problem and one minor problem. The
  first
  is about pywin32's inability to pass FireEvent's second argument.
 
 I can't explain that :(  I've stepped through the code, and it seems we are
 passing a VT_VARIANT containing a VT_BYREF|VT_DISPATCH.  I'm afraid I'm not
 familiar enough with comtypes to know how it is passing that param.

I think that comtypes passes a VT_DISPATCH type in the DISPPARAMS VARIANTARG 
field.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Docs bonus: pywin32 docs

2008-05-28 Thread Thomas Heller
Tim Golden schrieb:
 Simon Dahlbacka wrote:
 Very nice, however you might want to fix the code samples to be properly 
 indented instead of collapsed whitespace..
 
 Can you point me towards an example?

Here's an example:

http://timgolden.me.uk/pywin32-docs/html/win32/help/process_info.html

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] os.startfile mysteriously failing

2008-04-21 Thread Thomas Heller
Tim Golden schrieb:
 King Simon-NFHD78 wrote:
 Hello all,
 
 I am developing an application that, amongst other things, exports files
 and then launches them in their associated applications using
 os.startfile. It also uses webbrowser.open, which I see uses
 os.startfile.
 
 Everything works on my PC and on all the other PCs in the office that I
 have tested on. However, when we released our first version, a few users
 reported unhandled exceptions that seem to be coming from os.startfile.
 Here are some examples:
 
 [... snipped ...]
 
 Unless someone comes in with something more authoritative, here
 are a few avenues to try:
 
 1) According to this:
 
   
 http://groups.google.co.uk/group/microsoft.public.platformsdk.shell/msg/943b9844d480b029
 
 ShellExecute on a URL invokes a shell extension handler which will operate
 in apartment threading mode. (ie you're using COM whether you like it or
 not). Exactly how this affects your situation I'm sure I couldn't say, 
 especially
 since you seem to have tried that route and you're not specifying  a COM
 threading model.

Some remarks that may or may not be useful:

AFAIK, a single threaded COM apartment needs to run a message loop,
according to the COM rules.  If the OP has a gui-application, and
calls os.startfile from the main thread, then this should be no problem.

If he has a console application, there normally is no message loop.

Looking into the MSDN docs for ShellExecuteEx [1], *this* function allows
to set additional flags in the SHELLEXECUTEINFO structure that you pass to it.
It seems that SEE_MASK_FLAG_DDEWAIT may be something worth to try out [2]:


The SEE_MASK_FLAG_DDEWAIT flag must be specified if the thread calling 
ShellExecuteEx
does not have a message loop or if the thread or process will terminate soon 
after
ShellExecuteEx returns. Under such conditions, the calling thread will not be 
available
to complete the DDE conversation, so it is important that ShellExecuteEx 
complete the
conversation before returning control to the calling application. Failure to 
complete
the conversation can result in an unsuccessful launch of the document.


[1] http://msdn2.microsoft.com/en-us/library/bb762154.aspx
[2] http://msdn2.microsoft.com/en-us/library/bb759784(VS.85).aspx

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Convert PyIDispatch object to struct IDispatch*

2008-04-11 Thread Thomas Heller
Huayang Xia schrieb:
 I am trying to use ctypes to call dll functions. One of the functions
 requires argument struct IDispatch* . I do have a PyIDispatch object
 in python. How can I convert this PyIDispatch object to struct
 IDispatch* ?
 Thanks in advance.

The only way (that I know of) to retrieve the 'IDispatch*' pointer
from the PyIDispatch object is to print it:

 from win32com.client import Dispatch
 ie = Dispatch(InternetExplorer.Application)
 print ie
Windows Internet Explorer
 repr(ie)
'COMObject InternetExplorer.Application'
 print ie._oleobj_
PyIDispatch at 0xb17fb4 with obj at 0x27005c


The last number is the pointer in question, you can parse it from the repr
and pass it to the ctypes function call.

For fun, attached is a script that creates a comtypes IDispatch pointer
from the PyIDispatch object.

Thomas

snip
# Shows how to convert an pywin32 PyIDispatch object
# into a comtypes COM pointer.

from win32com.client import Dispatch

d = Dispatch(InternetExplorer.Application)

x = d._oleobj_

print repr(x)

# repr(x) is like this:
# PyIDispatch at 0xb12fac with obj at 0x2700b4
#
# The last number is the address of the IDispatch pointer:
addr = int(repr(x).split()[-1][2:-1], 16)

print hex(addr)

from ctypes import *
from comtypes.automation import IDispatch
from _ctypes import CopyComPointer

# create a NULL comtypes pointer
p = POINTER(IDispatch)()

# put the IDispatch pointer into the comtypes IDispatch
# pointer:
cast(byref(p), POINTER(c_void_p))[0] = addr

# Call AddRef(), since the comtypes pointer will call Release() when
# it goes away:
p.AddRef()

print p

snip/

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] OT: Version in EXE ...

2008-04-03 Thread Thomas Heller
Clinton Lee Taylor schrieb:
 Greetings ...
 
  This might be a little off topic, but I'm hoping that some might know
 how to add version details to exe files created with py2exe so that
 install system can version control upgrades ...
 
 Thanks
 Mailed
 LeeT

IIRC, py2exe itself has samples that have this.  Look into
the subdirectories of pythonXY\Lib\site-packages\py2exe\samples.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] possible to save the output of TTS to a WAV file?

2008-03-07 Thread Thomas Heller
Alec Bennett schrieb:
 I'm trying to save the output of some TTS to a sound file, is this possible?
 
 Here's how I'm doing the TTS, though am certainly open to other methods:
 
 import pythoncom, win32com
 import win32api, win32com.client
 pythoncom.CoInitialize ()
 
 s = win32com.client.Dispatch(SAPI.SpVoice)
 s.Speak(hi there)
 
 Thanks for any help.

In comtypes, this code does 'speak to a file':

engine = CreateObject(SAPI.SpVoice)
stream = CreateObject(SAPI.SpFileStream)
from comtypes.gen import SpeechLib

stream.Open(fname, SpeechLib.SSFMCreateForWrite)

engine.AudioOutputStream = stream
engine.speak(Hello, World, 0)
stream.Close()

Should be trivial to convert it to pywin32.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Help calling IProgressDialog Interface

2008-02-27 Thread Thomas Heller
Larry Bates schrieb:
 One last problem.  When I working class inside my COM object and everything 
 works until I (or Python) destroys the reference to this object.  I then get 
 this exception:
 
 Exception exceptions.ValueError: 'COM method call without VTable' in bound 
 meth
 od POINTER(IProgressDialog).__del__ of POINTER(IProgressDialog) ptr=0x2670c8 
 at
   1ef5e90 ignored
 
Can you post (or send by mail) your code?

Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Help calling IProgressDialog Interface

2008-02-26 Thread Thomas Heller
Larry Bates schrieb:
 Thomas Heller wrote:
 Larry Bates schrieb:
 I've spent all morning searching and I just can't seem to find the 
 TypeLibrary 
 name for this COM interface.

 Sometimes someone who wants to use the object from VB writes an idl file
 and compiles a typelib (but you could also try it yourself, maybe).
 With a little googling I found a zip-file containing such a library:
 
 http://www.msjogren.net/dotnet/eng/samples/vb6_progdlg.asp

 Ok, I downloaded that project, and stripped out the TLB.  I then got comtypes 
 and was able to use comtypes.client.GetModule to generate the typelib wrapper 
 module for it:
 
   GetModule(progdlg.tlb)
 module 'comtypes.gen.VBProgressDialog' from 
 'C:\Python25\lib\site-packages\comtypes\gen\_2F2719A2_83CC_11D3_A08C_0040F6A4BFEC_0_1_1.pyc'
   import comtypes.gen.VBProgressDialog
 
 Now I can't seem to figure out what to do.  There are three classes generated:
 
 class IOleWindow(comtypes.IUnknown)
 class IProgressDialog(comtypes.IUnknown)
 class ProgressDialog(comtypes.CoClass)
 
 Instantiating IProgressDialog() seems to give me an instance that has the 
 methods that I'm looking for (at least they show up in Idle as callable 
 methods), but when I try to call one I get the following message:

Larry, you do not instantiate the generated classes directly.  You must use
the comtypes.client.CreateObject function to do that for you, passing the 
CoClass
as parameter.  I think that this code should work:

import comtypes.gen.VBProgressDialog
from comtypes.client import CreateObject
dia = CreateObject(comtypes.gen.VBProgressDialog.ProgressDialog)
dia.StartProgressDialog()

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Help calling IProgressDialog Interface

2008-02-22 Thread Thomas Heller
Larry Bates schrieb:
 I've spent all morning searching and I just can't seem to find the 
 TypeLibrary 
 name for this COM interface.  I've searched the registry, scanned COM browser 
 list at least a dozen times, etc.  Some information about this COM object is 
 located here:
 
 http://www.com.it-berater.org/COM/windows_shell/interfaces/IProgressDialog%20.htm
 
 It appears to be located in browseui.dll, but that didn't help either.
 
 I also tried using pythoncom.CoCreateInstance, but it reports:
 
   
 pdlg=pythoncom.CoCreateInstance('{F8383852-FCD3-11d1-A6B9-006097DF5BD4}', No
 ne, 1, '{EBBC7C04-315E-11d2-B62F-006097DF5BD4}')
 Traceback (most recent call last):
File stdin, line 1, in module
 TypeError: There is no interface object registered that supports this IID
 
 I'm hoping that someone out there can assist?

Quite some com objects do not have a type library; probably those that are only
supposed (by MS) to be used by C++ code.

Sometimes an .idl file can be found somewhere in the SDKs which you can
compile into a .tlb file, sometimes not.

Sometimes someone who wants to use the object from VB writes an idl file
and compiles a typelib (but you could also try it yourself, maybe).
With a little googling I found a zip-file containing such a library:

http://www.msjogren.net/dotnet/eng/samples/vb6_progdlg.asp

However, this typelib would not help if you are using pywin32; comtypes
would probably be able to use it - I haven't tried it myself.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Help calling IProgressDialog Interface

2008-02-22 Thread Thomas Heller
 Ok, I downloaded that project, and stripped out the TLB.  I then got comtypes 
 and was able to use comtypes.client.GetModule to generate the typelib wrapper 
 module for it:
 
   GetModule(progdlg.tlb)
 module 'comtypes.gen.VBProgressDialog' from 
 'C:\Python25\lib\site-packages\comtypes\gen\_2F2719A2_83CC_11D3_A08C_0040F6A4BFEC_0_1_1.pyc'
   import comtypes.gen.VBProgressDialog
 
 Now I can't seem to figure out what to do.  There are three classes generated:
 
 class IOleWindow(comtypes.IUnknown)
 class IProgressDialog(comtypes.IUnknown)
 class ProgressDialog(comtypes.CoClass)
 
 Instantiating IProgressDialog() seems to give me an instance that has the 
 methods that I'm looking for (at least they show up in Idle as callable 
 methods), but when I try to call one I get the following message:
 
 Traceback (most recent call last):
File pyshell#20, line 1, in module
  b.SetTitle('test')
 TypeError: Expected a COM this pointer as first argument
 
 Sorry to be so dense, I'm still learning the COM stuff.
 
 Thanks in advance.
 Larry
 
 Test program:
 
 import comtypes.client.GetModule
 GetModule('progdlg.tlb')
 import comtypes.gen.VBProgressDialog
 ci=comtypes.gen.VBProgressDialog
 a=ci.ProgressDialog()
 a.SetTitle('test')

I will look into that, but not before Monday or Tuesday.

Thanks,
Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] LP_WNDCLASS vs pointer to WNDCLASS

2008-01-17 Thread Thomas Heller
Henry Baxter schrieb:
 Hello,
 
 I keep getting this error, and I cannot figure out why. I have code that
 registers a window class that works, and code that does not. Both bits of
 code create a WNDCLASS, both use byref(thewndclassinstance), both make sure
 there is always a reference to the window class structure instance to ensure
 it is not destroyed. Here is the error.
 
 ctypes.ArgumentError: argument 1: type 'exceptions.TypeError': expected
 LP_WND
 CLASS instance instead of pointer to WNDCLASS
 
 Why would byref sometimes create an LP_WNDCLASS, and sometimes a 'pointer to
 WNDCLASS'?

This problem probably happens when you have several WNDCLASS classes defined,
perhaps in several modules.  These classes are similar, but separate, and ctypes
isinstance checks fail.

You should always use the WNDCLASS defined in ctypes.wintypes instead of 
defining
your own.  In ctypeslib dynamic modules, you should place a 'from ctypes import 
*'
and 'from ctypes.wintypes import *' at the top.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Custom control, WS_CHILD

2008-01-13 Thread Thomas Heller
Henry Baxter schrieb:
 Problem solved!
 
 I was using ctypes.byref to pass a reference to the window class, but before
 calling CreateWindow the window class in question went out of scope and was
 destroyed.
 
 I'm worried this type of problem will happen more often, but I'm not sure
 how to stop it...suggestions welcome!

I guess the important thing that needs to be kept alive is the ctypes-pointer
to your WindowProc.  If the window class keeps a reference to the WindowProc
you could attach the window class to the Python class that implements the 
window.
Or you keep it in a global variable, it depends on how your code is structured.

You could also look into the venster code (google for it) for ideas.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Custom control, WS_CHILD

2008-01-13 Thread Thomas Heller
Henry Baxter schrieb:
 Thanks for the tip, venster not only has a neat way to resolve this issue,
 but plenty of other really useful things (lists of windows constants and
 other stuff that take time to assemble).
 

Then you might also be interested in the ctypeslib package; it is able
to make the constants available on demand:

http://starship.python.net/crew/theller/wiki/CodeGenerator/DynamicModule

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Writing .NET component in Python

2007-09-06 Thread Thomas Heller
Larry Bates schrieb:
 Does anyone have any insight where I would start looking for information on 
 writing .NET compatible components in Python.  I have a COM object that is 
 written in Python and some developers have asked for a .NET port of it.  I 
 spent 
 some time in Google and didn't come up with any information to get me going.

Not sure what you mean by .NET port.  I have the impression (from reading, never
used .NET myself) that .NET is able to use COM objects.  It may be required that
the COM objects must have a type library.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Writing .NET component in Python

2007-09-06 Thread Thomas Heller
Sidnei da Silva schrieb:
 [ Thomas Heller ]
 Not sure what you mean by .NET port.  I have the impression (from reading, 
 never
 used .NET myself) that .NET is able to use COM objects.  It may be 
 required that
 the COM objects must have a type library.
 
 That's my understanding too. If you search for articles on .NET and COM 
 Interop pretty much all of them talk about using type libraries.
 
 Soo... the question is, how to create a type library for Python COM objects?
 

The canonical answer is:  Write an IDL file, and compile it with the MIDL 
compiler:

midl mytypelib.idl /tlb mytypelib.tlb

This creates the 'mytypelib.tlb' typelibrary (among other files that you will 
not need).
A MIDL compiler is probably included in the free VC 2005 express edition, or 
maybe even
in the MS platform SDK.

The syntax of IDL files is documented on MS sites.  Also useful for reference
is the OLEVIEW program which allows to decompile existing type libraries.


The second approach would be to use pywin32 apis to create the type library 
programmatically;
there have been several attempts in the past but I have not yet seen a finished 
solution.


What I do NOT know:  Is the presence of a typelibrary file sufficient for 
accessing the COM object,
or must the typelib be integrated into the object itself?  There are interfaces 
that allow a COM
object to make its type information available to clients; I do not know if they 
are used by .NET
or not.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com does not recognise an Interface for events

2007-08-10 Thread Thomas Heller
Len Remmerswaal schrieb:
 
 import comtypes.client as cc
 import comtypes.gen.S7PROSIMLib as S7PS
 class testVehikel:
 def __init__(self, progid, eventsClass):
 self.intf = cc.CreateObject(progid)
 self.rcvr = eventsClass()   ## just added () to assign an obj i.o. a 
 class
 self.cb = cc.GetEvents(self.intf, self.rcvr, S7PS.IS7ProSimEvents)
 ()
 
 I do need the interface definition in GetEvents or I get:  TypeError: cannot 
 determine source interface. So be it.

Sure.  I just wanted to mention that often you do not have to do this.

 Forth, comtypes has a useful function that will help exploring the events: 
 ShowEvents().
 This has the same signature and functionality as the GetEvents function, 
 except that
 you cannot pass the eventreceiver argument:  ShowEvents(obj [, interface]) 
 constructs
 a universal event receiver object itself.  This object will first simply 
 print out
 the event methods that it finds in the source interface, and then will print 
 out
 the event names and arguments when events are received.  Again, you must 
 keep the
 return value of the ShowEvents() call as long as you want to receive events.
   
 I suppose I'll have to download the development version for that: version 
 0.2.1 
 seems not to have ShowEvents.

Please download comtypes-0.3.2 which was released two days ago.

 And finally, depending on the COM apartment your code runs in, and depending
 on the COM object, you may need to run a windows MessageLoop so that events
 are properly dispatched by COM.
   
 I'll try that: right now some events seem to occur only when a corresponding 
 dispatch routine is run, i.e. an event Status changed occurs if I call
 getStatus. I saw an example of how to do this in comtypes\test\test_ie.py.
 What I wonder is how this message loop relates to the pywin message loop in 
 which I currently run this code, or perhaps the wxPython message loop where 
 this 
 code will probably be running in later. BTW: the COM object resides in a DLL 
 so 
 I would think it runs in-process.

IMO in-process or outof-process doesn't matter.
Any message loop should do:  Either the PumpWaitingMessage function in the
test_ie.py module, the pythoncom.PumpWaitingMessage funtion from pywin32,
the message loop that PythonWin uses if you run the code inside that, maybe
even a wxPython, Tkinter or IDLE messageloop.

In the development version of comtypes in SVN I just added the 
PumpWaitingMessages
function to the comtypes.client module.

 
 I final question:
 What should the event routines look like? Currently they look like this:

 class testCalls2:
 def ScanFinished(self, this, ScanInfo):
 print Event: ScanFinished: , ScanInfo
 ()

 on the basis of clsid.py, the result of GetMessage, saying this:

 IS7ProSimEvents._methods_ = [
 COMMETHOD([helpstring(u'Fired when single scan is done.')], HRESULT, 
 'ScanFinished',
   ( [], VARIANT, 'ScanInfo' )),
 ()

 I thought to have read somewhere that I need a (not further needed) 'this' 
 argument. Should I do it like this or should the 'this' argument go?
 So far I have not been able to trigger any of these routines and make them 
 do 
 their printing.
 


 I think this is correct, the this parameter is needed
   
 Almost correct. All event routines must return an integer, or I get this:
 
 Traceback (most recent call last):
   File source/callbacks.c, line 216, in 'converting callback result'
 TypeError: int expected instead of NoneType instance
 Exception  in function func at 0x00EEF370 ignored
 
 after which the thing continues happily.
 At first I tried returning 0 (ERROR_SUCCESS) as the HRESULT , but this hangs 
 up 
 the code. Now I return 1 and it works fine.
 The odd thing is that the methods in EventSink in comtypes\test\test_ie.py do 
 not return anything. Is this a version problem (I use 0.2.1)?

I think so.  Please use 0.3.2: it is much improved.

BTW: You should probably subscribe to the new comtypes-users mailing list,
and move this discussion over there:
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com does not recognise an Interface for events

2007-08-07 Thread Thomas Heller
 OLE Viewer finds a second interface IS7ProSimEvents that is 
 made the default source makepy does not recognise 
 IS7ProSimEvents as an interface at all.
 
 
 It would appear that makepy is excluding non-dual interfaces, and that the
 integration with the 'universal' support for vtable interfaces isn't
 complete.

You could try comtypes: it should support custom interfaces and
custom event interfaces.

'easy_install comtypes==dev' to get the SVN version.

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] comtypes mailing list

2007-08-07 Thread Thomas Heller
Since the number of comtypes users seems to be growing slowly,
I have created a comtypes mailing list.

The mailing list interface is here:

http://lists.sourceforge.net/lists/listinfo/comtypes-users

comtypes homepage:

http://cheeseshop.python.org/pypi/comtypes

Thomas

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Win32 COM cache problem

2007-05-30 Thread Thomas Heller
Marc-André Belzile schrieb:
 I dig a bit more and it appears that the python win32 com module requires all 
 target typelibs to be in the app current directory. Otherwise the cache is 
 systematically re-generated anytime a new scripting engine is created. 
 
 Am I doing something wrong ? Thanks in advance...
 
 -mab
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marc-André 
 Belzile
 Sent: May 28, 2007 6:28 PM
 To: python-win32@python.org
 Subject: [python-win32] Win32 COM cache problem
 
 Hi,
 
 My win32 app is hosting python 2.5 via the scripting ActiveX object. 
 Everything works perfectly but the win32 COM cache behaves strangely if the 
 app current folder (e.g. c:\temp) is different than the application path 
 (e.g. c:\bin\MyApp). At some point when the app needs to create a new python 
 scripting engine, the whole cache gets re-created from scratch which makes 
 things pretty slow. This will not happen if the app is executed from it's 
 normal application folder.
 
 Is there anything I can do to avoid this problem other than running the app 
 from its normal application folder ?
 
 Below is an excerpt of a filemon log that shows the cache generation.
 
 Thanks for your help.
 
 -mab
 
 5:47:26 PM XSI.exe:4964 OPEN 
 C:\Python25\lib\site-packages\win32com\gen_py\269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0.py
  NOT FOUND Options: Open  Access: 00010080
 5:47:26 PM XSI.exe:4964 OPEN 
 C:\Python25\lib\site-packages\win32com\gen_py\269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0.pyc
  NOT FOUND Options: Open  Access: 00010080
 5:47:26 PM XSI.exe:4964 OPEN 
 C:\Python25\lib\site-packages\win32com\gen_py\269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0.pyo
  NOT FOUND Options: Open  Access: 00010080
 5:47:26 PM XSI.exe:4964 CREATE 
 C:\Python25\lib\site-packages\win32com\gen_py\269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0\__init__.py
  SUCCESS Options: OverwriteIf  Access: 00120196
 5:47:26 PM XSI.exe:4964 QUERY INFORMATION 
 C:\Python25\lib\site-packages\win32com\gen_py\269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0\__init__.py
  SUCCESS FileFsVolumeInformation
 5:47:26 PM XSI.exe:4964 QUERY INFORMATION 
 C:\Python25\lib\site-packages\win32com\gen_py\269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0\__init__.py
  BUFFER OVERFLOW FileAllInformation

 ^^^
Have you investigated why the above call fails?  To me this looks like pywin 
cannot determine something about the file,
and then recreates it just in case...

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] DCOM

2007-05-25 Thread Thomas Heller
Francesco Guerrieri schrieb:
 hi Mark,
 
 actually I have used dcomcnfg to set the various accesses. Now I'm at
 loss, since I have looked at all the various tabs and settings
 available, and it seems that all refer to enabling DCOM (which I did)
 and granting access (which I think I did).
 But I will continue trying... I've googled around and found many VB
 users stumbling on the same problems. Only problem is, I didn't
 stumble on the posts with the solution :-)

IIRC, you have to open the firewall for the protocols and ports that DCOM uses.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] com events while running wx main loop

2007-04-20 Thread Thomas Heller
Christian K. schrieb:
 Thomas Heller wrote:
 Christian K. schrieb:
 Now I installed comtypes from svn and get this error running your new
 example:

 Traceback (most recent call last):
File C:\Dokumente und Einstellungen\ck\Desktop\x.py, line 64, in ?
  Listener()
File C:\Dokumente und Einstellungen\ck\Desktop\x.py, line 50, in 
 __init__
  self.com_init()
File C:\Dokumente und Einstellungen\ck\Desktop\x.py, line 59, in 
 com_init
  self.s = comtypes.client.GetEvents(self.o, sink)
File c:\Python24\Lib\site-packages\comtypes\client\__init__.py, 
 line 358, in GetEvents
  raise TypeError(cannot determine source interface)
 TypeError: cannot determine source interface
 
 First of all, when you install a new comtypes version you should clear the
 contents of the comtypes\gen directory, so that the typelib wrappers can
 be regenerated.  The old versions from previous comtypes releases should
 better not be used.
 
 I had the comtypes directory removed before installing from svn.
 
 Second, if you are running the exact sample that I posted then it should work
 for InternetExplorer, and with slight changes also for Outlook.  At least
 it worked for me.
 
 Well, here it doesn't.

I will try to find this problem later.

 I successfully read out the Outlook inbox using comtpyes but finally 
 switched back to pywin32 because I was not able to interprete the value 
 of MailItem.CreationTime,
 e.g:
 obj.Session.Folders['mail.server.com'].Folders['INBOX'].Items.Item(1).CreationTime
 which looks like a posix timestamp which dates back to the 70th. I guess 
 pywin32 is doing some conversion there and comtypes is not?

pywin32 uses the IDispatch interface, which probably returns the time in a 
VARIANT with
typecode VT_DATE, and of type C double.  This way the code knows that a 
date/time is meant
and can convert accordingly.

The outlook type library seems to use the C double also, but comtypes does not 
know that
a date/time is meant.  In COM, date/time is represented as double, in days 
since 30. Dec 1899.
In comtypes\automation is code to do the conversion from/to VARIANT instances, 
from what I see
there you should be able to do the conversion yourself with code like this:

import datetime
_com_null_date = datetime.datetime(1899, 12, 30, 0, 0, 0)

def double_to_datetime(days):
Takes a COM date/time value, a float, and returns a datetime object
return datetime.timedelta(days=days) + _com_null_date

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] com events while running wx main loop

2007-04-20 Thread Thomas Heller
Christian K. schrieb:
 Second, if you are running the exact sample that I posted then it should work
 for InternetExplorer, and with slight changes also for Outlook.  At least
 it worked for me.
 
 Well, here it doesn't.

comtypes uses fairly extensive logging calls in certain areas.  You can enable 
this
to find out the reason.  Here is a little code snippet that shows what happens 
on
my system when I call GetEvents() with Internet Explorer:

code
from comtypes.client import CreateObject, GetEvents
import logging
ie = CreateObject(InternetExplorer.Application)
logging.basicConfig(level=logging.DEBUG)
GetEvents(ie, sink=object())
code/

and here is the output:

DEBUG:comtypes.client._events:POINTER(IWebBrowser2) object e27d00 using 
sinkinterface from clsid class 'comtypes.gen.
_EAB22AC0_30C1_11CF_A7EB_C05BAE0B_0_1_1.DWebBrowserEvents2'
DEBUG:comtypes.client._events:Start advise class 
'comtypes.gen._EAB22AC0_30C1_11CF_A7EB_C05BAE0B_0_1_1.DWebBrowserE
vents2'
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({0003-000
0--C000-0046}) - E_NOINTERFACE
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({0003-000
0--C000-0046}) - E_NOINTERFACE
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({001B-000
0--C000-0046}) - E_NOINTERFACE
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({-000
0--C000-0046}) - S_OK
DEBUG:comtypes._comobject:1 active COM objects: Added   
comtypes.client._events._DispEventReceiver object at 0x00DAD910

DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.AddRef() - 1
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.AddRef() - 2
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({0018-000
0--C000-0046}) - E_NOINTERFACE
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({0019-000
0--C000-0046}) - E_NOINTERFACE
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({4C1E39E1-E3E
3-4296-AA86-EC938D896E92}) - E_NOINTERFACE
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.Release() - 1
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.QueryInterface({34A715A0-658
7-11D0-924A-0020AFC7AC4D}) - S_OK
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.AddRef() - 2
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.AddRef() - 3
DEBUG:comtypes:Release POINTER(IConnectionPointContainer) object dab300
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.Release() - 2
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.Release() - 1
DEBUG:comtypes._comobject:comtypes.client._events._DispEventReceiver object at 
0x00DAD910.Release() - 0
DEBUG:comtypes._comobject:0 active COM objects: Removed 
comtypes.client._events._DispEventReceiver object at 0x00DAD910

DEBUG:comtypes:Release POINTER(IConnectionPoint) object dab030
DEBUG:comtypes:Calling CoUnititialize()
DEBUG:comtypes:CoUnititialize() done.

You should run the snippet yourself and compare the output.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] com events while running wx main loop

2007-04-19 Thread Thomas Heller
Christian K. schrieb:
 
 Now I installed comtypes from svn and get this error running your new
 example:
 
 Traceback (most recent call last):
File C:\Dokumente und Einstellungen\ck\Desktop\x.py, line 64, in ?
  Listener()
File C:\Dokumente und Einstellungen\ck\Desktop\x.py, line 50, in 
 __init__
  self.com_init()
File C:\Dokumente und Einstellungen\ck\Desktop\x.py, line 59, in 
 com_init
  self.s = comtypes.client.GetEvents(self.o, sink)
File c:\Python24\Lib\site-packages\comtypes\client\__init__.py, 
 line 358, in GetEvents
  raise TypeError(cannot determine source interface)
 TypeError: cannot determine source interface

First of all, when you install a new comtypes version you should clear the
contents of the comtypes\gen directory, so that the typelib wrappers can
be regenerated.  The old versions from previous comtypes releases should
better not be used.

Second, if you are running the exact sample that I posted then it should work
for InternetExplorer, and with slight changes also for Outlook.  At least
it worked for me.

Third, the GetEvents function requires that the COM object exposes type 
information,
and that this information includes info about the outgoing default interface.
Some objects do not do this, then you have to find the outgoing interface 
yourself
and pass that as the 'interface=...' parameter to the GetEvents function (this 
description
is from memory, read the sources to find out).

 As I'm real beginner with python on windows I'd like to ask some 
 elementary questions if you don't mind:
 1) Does comtypes depend on pywin32?

No, it is completely independend.

 2) It seems that it provides the same (similar) mapi interface as 
 pywin32, so can it be used as a replacement for pywin32?
 3) Does comtypes expose the extended mapi?

I never used mapi so I cannot really answer this.
comtypes normally creates the typelib wrappers itself; when these
contain the mapi interfaces then there are chances that it would work.

 Thanks for your help, Christian

If you are a newbie to COM, and pywin32 exposes the functionality that you need
you should probably better use pywin32. It is stable, well maintained, and 
documented.
You should probably get the 'Python Programming on Win32' book, or at least read
the online sample chapter.

However, if you are brave, if you need to use non-dispatch based interfaces; 
then
comtypes may be what you want.

Hope it really helps,

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] com events while running wx main loop

2007-04-18 Thread Thomas Heller
Christian K. schrieb:
 sorry. I forgot the attachment.
 
 Christian
 
 
 
 
 
 import unittest
 import comtypes.client
 
 import wx
 
 class EventHandler(object):
 Instances are called when the COM object fires events.
 def __init__(self, view, name):
 self.view = view
 self.name = name
 
 def __call__(self, this, *args, **kw):
 self.view.write(unicode(Event %s fired % self.name, args, kw))

Here is the problem:  
You are calling the unicode function with three arguments ;-).
Unfortunately, by default you do not get a traceback that points out the 
problem.

You can enable the tracebacks with these lines at  the top of your script:

import logging
logging.basicConfig(level=logging.WARNING)

BTW:  I see that you are using an old version of comtypes (in recent versions 
the CreateObject function
does not accept a 'sink' argument any longer; you have to setup the events by 
calling
comtypes.client.GetEvents function, and keep the returned object as long as you 
want
to receive the events).  Unfortunately I have never released a newer comtypes, 
but
you can get it with 'easy_install comtypes==dev', if you have svn installed.

Thomas

PS: I'll attach a working script that I have made, it connects to internet 
explorer which
is my favorite com client for testing (although I don't use it for browsing).




x.py
Description: application/python
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com: Problem with passing short integer?

2007-01-09 Thread Thomas Heller
Einar Sørheim schrieb:
 Hi,
 I have a set of com dlls that I have a hard time to get working together 
 with python.
[...]
 I have  sample programs doing the same in c++ and VB and it works there. 
 Have tried comtypes but then stumbles on another problem
 earlier in the program.

If it really works in C++ and VB, at least the problem cannot be that
the type library does not match the interface.  So it could still be
a comtypes problem.

I guess it is not possible for me to download the COM object you are using
somewhere and try for myself?

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] comtypes: Problem with passing string argument

2007-01-08 Thread Thomas Heller
Einar Sørheim schrieb:
 I have a com library that I have a hard time getting to work, some of it 
 works in win32com, some in comtypes.
 Have a question first for comtypes(using python2.4 and svn checkout 
 3.jan07 of comtypes):
 The following code fails at the last step:
 self.dl = comtypes.client.GetModule(rC:\Program Files\Common 
 Files\Calsep\PvtsDataLayer.dll)
 self.fl = comtypes.client.GetModule(rC:\Program Files\Common 
 Files\Calsep\PvtsDataModel.dll)
 self.datalayer = 
 comtypes.client.CreateObject(self.dl.FluidDepoWaxDataLayer)
 self.fluid = comtypes.client.CreateObject(self.fl.Fluid)
 cp=self.datalayer.CheckCompatibility(DatabasePath=rC:\Program 
 Files\Calsep\Sample Programs\FlashOSDatabase.fdb)
 Errormessage:
   File mtucpvt.py, line 46, in Connect
 cp=self.datalayer.CheckCompatibility(DatabasePath=rC:\Program 
 Files\Calsep\Sample Programs\FlashOSDatabase.fdb)
 ValueError: Procedure probably called with too many arguments (4 bytes 
 in excess)
 
 The generated inteface code looks like:
 _FluidDepoWaxDataLayer._methods_ = [
 COMMETHOD([dispid(1745027104), 'propput'], HRESULT, 'UseDatabaseFormat',
   ( ['in'], PvtsDLUseDatabaseFormat, 'None' )),
 COMMETHOD([dispid(1745027104), 'propget'], HRESULT, 'UseDatabaseFormat',
   ( ['retval', 'out'], POINTER(PvtsDLUseDatabaseFormat), 
 'None' )),
 COMMETHOD([dispid(1610809375)], HRESULT, 'IsConnectedAsReadOnly',
   ( ['retval', 'out'], POINTER(VARIANT_BOOL), 'None' )),
 COMMETHOD([dispid(1610809374)], HRESULT, 'CheckCompatibility',
   ( ['in'], BSTR, 'DatabasePath' ),
   ( ['retval', 'out'], POINTER(c_short), 'None' )),
 
 Any ideas on what is wrong here?

This looks like some problem with the interface code.  Was it generated or
written manually?  Does (re-)generating the module help?  Are you sure
that the type library is up-to-date?

If you also have problems using the object in win32com, what are the symptoms?

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] comtypes

2006-12-21 Thread Thomas Heller
Niki Spahiev schrieb:
 Thomas Heller wrote:
 comtypes seems to gain some attention (comtypes is a pure Python, lightweight
 COM client and server framework, based on the ctypes Python FFI package.)
 
 I'll try to release a new version over the next days.
 
 However, I'm wondering what would be the correct list to discuss this 
 package...
 
 - the python-win32 mailing list
 
 IMO most of COM knowledge is in python-win32 list. It's better not to 
 split due to python implementation details only.

I think that this is a convincing argument.  So, I will suggest to use
the python-win32 mailing list for questions about comtypes.

Thanks,
Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Implementing custom com interface, passing it to another com object for callbacks

2006-12-08 Thread Thomas Heller
johnny loops schrieb:
 Thomas, thanks for your help.  Everything seemed to work except when I
 needed to pass my com object to another com function to receive
 callbacks
 
  o=myComObjClass()
  otherDispatchedComObject.FunctionThatNeedsInterface(o, otherInputs)
 
 The other dispatched com object was created using win32com, and other
 functions of it work fine.  However, this specific function needs to
 be called with a com object implementing the interface as one of the
 inputs, and then its functions will be called as callbacks. The error
 I get when I pass o to this function is
 
 ValueError: argument is not a COM object
 
 Do you have any suggestions?  Thanks again for your help

If I understand you correctly, you have created the otherDispatchedComObject
by calling some win32com functions, and you want to pass a comtypes object
to a method of otherDispatchedComObject?

If this is so, then it fails because win32com does not know anything about
comtypes.  Fortunately, pythoncom25.dll exposes a function that can be called
with ctypes to do the conversion.  I have attached a module containing a 
unittest
that does this.  The 'comtypes2pywin' function accepts a comtypes COM pointer
or a comtypes COMObject instance and returns a win32com object - a PyIDispatch
object, or a PyOIUnknown object.

I think that should do what you want - please report back.  This code should 
probably
go into comtypes somewhere.

Thomas
import unittest

from ctypes import PyDLL, py_object, c_void_p, byref, POINTER
from ctypes.wintypes import BOOL

from comtypes import IUnknown
from comtypes.client import CreateObject
from comtypes.automation import IDispatch

import pythoncom
import win32com.client

# We use the PyCom_PyObjectFromIUnknown function in pythoncom25.dll to
# convert a comtypes COM pointer into a pythoncom COM pointer.
# Fortunately this function is exported by the dll...
#
# This is the C prototype; we must pass 'True' as third argument:
#
# PyObject *PyCom_PyObjectFromIUnknown(IUnknown *punk, REFIID riid, BOOL 
bAddRef)

_PyCom_PyObjectFromIUnknown = 
PyDLL(pythoncom.__file__).PyCom_PyObjectFromIUnknown
_PyCom_PyObjectFromIUnknown.restype = py_object
_PyCom_PyObjectFromIUnknown.argtypes = (POINTER(IUnknown), c_void_p, BOOL)

def comtypes2pywin(ptr, interface=None):
Convert a comtypes pointer 'ptr' into a pythoncom
PyIinterface object.

'interface' specifies the interface we want; it must be a comtypes
interface class.  The interface must be implemented by the object;
and the interface must be known to pythoncom.

If 'interface' is specified, comtypes.IUnknown is used.

if interface is None:
interface = IUnknown
return _PyCom_PyObjectFromIUnknown(ptr, byref(interface._iid_), True)



def comtypes_get_refcount(ptr):
Helper function for testing: return the COM reference count of
a comtypes COM object
ptr.AddRef()
return ptr.Release()

from comtypes import COMObject

class MyComObject(COMObject):
A completely trivial COM object implementing IDispatch. Calling
any methods will return the error code E_NOTIMPL (except the
IUnknown methods; they are implemented in the base class.
_com_interfaces_ = [IDispatch]



class Test(unittest.TestCase):
def tearDown(self):
if hasattr(self, ie):
self.ie.Quit()
del self.ie

def test_mycomobject(self):
o = MyComObject()
p = comtypes2pywin(o, IDispatch)
disp = win32com.client.Dispatch(p)
self.failUnlessEqual(repr(disp), COMObject unknown)

def test_ie(self):
# Convert a comtypes COM interface pointer into a win32com COM
# pointer.
ie = self.ie = CreateObject(InternetExplorer.Application)
# The COM refcount of the created object is 1:
self.failUnlessEqual(comtypes_get_refcount(ie), 1)
# IE starts invisible:
self.failUnlessEqual(ie.Visible, False)

# Create a pythoncom PyIDispatch object from it:
p = comtypes2pywin(ie, interface=IDispatch)
self.failUnlessEqual(comtypes_get_refcount(ie), 2)

# Make it usable...
disp = win32com.client.Dispatch(p)
self.failUnlessEqual(comtypes_get_refcount(ie), 2)
self.failUnlessEqual(disp.Visible, False)

# Cleanup and make sure that the COM refcounts are correct
del p, disp
self.failUnlessEqual(comtypes_get_refcount(ie), 1)

if __name__ == __main__:
unittest.main()
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] comtypes

2006-12-07 Thread Thomas Heller
comtypes seems to gain some attention (comtypes is a pure Python, lightweight
COM client and server framework, based on the ctypes Python FFI package.)

I'll try to release a new version over the next days.

However, I'm wondering what would be the correct list to discuss this package...

- the python-win32 mailing list

- the ctypes-users mailing list

- or should I create a new comtypes-users mailing list, mirrored on gmane, of 
course?

Thanks for any opinions,

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Implementing custom com interface, passing it to another com object for callbacks

2006-12-06 Thread Thomas Heller
johnny loops schrieb:
 I have been pining over implementing what seems to be a VB custom com
 interface for some time now, so I thought I would post to the list to see if
 anyone could help.
 
 I have a com component on which I have run makepy.  The function generates a
 couple of classes with functions and callbacks that all work fine when I
 DispatchWithEvents.  However there is one interface that I cannot figure out
 how to use.  This interface is only referenced in the vtables section as
 
 foo_vtables_dispatch_ = 0
 foo_vtables_ = [
 (( 'OnFunc1' , 'variable1' , ), 1610678272, (1610678272, (), [ (36, 1,
 None, None) , ], 1 , 1 , 4 , 0 , 12 , (3, 0, None, None) , 0 , )),
 (( 'OnFunc2' , 'variable2' , ), 1610678273, (1610678273, (), [ (36, 1,
 None, None) , ], 1 , 1 , 4 , 0 , 16 , (3, 0, None, None) , 0 , )),
 ]
 
 foo is also listed in the VTablesToClassMap  and the NamesToIIDMap
 
 Now, OnFunc1 and OnFunc2 are callback functions of an interface that I need
 to implement.  Once I implement the interface, I need to pass that object to
 another com object that will fire callbacks.  So reading some of these
 lists, I thought I should register the interface, create a server, wrap the
 server and pass it to the other com function.
 
 For example:
 universal.RegisterInterfaces(CLSID,0,2,0,[foo])
 class F:
   _com_interfaces_=[foo]
  _typelib_guid_ = CLSID
  _typelib_version_ = 2,0
 _public_methods_ = [] or ['OnFunc1', 'OnFunc2'] -- i've tried both
   def OnFunc1:
 do some stuff
   def OnFunc2
 do some other stuff
 o=wrap(F)
 otherDispatchedComObject.FunctionThatNeedsInterface(o, otherInputs)
 
 This does not produce any errors, but callbacks to OnFunc1 and OnFunc2 never
 fire-- and I know they are firing.  Also wrapping with a debugging
 dispatcher adds produces no information.  Callbacks to the regularly
 dispatched com objects do fire.
 
 So my question is: Is what I am trying to do possible using win32com?  Does
 this seem like it should work?

I cannot comment on this question.

  If not, does anyone have any suggestions
 using comtypes? I have read that vtable interfaces should be no problem for
 comtypes, but I can't find much in the way of documentation/examples.
 Basically, I'm lost here, to the point where I may have to switch to VB
 (eek)--so any help would be appreciated.


I have at least started writing some docs, and posted links to the ctypes users 
list:

  This describes how COM interfaces are defined, used, and implemented in 
comtypes:

  
http://svn.python.org/view/*checkout*/ctypes/trunk/comtypes/docs/com_interfaces.html

  and this describes the comtypes.client high-level module functionality:

  
http://svn.python.org/view/*checkout*/ctypes/trunk/comtypes/docs/comtypes.client.html

I hope these documents have some value.  Also I'm willing to help you
if you want to try out comtypes.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] pythoncom multithread troubles

2006-11-27 Thread Thomas Heller
Kostas Eleftheriou schrieb:
 Hi,
 
 I have built a python application that uses a COM server from multiple
 threads, and despite some initial problems, I got it to work. I found
 out (the hard way) that the COM server would have undefined behaviour
 if some of its functions were called at the same time form multiple
 threads (so it was not thread-safe, although from the registry keys it
 looked as if it was), so I made the calls from my application
 sequential using locks etc.

The most important thing to remember is that you *MUST* marshal com pointers
correctly between the different com apartments.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Determine admin rights

2006-11-15 Thread Thomas Heller
Arve Knudsen schrieb:
 Hi
 Is there a way I can determine whether a user is a local administrator using
 pywin32? I've used NetUserGetLocalGroups to see if the user is in the
 Administrators group, but this breaks on non-English versions of Windows.
 As far as I can see there exists a function IsUserAnAdmin in shell32.lib (
 shlobj.h), would it be possible to expose this through pywin32?
 
Maybe this works?

import ctypes
print ctypes.windll.shell32.IsUserAnAdmin()

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] py2exe and winxptheme

2006-11-14 Thread Thomas Heller
Andrea Gavana schrieb:
 Hi Thomas,
 

 Let me try to guess:  Do you have an XP-style manifest for the exe?

 
 Yes, I have it, embedded in the setup.py script. I have removed it
 from the file I sent to the mailing list because I thought it was
 redundant, but if you need to see it I can attach it to my e-mail. Is
 it a problem if I have a XP-Style manifest file? Sorry to be so
 ignorant in py2exe/WinXP things...

The manifest file is used to provide the app with the XP-native look and feel.
I thought it could also be related to the OpenTheme stuff...

 I attach the complete setup.py file. Thank you so much.

Seems I have to disappoint you - I have no idea anymore.  But then,
I've never used these theme functions.

Sorry,
Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] how to get the interface of an COM object?

2006-11-14 Thread Thomas Heller
Bruce Who schrieb:
 Hi, Thomas
 
 Finally I make it to create a COM object:
 
 class EventSink:
 def OnLoadFinished(self):
 print 'load finished'
 
 o = comtypes.client.CreateObject(SomeObj2.SomeObj.1, sink=EventSink())
 
 but the EventSink.OnLoadFinished() is never called, and I still donnot
 know how to get an interface, :-(


Well, comtypes.client.CreateObject /returns/ a pointer to a COM interface.
If it is not the interface you want, you can call 
o.QueryInterface(IOtherInterface)
on it - how you get or create the IOtherInterface Python class that 'describes'
the interface is another question.  If the COM object supplies type information
then comtypes generates a Python wrapper for the type library automatically
in the 'comtypes.gen' package.  The module name is derived from the type 
library,
for example for InternetExplorer  the typelib is name comtypes.gen.SHDocVw (Note
that this is a very shallow module, it imports everything from another module 
that
is named after the GUID and version from the typelib; for IE it is
'comtypes.gen._EAB22AC0_30C1_11CF_A7EB_C05BAE0B_0_1_1').
You can import the interfaces from any of these modules.

For the events: First, the event handler methods receive an additional argument
'this' just after the 'self', this is an implementation detail of comtypes; 
which
mirrors that COM methods you *implement* also receive this argument.
Then, it could be that the name of the method is wrong; comtypes does *not* 
prepend
an 'On' to the method name.

A useful event sink for COM objects is one that responds to __getattr__ by 
dynamically
creating event handlers, the attached script demonstrates this (for IE, again).

Oh, there 'may* be a totally different reason why you don't receive events:
By default, comtypes (like pythoncom) creates a single-threaded COM appartment,
in which you usually should run a message pump.

Thomas

import unittest
import comtypes.client

class EventHandler(object):
Instances are called when the COM object fires events.
def __init__(self, name):
self.name = name

def __call__(self, this, *args, **kw):
print Event %s fired % self.name, args, kw

class Events(object):
Provide handlers for COM events.
def __init__(self):
self._event_names = set()

def __getattr__(self, name):
if name.startswith(__) and name.endswith(__):
raise AttributeError(name)
print # event found:, name
self._event_names.add(name)
return EventHandler(name)

class EventsTest(unittest.TestCase):
def test(self):
sink = Events()
o = comtypes.client.CreateObject(InternetExplorer.Application,
 sink = sink)

from comtypes.gen.SHDocVw import IWebBrowser
print
print Default interface, o
print IWebBrowser interface, o.QueryInterface(IWebBrowser)

o.Visible = True
o.Visible = False
o.Quit()

if __name__ == __main__:
unittest.main()
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] py2exe and winxptheme

2006-11-14 Thread Thomas Heller
Andrea Gavana schrieb:
 Hi all,
 
 I am having some troubles mixing py2exe and winxptheme. Basically,
 I am using wxPython 2.7.2.0 with Python 2.5, and painting some window
 background using the UxTheme via winxptheme. This is what I am doing:
 
 hwnd = MyWindow.GetHandle()
 self.hTheme = winxptheme.OpenThemeData(hwnd, Window)
 
 winxptheme.DrawThemeBackground(self.hTheme, dc.GetHDC(), 5, 1,
(rc.top, rc.left, rc.right, rc.bottom), None)
 
 
 This works very well using python directly, but when I generate and
 executable file with py2exe, I get this error when executing that last
 line:
 
 TypeError: an integer is required
 
 This is because self.hTheme is *None*. It seems like OpenThemeData can
 not be initialized in an executable, or at least that I am not able to
 do it.

Let me try to guess:  Do you have an XP-style manifest for the exe?

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Waiting for Wireless

2006-10-25 Thread Thomas Heller
Tim Roberts schrieb:
 As a self-proclaimed studly Win32 programmer, I'm embarrassed at not
 being able to find a neat solution to this.  I come to you humbly,
 seeking coolness.
 
 I have a script on my laptop that runs after login and launches the
 tools that I use all the time, including the putty password agent, the
 Agent newsreader, and Firefox.  My wireless card takes about 15 seconds
 to sync up with my access point and get an IP address, by which time my
 script is done and the tools are running.  That means that Firefox
 always comes up complaining that it couldn't reach my home page.  So,
 I'd like to have my script wait for connectivity before launching the
 tools.  The question is, how can that be done?
 
 I could use os.system to poll the ipconfig command, but that's icky
 and not at all studly.  I could loop on gethostaddr for localhost until
 it gets an IP, but even that's not studly, because there's no way to
 know that it's really the wireless adapter's IP address.
 
 There must be a way for me to ask the musical question, does the
 network adapter called 'Wireless Network Adapter' have an IP address? 
 Does anybody know that tune?
 

I have a module lying around that does this.  Should work on 2k and XP, at 
least.
You call it with the 'friendly name' of the network adaper, and it displays the
ip address and network mask (IIRC).  Should be easy to adapt to our needs, and 
more.

Thomas
# This module MUST also work on win2k, although some functions
# exported by iphlpapi are win XP only!
from ctypes import *
from ctypes.wintypes import DWORD, BOOL, HANDLE

MAX_ADAPTER_ADDRESS_LENGTH = 8
MAX_ADAPTER_DESCRIPTION_LENGTH = 128
MAX_ADAPTER_NAME_LENGTH = 256

IP_MASK_STRING = IP_ADDRESS_STRING = c_char * 16

class IP_ADDR_STRING(Structure):
pass
IP_ADDR_STRING._fields_ = [(Next, POINTER(IP_ADDR_STRING)),
   (IpAddress, IP_ADDRESS_STRING),
   (IpMask, IP_MASK_STRING),
   (Context, DWORD)]

class IP_ADAPTER_INFO(Structure):
pass
IP_ADAPTER_INFO._fields_ = [(Next, POINTER(IP_ADAPTER_INFO)),
(ComboIndex, DWORD),
(AdapterName, c_char * (MAX_ADAPTER_NAME_LENGTH + 
4)),
(Description, c_char * 
(MAX_ADAPTER_DESCRIPTION_LENGTH + 4)),
(AddressLength, c_uint),
(Address, c_byte * MAX_ADAPTER_ADDRESS_LENGTH),
(Index, DWORD),
(Type, c_uint),
(DhcpEnabled, c_uint),
(CurrentIpAddress, POINTER(IP_ADDR_STRING)),
(IpAddressList, IP_ADDR_STRING),
(GateWayList, IP_ADDR_STRING),
(DhcpServer, IP_ADDR_STRING),
(HaveWins, BOOL),
# ... more
]


class AdapterError(Exception):
pass

def GetAdapterInfo(friendlyName):
# Return a list containing (ip address, netmask) tuples for an
# adapter of the given friendly name (that's the name that is
# shown in Network and Dial-up Connections)
outbuflen = c_ulong()
windll.iphlpapi.GetAdaptersInfo(None, byref(outbuflen))

# hack, hack, hack
cdll.msvcrt.malloc.restype = POINTER(IP_ADAPTER_INFO)
p = cdll.msvcrt.malloc(outbuflen.value)

windll.iphlpapi.GetAdaptersInfo(p, byref(outbuflen))

h = HANDLE()
windll.mprapi.MprConfigServerConnect(None, byref(h))

result = []
while 1:
adapterName = (c_wchar * 256)()
windll.mprapi.MprConfigGetFriendlyName(h,
   unicode(p[0].AdapterName),
   byref(adapterName),
   sizeof(adapterName))
if adapterName.value.lower() == friendlyName.lower():
a = p[0].IpAddressList
while 1:
result.append((a.IpAddress, a.IpMask))
if a.Next:
a = a.Next[0]
continue
return result

p = p[0].Next
if not p:
raise AdapterError, Network adapter '%s' not found % friendlyName
return result

if __name__ == __main__:
import sys
print GetAdapterInfo(sys.argv[1])
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Trouble Automating Alibre CAD package

2006-07-12 Thread Thomas Heller
[EMAIL PROTECTED] schrieb:
 Hello,
 
 I am trying to use pywin32 to automate a CAD package from Alibre 
 (www.alibre.com) called Design Express.
 
 The documentation I can get is written for Visual Basic (and not all that 
 well at that), and I get the following error from the following lines:
 
 [Python Code]
 import win32com.client
 
 AlibreObject=win32com.client.Dispatch(rAlibreX.AutomationHook)
 [End Python code]
 
 Error traceback:
 AlibreObject = win32com.client.Dispatch(rAlibreX.AutomationHook)
   File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 95, 
 in Dispatch
 dispatch, userName = 
 dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
   File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 98, 
 in _GetGoodDispatchAndUserName
 return (_GetGoodDispatch(IDispatch, clsctx), userName)
   File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 78, 
 in _GetGoodDispatch
 IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, 
 pythoncom.IID_IDispatch)
 pywintypes.com_error: (-2147467262, 'No such interface supported', None, None)
 

The problem seems that the COM object that Alibre implements is buggy.  
According to the
type library (I've installed the free Express version) the call above should 
return an
object that implements the IAutomationHook interface, which is derived from 
IDispatch:

[
  odl,
  uuid(424539A8-7014-4174-B0BF-F5EE5BB71DF5),
  helpstring(IAutomationHook interface),
  dual,
  oleautomation
]
interface IAutomationHook : IDispatch {
[id(0x0001), propget, helpstring(Returns the automation root)]
HRESULT Root([out, retval] IDispatch** ppRoot);
[id(0x0002), helpstring(Initiates a new Alibre Design Automation 
client)]
HRESULT Initialize(
[in] BSTR serverURL, 
[in] BSTR loginID, 
[in] BSTR passwd, 
[in] VARIANT_BOOL disableSecureMode, 
[in] int unused);
[id(0x0003), helpstring(Initiates a new Debug client)]
HRESULT InitializeDebug(
[in] BSTR serverURL, 
[in] BSTR loginID, 
[in] BSTR passwd, 
[in] VARIANT_BOOL disableSecureMode, 
[in] int unused);
};

Experiments with comtypes (the ctypes com framework) show that the
object can successfully be QueryInterface'd for IAutomationHook, but not
for IDispatch.  I'm not sure pywin32 can handle such a buggy object,
but you could probably try to run makepy on the typelib and then
create the object.  Others may have more knowledge if or how this
would work.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Trouble Automating Alibre CAD package

2006-07-12 Thread Thomas Heller
[EMAIL PROTECTED] schrieb:
  Hello,
  
  I am trying to use pywin32 to automate a CAD package from Alibre 
  (www.alibre.com) called Design Express.
  
  The documentation I can get is written for Visual Basic (and not all that 
  well at that), and I get the following error from the following lines:
  
  [Python Code]
  import win32com.client
  
  AlibreObject=win32com.client.Dispatch(rAlibreX.AutomationHook)
  [End Python code]
  
  Error traceback:
  AlibreObject = win32com.client.Dispatch(rAlibreX.AutomationHook)
File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 
  95, in Dispatch
  dispatch, userName = 
  dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 98, 
  in _GetGoodDispatchAndUserName
  return (_GetGoodDispatch(IDispatch, clsctx), userName)
File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 78, 
  in _GetGoodDispatch
  IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, 
  pythoncom.IID_IDispatch)
  pywintypes.com_error: (-2147467262, 'No such interface supported', None, 
  None)
  

The problem seems that the COM object that Alibre implements is buggy.  
According to the
type library (I've installed the free Express version) the call above should 
return an
object that implements the IAutomationHook interface, which is derived from 
IDispatch:

[
  odl,
  uuid(424539A8-7014-4174-B0BF-F5EE5BB71DF5),
  helpstring(IAutomationHook interface),
  dual,
  oleautomation
]
interface IAutomationHook : IDispatch {
[id(0x0001), propget, helpstring(Returns the automation root)]
HRESULT Root([out, retval] IDispatch** ppRoot);
[id(0x0002), helpstring(Initiates a new Alibre Design Automation 
client)]
HRESULT Initialize(
[in] BSTR serverURL, 
[in] BSTR loginID, 
[in] BSTR passwd, 
[in] VARIANT_BOOL disableSecureMode, 
[in] int unused);
[id(0x0003), helpstring(Initiates a new Debug client)]
HRESULT InitializeDebug(
[in] BSTR serverURL, 
[in] BSTR loginID, 
[in] BSTR passwd, 
[in] VARIANT_BOOL disableSecureMode, 
[in] int unused);
};

Experiments with comtypes (the ctypes com framework) show that the
object can successfully be QueryInterface'd for IAutomationHook, but not
for IDispatch.  I'm not sure pywin32 can handle such a buggy object,
but you could probably try to run makepy on the typelib and then
create the object.  Others may have more knowledge if or how this
would work.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Building pywin32 with the free MS toolkitcompiler

2006-04-19 Thread Thomas Heller
Paul Moore wrote:
 On 4/19/06, Roger Upole [EMAIL PROTECTED] wrote:
 I've removed the ATL macros from win32wnet. (checkin messages are still 
 bouncing)
 
 Cool, thanks. I was going to look at this, but real life came along...
 
 When I get back to it, I'll see how much I can get running, and post a
 patch on SF.
 
 Paul.
 
 PS Is SF CVS the right place to get the latest sources? I ask because
 the log for win32wnet on there (using the viewcvs interface) shows the
 last change to win32wnet.cpp being by Mark, 5 months ago, saying
 Finish the excise of the atl unicode conversion macros. I'm confused
 - has Guido been letting the time machine keys out of his sight again?
 :-)

The anon CVS on SF is not currently synced with the developer CVS servers:

http://sourceforge.net/docman/display_doc.php?docid=2352group_id=1#1145038684

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ATT DSP32C to IEEE

2006-01-06 Thread Thomas Heller
RayS [EMAIL PROTECTED] writes:

 I'm trying to find an efficient way to convert from DSP32C binary files
 smmm   
 to IEEE float
 seee emmm  

 I tried struct and bit-shifting from a C manual example, but it 
 failed. Has someone else coded this in Python? I'll post the early 
 attempt when I get into the office later, if not.

 I re-coded from scratch, converting each 32 bit ATT value to a binary 
 string, slice-rearranging bits, then re-packing to IEEE. A bit 
 slow. At least they're small files.

You could try ctypes bitfield structures, maybe, to access the fields?

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to unload ShellExtension?

2006-01-04 Thread Thomas Heller
aurora [EMAIL PROTECTED] writes:

 I have previously asked about how to reload a ShellExtension during  
 development. There a a few good suggestions like killnig the explorer  
 process.

AFAIK, the official way to kill explorer (useful during development) on
XP is to press Start-Shutdown.  In the dialog box that now appears,
while holding down ALT-CTRL-SHIFT click the cancel button.  This will
end explorer.  Then use CTRL-SHIFT-ESCAPE to open task manager and start
a new explorer instance (via New Task).

 Now I run into a bigger issue. When I uninstall (using innosetup), the
 process is still loaded and it lock up scores of DLLs.  Killing
 explorer is probably too heavy handed for end users. So let me try one
 more time, is there anyway to positively tell explorer to unload a COM
 server?

For the end user there's no other way than to reboot.  Isn't this what
innosetup suggests anyway?

I cannot understand why MS didn't provide a way to programmatically
restart explorer.  And, BTW, the problem isn't python specific.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com v.s. win32comext?

2006-01-03 Thread Thomas Heller
aurora [EMAIL PROTECTED] writes:

 I use win32com.shell. There are something special going on I don't  
 understand. Notice the commands below. I imported win32com.shell. But the  
 module is being loaded from win32comext\shell\__init__.pyc.

 import win32com.shell
 win32com.shell
 module 'win32com.shell' from  
 'c:\Python24\Lib\site-packages\win32comext\shell\__init__.pyc'

 What is the mechanism to make this happen?

It is __path__ trickery in win32com\__init__.py:

c:\py24
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 import win32com
 win32com.__path__
['c:\\python24\\lib\\site-packages\\win32com', 
'c:\\python24\\lib\\site-packages\\win32comext']



 I am digging into this because when I try to use py2exe, I got this
 error:

 The following modules appear to be missing
 ['win32com.shell']


http://starship.python.net/crew/theller/moin.cgi/WinShell

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com and static dispatch

2005-11-03 Thread Thomas Heller
geon [EMAIL PROTECTED] writes:

 Does there exist any tutorial/manual about static vs. dynamic dispatch?

 Thank you
 Pavel

Mark Hammond's book Programming Python on win32.

http://www.oreilly.com/catalog/pythonwin32/

A sample chapter is online:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] hide subshell os.system

2005-09-23 Thread Thomas Heller
le dahut [EMAIL PROTECTED] writes:

 Hi everyone,

 How can the subshell be hidden when executing code such as :

 os.system('ping host') ?

 The program uses GTK and it's very annoying to see a black window when
 using a graphical program ...

You should use the subprocess module instead, it is more flexible and
should allow this.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] wmi - 9x and py2exe

2005-09-23 Thread Thomas Heller
le dahut [EMAIL PROTECTED] writes:

 I've crawled google and its search results in broad, length and through
 but I didn't find a real explanation concerning the use of wmi with
 py2exe under win 9x/Me.

 My program works fine on the 98 machine where python pygtk gtk runtime
 and wmi are installed. I want to run it on fresh installed machines,
 where nothing but the base system is installed. Is it possible to hard
 compile WMi ?

The windows WMI runtime must be installed in the win98 machine,
otherwise it cannot work.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Open PDF

2005-09-22 Thread Thomas Heller
Jorge Ramirez [EMAIL PROTECTED] writes:

 Hello,
  
 I would like to know how to open a PDF document from a python script,
 any suggestions are appreciated.

os.startfile(mydoc.pdf)

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Getting tired with py2exe

2005-09-20 Thread Thomas Heller
I'm slowly getting tired maintaining py2exe.  It is far from perfect,
although it has interesting features (I would say).

The problem, apart from the work, is that it is good enough for me - I
can do everything that I need with it.  But I assume I use far less
libaries than other Python programmers, so a lot of bugs will never bite
me.

It is also interesting that the recently introduced bundle-files option,
which allows to build single-file exes has gained a lot of interest -
although the ONLY use case (so far) I have myself for it is to implement
inproc COM servers which will compatible with Python clients (and other
Python inproc COM servers) because of the total isolation of the Python
VMs.

Is anyone interested in taking over the maintainance, documentation, and
further development?

Should py2exe be integrated into another, larger, package?  Pywin32
comes to mind, but also Philip Eby's setuptools (that's why I post to
distutils-sig as well)...

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com events using native interfaces

2005-09-15 Thread Thomas Heller
Michael Zuercher [EMAIL PROTECTED] writes:

 I have a COM object that sends events. Rather that have the source 
 interface be 'dispinterface' in the IDL, it is just 'interface'. Is 
 there a way to catch events from this interface using win32com? The IDL 
 for the coclass is below for reference.

 [
uuid(10020202-EB1C-11CF-AE6E-00AA004A34D5),
version(2.0),
helpstring(Data Transformation Services Package Object),
helpcontext(0x02ee)
 ]
 coclass Package2 {
  interface _Package;
  [default] interface _Package2;
  [default, source] interface PackageEvents;
 };

Although it isn't in the recently released 0.1 version, comtypes
supports this.  Also you can receive events from a non-default source
interface.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] WindowsError: (0, 'The operation completed successfully') with compiled prog only

2005-09-15 Thread Thomas Heller
Ray Schumacher [EMAIL PROTECTED] writes:

 Hi all, anyone seen this?

 I'm writing a Win98 replacement shell; when I compile with console=[foo] I 
 get no errors logged or in the console, but when compiled with windows=[foo] 
 I get an error when I try to run subprocess:

 Traceback (most recent call last): 
   File Frame2.pyo, line 75, in OnProcessTimer 
   File Frame2.pyo, line 83, in getProcList 
   File Frame2.pyo, line 97, in launchWithoutConsole 
   File subprocess.pyo, line 549, in __init__ 
   File subprocess.pyo, line 626, in _get_handles 
 WindowsError: (0, 'The operation completed successfully')

 (?)

 My code is:

 result = self.launchWithoutConsole('pv', [-fq,])

 def launchWithoutConsole(self, command, args):
 Launches 'command' windowless and waits until finished
 startupinfo = subprocess.STARTUPINFO()
 startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
 startupinfo.wShowWindow = win32con.SW_HIDE
 proc = subprocess.Popen([command] + args, startupinfo=startupinfo, 
 shell=False,
 bufsize=1000,
 stdin=subprocess.PIPE, stdout=subprocess.PIPE
 )

 return proc.stdout.readlines()

 I've tried many variations, but all (so far) leave a LAUNCHER.EXE.log with 
 this error, even if command =anything else..

 If 'The operation completed successfully' and the error level is zero, why 
 the logged error?
 Can it be suppressed?

 I also posted to py2exe-users...

I answered this on the py2exe-users list.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] py2dll - or an example of a dll writen in python?

2005-09-02 Thread Thomas Heller
Darren Blaser [EMAIL PROTECTED] writes:

 Hi,

 I have a dll that I'd like to write a simple replacement for in python. 
 Is this possible? Is there an example somewhere of a dll written in python?

 The example could be for something as simple as a single dll export 
 implementing the following GetApiVersion call...

 typedef enum _Status
 {
STATUS_SUCCESS   = 0x,
STATUS_FAILED= 0x0001
 }Status;

 typedef struct _ApiVersionInfo
 {
DWORD dwMajor;
DWORD dwMinor;
DWORD dwDetailed
 }ApiVersionInfo;

 Status GetApiVersion(ApiVersionInfo *pstVersion);

 My googling turned up this old post from 5 years ago, but nothing more 
 recent.
 http://mail.python.org/pipermail/python-list/2001-November/074600.html

 Thank you very much for any feedback.

In principle this is not complicated.
Write the dll as usual, and call Python from the exported functions.
Just make sure that you initialize Python somewhere, and be sure to
handle the GIL correctly.

It gets more complicated when the exe-process may also be using Python,
or if other dlls used in the same process are also using Python (maybe
because inproc COM objects are implemented in Python).  Then you must be
prepared to handle the case that Python already *is* initialized.

The next step would be if you want to use py2exe or a similar tool to
distribute your dll to machines that don't have Python installed (if you
need that).

But, of course there is prior art:

pywin32, for example, has a ISAPI extension (which is a dll):
http://cvs.sourceforge.net/viewcvs.py/pywin32/pywin32/isapi/src/pyISAPI.cpp?rev=1.2view=auto

And pywin32's pythoncom, which is the inproc COM server dll.

Thomas



___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problems with XML COM server

2005-07-06 Thread Thomas Heller
Stephen Dicks [EMAIL PROTECTED] writes:

 Hi,
I have a simple COM server in python which parses an XML file via 
 SAX, and I want to distribute it via py2exe as the target machines will 
 not have python installed (and in some cases could not have it installed)

 However I have tried several (recent) versions of py2exe, python itself 
 and the various fixes suggested by various people in the past, but I 
 still can't get it to work in any configuration using either python 
 2.3.5/2.4.1 or py2exe 0.4.2/0.5.4 with Windows XP

 Using python 2.3 and py2exe 0.4.2, a standalone EXE builds and works 
 fine, but the COM server fails the --register command line with 'Cannot 
 locate Python module win32com.server.localserver' while executing 
 UseCommandLine()

 Using python 2.4 and py2exe 0.5.4, the standalone executable fails with:

 Traceback (most recent call last):
File fred.py, line 39, in ?
  parser.parseFile(file(sys.argv[1]))
File xml\sax\drivers\drv_pyexpat.pyc, line 68, in parseFile
File xml\sax\drivers\drv_pyexpat.pyc, line 45, in startElement
  AttributeError: module object has no attribute AttributeMap

 which no-one else seems to have had trouble with.

 Using python 2.3 and py2exe 0.5.4, the py2exe setup stage fails with errors 
 like:

 'Cant find module linecache' 
 'Cant find module xml'

 and the parse stops with 'Cannot find parser' (not surprisingly) if I try to 
 run the resulting executable.

 Does anyone know of a combination that works?

Do you have PyXML installed for Python 2.4, and not Python 2.3?  Maybe
this is the reason that the 2.4 build fails - but this is just a guess.

For the 'Cant find module linecache' (speculation again) please take a
look at this page:

http://adelux.c2a.fr/libre/howto/deployTwistedWindows/#bug-in-py2exe-0-5-4

You could try out a similar fix to the boot_com_servers.py script.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM server with events and multiple threads

2005-06-03 Thread Thomas Heller
Mark Hammond schrieb:
 The problem is that the connection server is getting an interface object on
 one thread (the main thread as part of the Advise call) - but the new
 threads you create are using these objects without marshalling the objects.
 
 ie, your new threads are referencing objects owned by another thread.
 This is why the calls are being delivered to VB on the wrong thread.  If you
 marshalled the objects to the new thread, that marshalling would ensure VB
 received the call on the correct thread.
 
 You marshall the COM object by using CoMarshalInterThreadInterfaceInStream
 and CoGetInterfaceAndReleaseStream.
 
 win32com.server.connect wasn't really designed for this case -
 'self.connections' can only be used directly or indirectly by thead the
 Advise call was made on.  Each thread must have its own copy of the
 interfaces in self.connections, passed to it via
 CoMarshalInterThreadInterfaceInStream.  This will be tricky to work with new
 connections established after the thread has started.  One option may be a
 queue - the main thread could queue CoMarshalInterThreadInterfaceInStream
 wrapped objects, and the worker thread could dequeue the objects and call
 CoGetInterfaceAndReleaseStream before attempting to use the object.
 
 If you could make sensible modifications to win32com.server.connect to
 support that scenario, I'd be happy to integrate them.  You may find it
 easier to fork that class for your own purposes though.
 

Another (easier, imo) option would be to use the Global Interface Table.
Once that is wrapped in win32com.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] CoUninitialize

2005-05-06 Thread Thomas Heller
 I'm experimenting with a pythoncom client which uses a ctypes.com
 server.  I have the impression that DispatchWithEvents somehow doesn't
 clean up correctly.

 That is possible.  Most leaks of COM objects should be evident by querying
 pythoncom._GetInterfaceCount() and pythoncom._GetGatewayCount() - it would
 be interesting to know if these were both zero and you still had the
 problem.

Here is the program I use, it is accessing a localserver COM object:


# ctypes client code, using the CSum COM object
from win32com.client import Dispatch, DispatchWithEvents
import pythoncom

class events:
def OnAdded(self, *args):
print OnAdded, args

def test():
s = DispatchWithEvents(ctypes.SumObject, events)
##s = Dispatch(ctypes.SumObject)
print Adding
print s.Add(3.14, 2.78)
del s

print pythoncom._GetInterfaceCount():, pythoncom._GetInterfaceCount()
print pythoncom._GetGatewayCount():, pythoncom._GetGatewayCount()

print pythoncom.CoUninitialize()
pythoncom.CoUninitialize()

print pythoncom._GetInterfaceCount():, pythoncom._GetInterfaceCount()
print pythoncom._GetGatewayCount():, pythoncom._GetGatewayCount()


if __name__ == __main__:
test()


and the output:


C:\sf\ctypes_dist\win32\com\samples\serverpy23 w32_user.py
Adding
OnAdded ()
5.92
pythoncom._GetInterfaceCount(): 1
pythoncom._GetGatewayCount(): 3
pythoncom.CoUninitialize()
pythoncom._GetInterfaceCount(): 0
pythoncom._GetGatewayCount(): 0

C:\sf\ctypes_dist\win32\com\samples\server


 Is there a reason why pythoncom doesn't call CoUninitialize() itself?

 We had a few problems trying to do that.  In some cases when not all COM
 objects were explicitly closed, we found that system shutdown time could
 cause the object to attempt to release the COM pointer - but *after*
 CoUninit had been called.  But I have found very few errors *not* calling
 it - especially when all COM objects have been cleaned up.  I guess that is
 really just a matter of finding the correct hook (but note that in a COM DLL
 case, Python itself will never be Uninitialized!

ctypes.com uses this strategy to initialize and deinitialize (the code
is part of the ctypes.com module):


ole32.CoInitialize(None)

class _Cleaner(object):
def __del__(self, func=ole32.CoUninitialize):
# Sometimes, CoUnititialize, running at Python shutdown, raises an 
exception.
# We suppress this when __debug__ is False.
if __debug__:
func()
else:
try: func()
except WindowsError: pass

__cleaner = _Cleaner()
del _Cleaner

def _clean_exc_info():
# the purpose of this function is to ensure that no com object
# pointers are in sys.exc_info()
try: 1//0
except: pass

import atexit
atexit.register(_clean_exc_info)


Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Re: Help on using win32api.SendMessage to send keystrokes

2005-04-07 Thread Thomas Heller

 ctypes is a wonderful package -- invaluable for someone doing Win32 API
 work.  Basically, it allows you to call any API in any DLL, as long as
 you can describe the parameters.

 except mapvirtualkey. not that it matters now, anyway, but, behold this:

 # ##code:
 from ctypes import *
 import time

 sc = windll.user32.MapVirtualKey(0x41, 0)
 print sc
 # ##end code

 ###output:
 Traceback (most recent call last):
   File C:\Documents and Settings\dfolkins\Desktop\python
 scripts\mapvirtualkey.py, line 4, in ?
 sc = windll.user32.MapVirtualKey(0x41, 0)
   File C:\Python24\Lib\site-packages\ctypes\__init__.py, line 366,
 in __getattr__
 func = self._StdcallFuncPtr(name, self)
 AttributeError: function 'MapVirtualKey' not found
 ###end output

MapVirtualKey is implemented as unicode and ansi function.  Quote MSDN:
Function Information

Minimum DLL Version user32.dll 
Header Declared in Winuser.h, include Windows.h 
Import library User32.lib 
Minimum operating systems Windows 95, Windows NT 3.1 
Unicode Implemented as ANSI and Unicode versions.  

Which means: Call MapVirtualKeyA for ansi strings, MapVirutalKeyW for
unicode strings.

 so... even though i dont care about mapvirtualkey per se, i wonder
 what gives... any ideas?

 and... if anyone ever happens upon a way to hook and inject events
 upstream of directinput in a nice api-like way, please let me know,
 eh? :)

 Thank you,
 Daniel, off to learn how to inject dll

Hehe. Good luck.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Re: reading from console child process

2005-04-05 Thread Thomas Heller
Niki Spahiev [EMAIL PROTECTED] writes:

 Chris Maloof wrote:

 Thanks for the help!  ctypes ended up working for me, with help from
 win32process where possible.  I'm not sure why the solutions
 involving popen variants failed; I might have missed something
 easier.  Here's the meat of my solution for the archives anyway,
 though.

 IIRC there is new module process which replaces popen with better
 functionality.

This is subprocess (included in Python 2.4). But if the child
application really writes to the console directly, and not to standard
output, I would guess that subprocess won't be able to read the output.

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Re: Feature request for Python's msi

2005-01-20 Thread Thomas Heller

 2. Append .PY to the system PATHEXT.

 This makes sense, but also may be confusing with multiple versions.

I don't see a problem with multiple versions, the 'default' version is
used when you type 'path\to\script'.  And you can use batch files to
select a specific Python version.

But I also don't see a problem changing the env var yourself: it has
only be done once.

 That way, if I install some tool that happens to have been written in
 python, I can use it on the command line as

 C:\somewhere\ foo arg arg

 , rather than as:

 C:\somewhere\ C:\Python24\Scripts\foo.py arg arg

 In your real cases, who provided foo.py?  If it was not installed with
 Python itself (ie, is a script you provided), then it may be better to add
 these scripts to a completely different directory, and ensure that directory
 is on your PATH.  I can't think of any Python supplied scripts which are so
 useful they should be on the PATH, so I suspect you would have an uphill
 battle getting that one accepted.

c:\PythonXY\Scripts is the default directory for scripts installed via
distutils.  If the ..\Scripts directory would be changed into a package,
and the '-m' Python command line switch would be implemented fully
(there's a PEP for it now), you could run the script in this way, with
the batch files helpers (py23.bat, py24.bat) I mentioned before:

py23 -m Scripts.foo arg arg

Thomas

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32