Creating COM objects with Ada
The following is an example of how to create COM objects with Ada. I will be working on putting together an article on the basics of COM and how this example works soon. This COM object was designed with DCOM in mind and with some minor configuration on the client side (either in the client code or on the client machine), these machines can be accessed remotely.
GNAT 3.12p:
- Download the source code including a make file contributed by Rob Veenker.
here.
New version available supporting multiple interfaces, BSTRs and more
Click here to download
- Unzip it
- Run make in the directory you unzipped
- Type regsvr32 beep.dll to register the COM object on your system
- run Regsvr32 Beep.dll (If you are running Win95/98 regsvr32.exe is in the Windows\System dir and on NT it is in Winnt\system32)
- Run the ComBeep sample program to test out your new COM object!
UPDATE: I have now included the files needed to create a EXE local server in addition to the DLL in process server. Take a look at the readme.txt file in the zip.
Aonix ObjectAda 7.1.2:
The COM object as coded works perfectly, but there is still a problem with OA's ability to create COM objects. If I try to allocate any memory with in the COM object or try and use To_C, the COM object breaks. To see this in action modify the BeepCom.Beep procedure to call the function Beep_Global.Message_Box("Hello","World") instead of the Win32 API MesssageBox function.
- Download the source code here.
- Create a new project in ObjectAda
- Add the files BeepDll.ads and BeepDll.adb to the project (unless you are creating the EXE Local Server then use BeepExe.adb instead)
- Add the remaining *.adb and *.ads files to the project from the downloaded zip file (excluding BeepDll.* and BeepExe.adb)
- Add the file beeprc.res from the downloaded zip file
- Go to Projects|Settings... on the menu
- Go to the Search tab
- Select show links of type: Normal
- Click and select XXXX:\Program Files\Aonix\ObjectAda\WIN32ADA\BINDING\LIB
- Select show links of type: Linker Only
- Click and select XXXX:\Program Files\Aonix\ObjectAda\APILIB
- Go to the Build tab
- Select the option Compile (locally) out-of-date files from linked libraries (I had to make a small change to the Win32 bindings in the OLEAUT32.ADS file and this will allow us to compile in the change, ie. I had to comment out the pragmas importing: RemVariant_v0_1_c_ifspec and RemVariant_v0_1_s_ifspec. They are not in the included import libs.)
- Go to the Link tab
- Select Application type DLL
- Build the project
- run Regsvr32 Beep.dll (If you are running Win95/98 regsvr32.exe is in the Windows\System dir and on NT it is in Winnt\system32)
- Run the ComBeep sample program to test out your new COM object!
UPDATE: I have now included the files needed to create a EXE local server in addition to the DLL in process server. Follow all the above until the directions ot Choose and Application type of DLL. Build the project and then run the file BeepExe -RegServer to Register the COM Object.
Contributed by: David Botton
Contributed on: February 14, 1999
Last Updated on: June 16, 1999
License: Public Domain
Back