Here we go, the HelloWorld for Windows written in Ada – put the codes below to a hellowwindows.adb, then run:
gnat make -IC:\GNAT\2008\include\Win32ada -LC:\GNAT\2008\lib\Win32Ada HelloWindows
sure you need to change the include and library directory to the right one.
Compile it, run it with “hellowindows”, you will see a pop-up window as shown on right.
Here are codes:
-- 我的第一个Windows Ada程序 with Ada.Command_Line; with Ada.Unchecked_Conversion; with Interfaces.C; with System; with Win32; with Win32.WinDef; with Win32.WinMain; with Win32.WinUser; procedure HelloWindows is function CP (pch: Interfaces.C.CHAR_Array) return Win32.LPCSTR is function CSTR_To_Address is new Ada.Unchecked_Conversion(System.Address, Win32.LPCSTR); begin return CSTR_To_Address(pch(pch'FIRST)'ADDRESS); end CP; function WinMain( hInstance : Win32.Windef.HINSTANCE; hPrevInstance: Win32.Windef.HINSTANCE; lpszCmdLine : Win32.PCSTR; nCmdShow : Win32.INT) return Win32.UINT is szMessage : constant Interfaces.C.CHAR_Array := Interfaces.C.To_C( "你好,Ada世界!", True ); szTitle : constant Interfaces.C.CHAR_Array := Interfaces.C.To_C( "第一个Windows Ada程序" ); hWnd : Win32.Windef.HWND; nretVal : Interfaces.C.int; begin hWnd := Win32.Winuser.GetDesktopWindow; nRetVal := Win32.Winuser.MessageBox( hWnd, CP(szMessage), CP(szTitle), Win32.Winuser.MB_OK ); return 0; end WinMain; begin Ada.Command_Line.Set_Exit_Status( Ada.Command_Line.Exit_Status( WinMain( Win32.Winmain.Get_hInstance, Win32.Winmain.Get_hPrevInstance, Win32.Winmain.Get_lpCmdline, Win32.Winmain.Get_nCmdShow ) ) ); end HelloWindows;