diff --git a/com/win32com/HTML/COM_Records.html b/com/win32com/HTML/COM_Records.html new file mode 100644 index 0000000000..489bb91b5a --- /dev/null +++ b/com/win32com/HTML/COM_Records.html @@ -0,0 +1,382 @@ + + +COM Record Support + + + + + + + + +
+
+
+
+
+
+
+
+

COM Record support in pywin32

+

The pywin32 package provides COM Record support for late-bound and early-bound objects. In both cases it is required that the Type Library which defines the COM Record has been registered in Windows.

+

Late-bound objects

+

For late-bound objects, were makepy-support is not available, it is possible to create a particular COM Record if the following is known:

+
    +
  • GUID of the Type Library were the Record is defined
  • +
  • Major version of the registered Type Library
  • +
  • Minor version of the registered Type Library
  • +
  • LCID of the registered Type Library
  • +
  • GUID of the COM Record in this Type Library
  • +
+

An instance of the COM Record is created with pythoncom.GetRecordFromGuids, e.g.:

+
import pythoncom
+
+PyCOMTestLib_GUID = '{6bcdcb60-5605-11d0-ae5f-cadd4c000000}'
+MAJVER = 1
+MINVER = 1
+LCID = 0
+TestStruct1_GUID = '{7a4ce6a7-7959-4e85-a3c0-b41442ff0f67}'
+
+record1 = pythoncom.GetRecordFromGuids(PyCOMTestLib_GUID, MAJVER, MINVER, LCID, TestStruct1_GUID)
+
+

The Python type of the returned COM Record instance is:

+
>>> type(record1)
+    <class 'com_record'>
+
+

which is a generic type that is returned for all COM Records, i.e. COM Records with different GUIDs nevertheless all have the same Python type pythoncom.com_record.

+

Instances of <class 'com_record'> can be used as method parameters and are returned by COM methods that return a COM Record. However, it is not possible to differentiate the COM Record Types, i.e. COM Records of different GUID at runtime.

+

Early-bound objects

+

The availability of makepy-support does in its basic form offer the convenience function win32com.client.Record to create COM Record instances using the COM Record name from the Type Library and an interface object of the same Type Library:

+
import win32com.client
+
+com_test = win32com.client.Dispatch("PyCOMTest.PyCOMTest")
+
+record1 = win32com.client.Record('TestStruct1' ,com_test)
+
+

Still the Python type of the returned COM Record instance is:

+
>>> type(record1)
+    <class 'com_record'>
+
+

i.e. the generic base type of all COM Records.

+

Defining subclasses of pythoncom.com_record +

+

It is possible to create subclasses of the base pythoncom.com_record type and register such a subclass for a particular COM Record type. As a prerequisite, it is mandatory for the subclass to define the following class attributes:

+
    +
  • TLBID : The GUID of the containing TypeLibrary as a string
  • +
  • MJVER : The major version number of the TypeLibrary as an integer
  • +
  • MNVER : The minor version number of the TypeLibrary as an integer
  • +
  • LCID : The LCID of the TypeLibrary as an integer
  • +
  • GUID : The GUID of the COM Record as a string
  • +
+

with GUID strings in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} notation, e.g.:

+
import pythoncom
+
+class TestStruct1(pythoncom.com_record):
+  TLBID = '{6bcdcb60-5605-11d0-ae5f-cadd4c000000}'
+  MJVER = 1
+  MNVER = 1
+  LCID = 0
+  GUID = '{7a4ce6a7-7959-4e85-a3c0-b41442ff0f67}'
+
+

Before this subclass can be used to create TestStruct1 instances, it has to be registered with win32com.client.register_record_class, e.g.:

+
from win32com.client import register_record_class
+
+register_record_class(TestStruct1)
+
+

With such a class, registered for a particular COM Record type, it is possible to identify the COM Record type at runtime:

+
>>> record1 = TestStruct1()
+
+>>> type(record1)
+    <class 'main.TestStruct1'>
+
+

Also COM methods that return a COM Record type for which a Python class was registered as described above, will return values of the proper Python class type, e.g.:

+
>>> # Given the following definition in the Type Library IDL-file:
+>>> # HRESULT GetStruct([out, retval]TestStruct1 *ret);
+
+>>> retval = GetStruct()
+
+>>> type(retval)
+    <class 'main.TestStruct1'>
+
+

COM methods that return a COM Record type for which no Python class was registered will continue to return values of the generic type pythoncom.com_record, e.g.:

+
>>> # Given the following definition in the Type Library IDL-file:
+>>> # HRESULT GetOtherStruct([out, retval]AnotherStruct *ret);
+
+>>> retval = GetOtherStruct()
+
+>>> type(retval)
+    <class 'com_record'>
+
+
+
+
+
+
+
+
+
+ + diff --git a/com/win32com/HTML/GeneratedSupport.html b/com/win32com/HTML/GeneratedSupport.html index 9cbb548bca..636abb390f 100644 --- a/com/win32com/HTML/GeneratedSupport.html +++ b/com/win32com/HTML/GeneratedSupport.html @@ -1,6 +1,6 @@ - + Generated Python COM Support diff --git a/com/win32com/HTML/PythonCOM.html b/com/win32com/HTML/PythonCOM.html index ed48a897e0..60102e8423 100644 --- a/com/win32com/HTML/PythonCOM.html +++ b/com/win32com/HTML/PythonCOM.html @@ -1,6 +1,6 @@ - + Untitled diff --git a/com/win32com/HTML/QuickStartClientCom.html b/com/win32com/HTML/QuickStartClientCom.html index d2b18787a9..a416c3d1d8 100644 --- a/com/win32com/HTML/QuickStartClientCom.html +++ b/com/win32com/HTML/QuickStartClientCom.html @@ -1,6 +1,6 @@ - + Quick Start to Client side COM and Python diff --git a/com/win32com/HTML/QuickStartServerCom.html b/com/win32com/HTML/QuickStartServerCom.html index be2d862256..bfb6fbaba6 100644 --- a/com/win32com/HTML/QuickStartServerCom.html +++ b/com/win32com/HTML/QuickStartServerCom.html @@ -1,6 +1,6 @@ - + Quick Start to Server Side COM and Python @@ -39,7 +39,7 @@

