OLEGuids Package

Author: Krool. Version: 1.0.10.0. On GitHub: Kr00l/VBCCR, in the folder twinBASIC Package/OLEGuids.

A twinBASIC package that declares 25 OLE and COM interfaces and 11 structures in twinBASIC source, so that a 32-bit or 64-bit project can call or implement them without a type library.

The package is a twinBASIC implementation of OLEGuids.tlb, the type library of OLE interface and type definitions that Krool’s VBCCR and VBFLXGRD controls (VBCCRxx.OCX and VBFLXGRDxx.OCX) use. It replaces OLEGuids.tlb in projects that build 64-bit programs, and works in 32-bit projects as well. This section documents version 1.0.10.0, published under the MIT licence.

Using the package

Add the package in Project → References (Ctrl-T) → Available Packages. The interfaces and structures are then visible to the whole project. Two things can be done with an interface:

  • Call it. Declare a variable of the interface type and assign an object to it. The assignment asks the object for that interface, and a call through the variable runs the object’s method.
  • Implement it. Name it in an Implements statement in a class, and write each method. A class cannot implement an interface that has a [PreserveSig] member (see How the declarations differ from Windows).

A name can be written bare (IOleWindow, OLERECT) or qualified with the package name (OLEGuids.IOleWindow, OLEGuids.OLERECT). The eleven structures are declared in a module named OLEGuids, which is why the qualified form works for them; the module has no page of its own.

Private Function InPlaceWindow(ByVal Obj As Object) As LongPtr
    Dim w As IOleWindow = Obj
    Return w.GetWindow()
End Function

Note

The package has no declaration named IDispatch. In a project that references stdole, as every default project does, the name is stdole’s declaration. A call through it is late-bound by name, and its four methods are not reached (see IDispatch). The package’s IDispatchUnrestricted declares the four methods, and an object is assigned to a variable of that type like any other interface.

Private Function HasTypeInfo(ByVal Obj As Object) As Boolean
    Dim d As IDispatchUnrestricted = Obj
    Dim count As Long
    d.GetTypeInfoCount count
    Return count > 0
End Function

How the declarations differ from Windows

The interfaces that exist in Windows have their original interface identifiers, so an object written in another language can be called through them. The declarations differ from the C headers in these ways:

Every interface except the four VB variants is declared [OleAutomation(False)], so it is not marked as an Automation interface. The contract of each method is that of the Windows interface, which Microsoft Learn documents; each interface page links to it.

Interfaces

Types

  • OLEACCELMSG – a window message, with the layout of the Windows MSG structure
  • OLECADWORD – a counted array of DWORD values
  • OLECALPOLESTR – a counted array of Unicode string pointers
  • OLECAUUID – a counted array of GUIDs
  • OLECLSID – a class or interface identifier, with the layout of the Windows GUID structure
  • OLECONTROLINFO – the keyboard mnemonic table of a control
  • OLEDISPPARAMS – the arguments of an IDispatch.Invoke call, with the layout of the Windows DISPPARAMS structure
  • OLEINPLACEFRAMEINFO – accelerator information of an in-place frame
  • OLEPOINT – a point, with the layout of the Windows POINT structure
  • OLERECT – a rectangle, with the layout of the Windows RECT structure
  • OLESIZE – a width and a height, with the layout of the Windows SIZE structure