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:
  1. 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

  2. Unzip it
  3. Run make in the directory you unzipped
  4. Type regsvr32 beep.dll to register the COM object on your system
  5. 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)
  6. 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.

  1. Download the source code here.
  2. Create a new project in ObjectAda
  3. Add the files BeepDll.ads and BeepDll.adb to the project (unless you are creating the EXE Local Server then use BeepExe.adb instead)
  4. Add the remaining *.adb and *.ads files to the project from the downloaded zip file (excluding BeepDll.* and BeepExe.adb)
  5. Add the file beeprc.res from the downloaded zip file
  6. Go to Projects|Settings... on the menu
  7. Go to the Search tab
  8. Select show links of type: Normal
  9. Click and select XXXX:\Program Files\Aonix\ObjectAda\WIN32ADA\BINDING\LIB
  10. Select show links of type: Linker Only
  11. Click and select XXXX:\Program Files\Aonix\ObjectAda\APILIB
  12. Go to the Build tab
  13. 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.)
  14. Go to the Link tab
  15. Select Application type DLL
  16. Build the project
  17. 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)
  18. 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