Implement a stand-alone Python class with your functionality

This is obviously a very simple server. In particular, custom error handling would be needed for a production class server. In addition, there are some contrived properties just for demonstration purposes.

Make Unicode concessions

-

At this stage, Python and Unicode don’t really work well together. All strings which come from COM will actually be Unicode objects rather than string objects.

+

At this stage, Python and Unicode don't really work well together. All strings which come from COM will actually be Unicode objects rather than string objects.

To make this code work in a COM environment, the last line of the "Hello" method must become:

@@ -85,7 +85,7 @@

Annotate the class with win32com specific attributes

_public_attrs_ = ['softspace', 'noCalls']

_readonly_attrs_ = ['noCalls']

def __init__(self):

-

[Same from here…]

+

[Same from here...]

Registering and assigning a CLSID for the object

@@ -179,7 +179,7 @@

Exception Handling

Default Policy attributes

The default policy object has a few special attributes that define who the object is exposed to COM. The example above shows the _public_methods attribute, but this section describes all such attributes in detail.

_public_methods_
-

Required list of strings, containing the names of all methods to be exposed to COM. It is possible this will be enhanced in the future (eg, possibly '*' will be recognised to say all methods, or some other ideas…)

+

Required list of strings, containing the names of all methods to be exposed to COM. It is possible this will be enhanced in the future (eg, possibly '*' will be recognised to say all methods, or some other ideas...)

_public_attrs_

Optional list of strings containing all attribute names to be exposed, both for reading and writing. The attribute names must be valid instance variables.

_readonly_attrs_
diff --git a/com/win32com/HTML/docindex.html b/com/win32com/HTML/docindex.html index fff74de826..9a82cb6409 100644 --- a/com/win32com/HTML/docindex.html +++ b/com/win32com/HTML/docindex.html @@ -1,6 +1,6 @@ - + win32com Documentation Index @@ -14,9 +14,10 @@

PythonCOM Documentation Index

A Quick Start to Server Side COM

Information on generated Python files (ie, what makepy generates)

An advanced VARIANT object which can give more control over parameter types

+

COM Record Support

A brief description of the win32com package structure

Python COM Implementation documentation

-

Misc stuff I don’t know where to put anywhere else

+

Misc stuff I don't know where to put anywhere else

ActiveX Scripting

ActiveX Scripting Demos

diff --git a/com/win32com/HTML/index.html b/com/win32com/HTML/index.html index 2ab0176a73..727171068f 100644 --- a/com/win32com/HTML/index.html +++ b/com/win32com/HTML/index.html @@ -1,6 +1,6 @@ - + win32com diff --git a/com/win32com/HTML/misc.html b/com/win32com/HTML/misc.html index 4374d221c8..ce010d8a9c 100644 --- a/com/win32com/HTML/misc.html +++ b/com/win32com/HTML/misc.html @@ -1,6 +1,6 @@ - + Misc win32com Stuff @@ -9,7 +9,7 @@ -

Misc stuff I don’t know where to put anywhere else

+

Misc stuff I don't know where to put anywhere else

Client Side Dispatch

Using win32com.client.Dispatch automatically invokes all the win32com client side "smarts", including automatic usage of generated .py files etc.

If you wish to avoid that, and use truly "dynamic" objects (ie, there is generated .py support available, but you wish to avoid it), you can use win32com.client.dynamic.Dispatch

diff --git a/com/win32com/HTML/package.html b/com/win32com/HTML/package.html index e98f08757f..a7a7a7f5f4 100644 --- a/com/win32com/HTML/package.html +++ b/com/win32com/HTML/package.html @@ -1,6 +1,6 @@ - + The win32com package @@ -32,6 +32,6 @@

The win32com package

 

The pythoncom module

The pythoncom module is the underlying C++ support for all COM related objects. In general, Python programmers will not use this module directly, but use win32com helper classes and functions.

-

This module exposes a C++ like interface to COM - there are objects implemented in pythoncom that have methods "QueryInterface()", "Invoke()", just like the C++ API. If you are using COM in C++, you would not call a method directly, you would use pObject->Invoke( …, MethodId, argArray…). Similarly, if you are using pythoncom directly, you must also use the Invoke method to call an object's exposed method.

+

This module exposes a C++ like interface to COM - there are objects implemented in pythoncom that have methods "QueryInterface()", "Invoke()", just like the C++ API. If you are using COM in C++, you would not call a method directly, you would use pObject->Invoke( ..., MethodId, argArray...). Similarly, if you are using pythoncom directly, you must also use the Invoke method to call an object's exposed method.

There are some Python wrappers for hiding this raw interface, meaning you should almost never need to use the pythoncom module directly. These helpers translate a "natural" looking interface (eg, obj.SomeMethod()) into the underlying Invoke call.