Dominik Heller wrote:
>
>>
>>> obj_2.DoSomething(“MyArgument”) # doesn’t work
>> What is the C++ signature of this method?
> This would be the declaration in the C++ class header:
>
> class CMyCommand : public CCmdTarget {
> // ...
> afx_msg void DoSomething(LPCTSTR message);
> // ...
> };
>
> with this being the dispatch macro in the corresponding cpp:
>
> DISP_FUNCTION(CMyCommand, "DoSomething", DoSomething, VT_EMPTY, VTS_BSTR)
That's odd. Is your application compiled with -DUNICODE? BSTR is
always Unicode, but LPCTSTR depends on the compiled character set. I
would expect it to be LPCWSTR. However, if it works for
"obj_2.SubObject.DoSomething", then that's not a problem.
What do you mean by "doesn't work"? Is the method missing, or do you
get trash results?
> Having GetSomeNumber as a property sounds false to me as well, it shouldn't
> be possible to set the value this COM method returns.
> It is declared/dispatched with:
>
> afx_msg long GetSomeNumber();
> DISP_FUNCTION(CMyCommand, "GetSomeNumber", GetSomeNumber, VT_I4, VTS_NONE)
Well, it's all about interpretation. A method that returns one thing
and accepts no parameters is (apparently) exposed by the Python COM
wrapper as a read-only property, and that's a reasonable interpretation.
> So if I understand you correctly, it should be possible to use all these
> methods even with a dynamic python dispatch object, as long as they're
> implemented correctly on C++ side? What could be the thing going wrong in
> the C++ code?
By "implemented correctly", I really meant "declared correctly". The
IDispatch handler in your code doesn't have a clue what the C++ function
signatures actually are. It has to trust your dispatch map. If there
is disagreement, garbage results.
> So if I'm aware that a python tuple is returned and the parameter list for
> the call is thus shorter, I can still call it on a dynamic dispatch?
That's the theory. ;) Most true COM-compliant functions return an
HRESULT, with a by-reference parameter as the output value. In that
case, the Python COM wrapper returns a tuple with those two values.
> Basically I'm trying to find out how much my life would get easier if I
> somehow generated those IDL-files, or if rather the existing C++ COM
> interface needs to be fixed.
That's a very good question. You will probably end up having to print
out what type mapping the Python COM wrappers have done. That's easier
if you have a makepy result from a type library, but I believe it's
still possible with an IDispatch. I just haven't done it in a while to
remember the recipe.
--
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32