[WINTCL] tcom module and pass by pointer/reference
by Gal Aviel other posts by this author
May 31 2007 10:30AM messages near this date
[WINTCL] allege rostrum
|
[WINTCL] crazily
Hi,
I have an MS-Windows application that exposes some functionality via a
COM interface.
The problem is that some of the methods exposed by this COM interface
have several [out] parameters that are returned by pointer, i.e. the
calling environment creates/allocates them and then passes a pointer to
them when calling the COM method. The COM method then uses these
pointers to return data to the calling environment.
I know TCL does not suppose pass by reference or pointer, so it seems
I'm stuck - can't use the current COM interface I have with TCL.
In Python, the win32com.client python module works around this
limitation (Python also does not support pointers), see the following
excerpt from "Python Programming on Win32":
Is there a similar way to get this done using TCL (and tcom or other TCL
module)?
Any help would be greatly appreciated,
Thanks - Gal.
<BEGIN EXCERPT>
Just as with the C and Visual Basic languages, it's possible in COM to
pass objects by value or by reference. Passing by value means the value
is passed, and changes to the value aren't reflected in the calling
object. Passing by reference means a pointer to the value is passed, so
changes to the value are reflected in the calling object.
Python doesn't support this concept; it's not possible to pass simple
parameters by reference in Python. The common pattern is for Python to
return the values from the function.
Fortunately, parameters passed by reference tend to be avoided. The
Microsoft Office suite doesn't use them, nor do any of the other type
libraries you could reasonably assume are installed on your PC. This
makes demonstrating the problem using real code somewhat difficult, but
as an example, let's assume you need to call a function that in C looks
like:
BOOL GetSize( int *left, int *right, int *top, int *bottom);
Your C code to call this function looks like this:
int left, right, top, bottom;
BOOL ok;
ok = GetSize( &left, &right, &top, &bottom);
Or in Visual Basic, the code looks like:
Declare GetSize( ByRef left as integer, ByRef right as integer, _
ByRef top as integer, ByRef bottom as integer) as
Integer
...
ok = GetSize(left, right, top, bottom);
In Python, the code looks something like:
left, right, top, bottom = GetSize() # Exception indicates error.
Note that the output parameters have been converted to the function
result; the same style is used for PythonCOM. It's critical to note,
however, that ByRef-style parameters may be detected only when using
early-bound dispatch. If you haven't used MakePy for the type library,
PythonCOM may not detect that the parameters are indeed marked as by
reference and therefore may not work as expected.
<END EXCERPT>
|