Next: , Previous: Temporary Files, Up: Microsoft Windows Topics


H.5 Mixed-Language Programming on Windows

Developing pure Ada applications on Windows is no different than on other GNAT-supported platforms. However, when developing or porting an application that contains a mix of Ada and C/C++, the choice of your Windows C/C++ development environment conditions your overall interoperability strategy.

If you use gcc or Microsoft C to compile the non-Ada part of your application, there are no Windows-specific restrictions that affect the overall interoperability with your Ada code. If you do want to use the Microsoft tools for your C++ code, you have two choices:

  1. Encapsulate your C++ code in a DLL to be linked with your Ada application. In this case, use the Microsoft or whatever environment to build the DLL and use GNAT to build your executable (see Using DLLs with GNAT).
  2. Or you can encapsulate your Ada code in a DLL to be linked with the other part of your application. In this case, use GNAT to build the DLL (see Building DLLs with GNAT Project files) and use the Microsoft or whatever environment to build your executable.

In addition to the description about C main in see Mixed Language Programming section, if the C main uses a stand-alone library it is required on x86-windows to setup the SEH context. For this the C main must looks like this:

     /* main.c */
     extern void adainit (void);
     extern void adafinal (void);
     extern void __gnat_initialize(void*);
     extern void call_to_ada (void);
     
     int main (int argc, char *argv[])
     {
       int SEH [2];
     
       /* Initialize the SEH context */
       __gnat_initialize (&SEH);
     
       adainit();
     
       /* Then call Ada services in the stand-alone library */
     
       call_to_ada();
     
       adafinal();
     }

Note that this is not needed on x86_64-windows where the Windows native SEH support is used.