COM for DLL

HOW TO TURN A DLL INTO A COM OBJECT

Providing a generic interface between a COM client and a DLL host, acting as a COM object

This module aimed at software developers who need to interface an application to
a COM client such as VBscript but want to avoid the toil of writing a COM server from scratch.

COMforDLL gives you great flexibility, supporting function calls with 0 to 8 parameters,
( VBscript doesnt seem to mind even more). Up to 8 callback functions each with 4 parameters.
All parameters are variants. You can attatch any number of DLLs and their functions, with or
without callbacks.

In this version I have not implemented rich textual error reporting.

The distributables are COMforDLL.dll (24k) and COMforDLL.TLB (4k)

However, the full COMforDLL PB source code is also provided, which you can incorporate into an 
application and adapt to your own needs. To make your own independent COM objects, you will
need the Platform SDK for Windows Server 2003. And the Visual C++ compiler to run MIDL. 
Both are free downloads but huge! A sledge hammer to crack a nut.

Much of the information used to develop this code came from a series of 5 excellent tutorials 
by Jeff Glatt 'COM in plain C' which you will find on 'The Code Project' website. I would 
also like to thank Jos Roca (IT-Berater) and Bob Zale (PowerBasic Inc) for technical advice
and comment during development.


To use this module you need to understand the following:
  Creating DLLs
  Variants
  Callbacks, events
  Pointers
  The general concepts of COM objects and ActiveX.


To make use of the source code you need to know, additionally about the following:

  Power Basic  PBwin v7.0 or v8.0
  Indirection
  Virtual tables 
  IUnknown Interface
  IDispatch Interface
  GUIDgen
  MIDL IDL & TLBs

Since there are 3 modules interacting with each other: the Client App, COMforDLL and the host DLL,
debugging can be quite tricky. I suggest the best way is to use  MSGBOXes to give you data at each
stage you need to test, and wherever possible only change one thing at a time. Use the examples
provided and progressively "morph" them into your application.

Charles Pegge
July 2006

charles@pegge.net
www.pegge.net