Torbjorn Tyridal schrieb: >> But maybe I completely misunderstand you and you want to return special >> HRESULT >> values from the event method implementations in your client ??? > > Yes I think so.. It's the event handler I'm implementing... Found the > ReturnHRESULT exception after some digging, and it's probably what I'm > looking for (??)
It depends, see below. > Again it's the softUSB (DSF) stuff from microsoft. It gives you the > option to either handle all requests manually, or all by the > framework. > > If you want some requests to be handled by the framework, the (my) > eventhandler should return E_NOTIMPL. (typed a bit fast there > previously when I said E_FAIL) comtypes implemented COM servers will automatically return E_NOTIMPL for methods that are not implemented. > would raising ReturnHRESULT pose a problem for comtypes? > > ie. > def myhandler(someparam): > if someparam==i_like_it: > return my, normal, values > else: > raise ReturnHRESULT(E_NOTIMPL, "Framework, do this for me please") For implementing COM server methods in comtypes you have two possibilities (I should really write and publish the docs for that ;-), on a method by method basis. The first one is what I have called the 'low level way' in a previous post, the second one is the 'high level' way. Take this simple IDL method as an example: interface IMyInterface : ... { ... HRESULT MyMethod([in] int a, [in] int b, [out] int *pa, [out] int *pb); ... }; Low level implementation: This is very similar to what you would have to write in C or C++. The method must accept and will receive all parameters that the IDL definition specifies, and returns a HRESULT values. In addition, the method's first parameter, just after the 'self', MUST be named 'this' and will normally receive an integer specifying the address of the COM object, just like the (invisible in C++) this pointer. Normally the value of the 'this' parameter is not useful for anything and can be ignored, the purpose is just to specify the 'calling convention'. So, the low level Python method would look like this: def MyMethod(self, this, a, b, pa, pb): # low level com method implementation if not pa: return E_POINTER if not pb: return E_POINTER # ... pa[0] = outvalue_a pb[0] = outvalue_b return S_OK High level implementation: Here you implement the COM method in a way very similar to what you would do in a 'normal' Python implementation. The method does NOT receive the 'this' parameter, it does not receive pointers for [out] parameters, instead it returns them; and you have no control over the HRESULT value that is returned: def MyMethod(self, a, b): # high level com method implementation return outvalue_a, outvalue_b The ReturnHRESULT exception is unneeded for the low level impl, but it may be used in the highlevel impl if you need to return a HRESULT other then S_OK which is returned when the function returns in a normal way, and E_FAIL which is returned when an uncatched exception happens in the method. I should note that the name of the method could also be IMyInterface_MyMethod. > Throwing in another question at the end here: > from comtypes/_comobject.py: > # This code assumes that input args are always first, and output > # args are always last. Have to check with the IDL docs if this > # is always correct. > > are you still assuming that? I have atleast found one object where > that's not true: > http://msdn.microsoft.com/en-us/library/bb201518.aspx > > If you've changed it I'll stop working on my patch right now :) I see your patch is already done - great. -- Thanks, Thomas ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users