[python-win32] How to use IExtractImage in python

Steven James steven.james at gmail.com
Fri Apr 20 21:22:05 CEST 2007


Thank your your excellent help, Mark. I have gotten everything to compile
properly, and can call IExtractImage::GetLocation and IExtractImage::Extract
from python on the necessary files. Even the exceptions on unknown file
types seem to be handled properly.

The final problem is getting the image data into python (and using it in
wxpython). The final return type is an HBITMAP, which I can see as an int in
Python using PyLong_FromVoidPtr, or as a PyHANDLE in python using
PyWinObject_FromHANDLE.

I realize that a discussion on wxpython would be outside this group's topic,
but if anyone could tell me where to start looking for a way to do this, I
would greatly appreciate it. From what I can tell, wxpython/wxwindows uses
the HBITMAP type internally to store images, and it appears to be a pointer
to a DIB in memory. If so, it may be possible to use wx.BitmapFromBuffer,
wx.BitmapFromBits, or some similar function, if I can somehow convert the
HBITMAP data (instead of the handle) to a string.

Thanks,
Steven James

On 4/19/07, Mark Hammond <mhammond at skippinet.com.au> wrote:
>
> > I have been delving in to the process of adding support for
> IExtractImage
> to
> > pythonwin. I have run makegw on the necessary files, added the resulting
> .cpp
> > and .h files to com/win32comext/shell/src, added references in shell.cpp
> and
> > setup.py, and now it seems all that is left to do is implement the
> proper
> > data types which makegw did not know how to handle. (Also, if it would
> > help anyone, I patched my makegw to run under Python 2.5 with no regex
> > or regsub modules.)
>
> Excellent - please feel free to send me the patches.  makegw is *very*
> dumb
> though.
>
> > I have a few questions about the next steps, for those who may have done
> this before:
>
> > I am left with a few lines of code in the PyIExtractImage.cpp file that
> look like this:
>
> > if (bPythonIsHappy && !PyObject_AsDWORD *( obpdwPriority, &pdwPriority
> ))
> bPythonIsHappy = FALSE;
>
> See above - makepy is dumb :)  For now, PyInt_AsLong should work fine for
> a
> DWORD.  HBITMAP should just use PyLong_FromVoidPtr (or however that is
> spelt), and a SIZE already has PyWinObject_FromSIZE.  You will just need
> to
> correct the invalid indirections created by makegw - eg, your line above
> would read as:
>
> > DWORD dwPriority;
> > if (bPythonIsHappy && !PyInt_AsLong( obpdwPriority, (long *)&dwPriority
> ))
> bPythonIsHappy = FALSE;
>
> Also, please see the existing support for IExtractIcon - this new
> interface
> should be almost identical - just one or 2 data types appear to be
> different
> between the interfaces (HICON -> HBITMAP being the most obvious one)
>
> Cheers,
>
> Mark
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20070420/c4089c57/attachment.htm 


More information about the Python-win32 mailing list