Mixed-Language Programming on Windows (GNAT User’s Guide for Native Platforms)

#### 7.4.8 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:

- You can encapsulate your C++ code in a DLL to be linked with your Ada application. In this case, use the Microsoft or other environment to build the DLL and use GNAT to build your executable (Using DLLs with GNAT).
- 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 (Building DLLs with GNAT Project files) and use the Microsoft or other environment to build your executable.

In addition to the description about C `main` in 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 you need not do this on x86_64-windows where the Windows native SEH support is used.