[python-win32] COM server
Peter Schay
pschay@pobox.com
Mon, 3 Feb 2003 10:09:04 -0800 (PST)
Help!
I am trying to implement a python COM server to be a
custom test type for a commercial test tool. I'm not
sure how to handle in/out parameters on the server
side (I have no trouble on the client side).
For example, the doc says that the test type object
has a method with the following syntax:
HRESULT GetBitmap([in] long Status, [out, retval]
long * Value)
Another method looks like this:
HRESULT CreateScriptTemplate([in] long TestKey,
[in,out] BSTR * LocalPath, [out,retval] long * Value)
How can I correctly implement methods like these in a
COM server?
Here's what I've done so far, trying to implement
GetBitmap():
Value is supposed to be an HBITMAP of the 16x16 test
type bitmap. I used the dynamic policy for my server
and popped up some win32ui.MessageBoxes in my object.
The __init__ gets called, _dynamic_ gets called,
various properties are queried, and then GetBitmap is
called. However I'm not sure how to return the
HBITMAP. I tried this:
def GetBitmap(self, Status):
f = open("c:\icon.bmp", "r")
b = win32ui.CreateBitmap()
b.LoadBitmapFile(f)
return 1, b.GetHandle()
I've tried just returning b.GetHandle() and other
possibilities such as (0, b.GetHandle()). However the
test tool does not use my bitmap -- of course I don't
get any errors and there is no relevant log.
Maybe I've done things right and the test tool always
ignores the returned value of getbitmap; however I
suspect the problem is on my side and most likely with
my COM server since I never wrote one before.
How can Python COM possibly know the expected
interface of methods like GetBitmap() and
CreateScriptTemplate() ? Doesn't it need to know?
Can I just return tuples and expect pythoncom to
magically do the right things when there are byref
parameters?
Thanks,
Pete