Status update (June 30th)

Below is the status update fro June 30th.

As planned I spent the last week testing the wrapped objects on Delphi (specifically version 3) and fixing any bugs found during this process. I am happy to say that the wrapped objects work really well. After importing the type library to Delphi it is possible to call global functions, manipulate global variables (using generated ‘getter’ and ‘setter’ functions) and also it is possible to create objects and call their member functions. Class factories work as expected and I have also added a simple implementation of DllRegisterServer (DllUnregisterServer will follow later). I have added the option (turned on by default) to generate a .DEF file for the wrapped module – it is rather simple (it just lists the 4 Dll* exports), but it might be helpful for users not too familiar with Win32. There are still many rough edges that I will be ironing out, but I prefer to have something working as early as possible.
I have made sure (and I will try to keep it this way) that the wrappers build and run correctly using both MSVC (2008 ) and MinGW (5.1.3, with GCC 3.4.5) and that if the wrapped module uses plain C then the wrapper compiles in plain C mode too.
There are still some things that I will need to sort out before I move on to the implementation of IDispach, namely constants, enums, opaque pointers and most importantly constructors. I hope to be done with at least some of them before the end of the week.

Below is a list of steps to generate and compile a wrapper if you would like to see the COM module in action. I assume that the wrapped module is contained in file simple.cpp and there is a corresponding header file simple.h.

1. Create a SWIG interface description file simple.i, containing something like this:

%module simple
%{
#include "simple.h"
%}
%include "simple.h"

2. Run the following command:

swig -c++ -com simple.i

The -c++ flag can be omitted if no C++ is used in the header file. The process should generate 3 files: simple_wrap.cxx (or simple_wrap.c), simple.idl and simple.def.
3. Compile simple.idl using midl (WINE’s widl also works well, but likes to overwrite simple.h in the process;)):

midl simple.idl

This results in the creation of simple.tlb
4. Build the server DLL. In MSVC this is done with this command:

cl /LD simple.cpp simple_wrap.cxx simple.def ole32.lib uuid.lib advapi32.lib

In MinGW you can use the following command:

dllwrap --driver-name g++ -o simple.dll simple.cpp simple_wrap.cxx  -luuid -lole32 -ladvapi32 --def simple.def

In case of a plain C file the option ‘–driver-name g++’ can be omitted.
5. Register the DLL:

regsvr32 simple.dll

Currently this assumes that the type library is a separate file (in this case simple.tlb) and that it resides in the same directory as the dll.

After these steps the wrapper is ready to use. In Delphi it can be imported into a project by selecting ‘Project->Import type library’. I haven’t had a chance to test with VB (or any other language that does not require IDispatch) but I will do it as soon as I finish the work on constants/enums/constructors.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: