COM Wizard

What our tool can

Our tool will generate the frame for a InprocServer, that is a DLL. It does not support building non Inproc Servers. But that will change if you will request that.

The generated frame will be useful for early binding and late binding COM clients. That mean one will be able to make use of the static type library in languages like C, Pascal all the .NET languages but also Scripting languages like VBScript, JavaScript etc.

Tools you'll need

Our first implementation is based on genereated code for idl files. For those to compiler you'll need the midl Utility and also some tool to generate an UUID for you. You can e.g write your own tools which will just call into ...

We suggest to download the Microsoft Platform SDK oder das DDK.

What you have to do

There are few steps needed by you to make use of the tools.

Writing an IDL File

At first you have to write an IDL file

I wrote the following file for that

/ This is always good to include

import "oaidl.idl";


[object, uuid(71209AAB-7553-4aed-9EF9-0A98F837BCFB),
 helpstring("Example for using the QSS comwizard "),
 dual, oleautomation, nonextensible
]


interface IExample: IDispatch
{
	[id(1), helpstring("Get a name")] HRESULT getText(BSTR *outText);
	[id(2), helpstring("Set a name")] HRESULT setText(BSTR *newValue);
	[id(3), helpstring("Adder for numbers") ] HRESULT addThis(FLOAT a, FLOAT b, FLOAT *result);

};


// the Library, under this name will the stuff be registered
[ uuid(F9F2A61D-A293-4a82-8912-32DEA18B7B38), version(1.0),
  helpstring("Q-Software Solutions GmbH, Example for the comwizard")]
library IExampleLibrary
{
	importlib("stdole32.tlb"); // according to the docs good to have anytime
	interface IExampleInterface;

	[ uuid(45745355-F798-4678-AC62-20806143F15F)]

	coclass CoIExampleClass
	{
		 [default] interface IExample;
		 // Now we're getting serious we implement our own Interface ;-)
	};
};

The most important things are the lines with "dual, oleautomation" and the line "Iexample: IDispatch". In our this version you have to assure that you dervie from IDispatch, which is needed to make this Component accessible from Scripting Languages or languages which just support late binding.

Now you can run the midl utility over this file, like this:

midl /server none /proxy none iexample.idl
      

The midl will generated some files which we'll need later to compile our files.

Run the comwizard.exe

You know can run our tool to generate the file which is (or will be) the implementation of the COM Server

Doing that is very easy

 comwizard iexample.idl
    

This will generate a lot of code for you, but the only parts which are of interest to you are the frames for the functions.

The functions look all the same

HRESULT STDMETHODCALLTYPE getText(            IExample * This,
            BSTR *outText)
{
    char msg[512];
    snprintf(msg, sizeof(msg), "in %s", __func__);
    MessageBox(NULL, msg, "Dummy", MB_OK | MB_ICONINFORMATION);
    return S_OK;
}

It's up to you to add the real functionality to this function. You have to keep in mind that the COM model is very strict. You always have to see that the client can not mess around with the server structures and that the server can not tamper with your client structures. And it's extremly important just to use data structures supported by Ole automation. This will restrict your possibilities but it will allow every other language to use this server.

Let's see what I did to add the functionality for this example Example code