{"id":164,"date":"2009-03-30T16:52:37","date_gmt":"2009-03-31T00:52:37","guid":{"rendered":"http:\/\/xiehang.com\/blog\/?p=164"},"modified":"2009-03-30T20:07:35","modified_gmt":"2009-03-31T04:07:35","slug":"my-first-windows-ada-program","status":"publish","type":"post","link":"https:\/\/xiehang.com\/blog\/2009\/03\/30\/my-first-windows-ada-program\/","title":{"rendered":"My first Windows Ada program"},"content":{"rendered":"

Here we go, the HelloWorld for Windows written in Ada – put the codes below to a hellowwindows.adb, then run:<\/p>\n

gnat make -IC:\\GNAT\\2008\\include\\Win32ada -LC:\\GNAT\\2008\\lib\\Win32Ada HelloWindows<\/code><\/p>\n

\"HelloWindows\"<\/p>\n

sure you need to change the include and library directory to the right one.<\/p>\n

Compile it, run it with “hellowindows”, you will see a pop-up window as shown on right.<\/p>\n

Here are codes:<\/p>\n

\r\n-- \u6211\u7684\u7b2c\u4e00\u4e2aWindows Ada\u7a0b\u5e8f\r\nwith Ada.Command_Line;\r\nwith Ada.Unchecked_Conversion;\r\nwith Interfaces.C;\r\nwith System;\r\nwith Win32;\r\nwith Win32.WinDef;\r\nwith Win32.WinMain;\r\nwith Win32.WinUser;\r\n\r\nprocedure HelloWindows is\r\n\r\n    function CP (pch: Interfaces.C.CHAR_Array) return Win32.LPCSTR is\r\n        function CSTR_To_Address is new Ada.Unchecked_Conversion(System.Address, Win32.LPCSTR);\r\n    begin\r\n        return CSTR_To_Address(pch(pch'FIRST)'ADDRESS);\r\n    end CP;\r\n\r\n    function WinMain( hInstance    : Win32.Windef.HINSTANCE;\r\n\t              hPrevInstance: Win32.Windef.HINSTANCE;\r\n\t              lpszCmdLine  : Win32.PCSTR;\r\n\t              nCmdShow     : Win32.INT) return Win32.UINT is\r\n\r\n\r\n        szMessage : constant Interfaces.C.CHAR_Array := Interfaces.C.To_C( \"\u4f60\u597d\uff0cAda\u4e16\u754c\uff01\", True );\r\n        szTitle   : constant Interfaces.C.CHAR_Array := Interfaces.C.To_C( \"\u7b2c\u4e00\u4e2aWindows Ada\u7a0b\u5e8f\" );\r\n\r\n        hWnd : Win32.Windef.HWND;\r\n        nretVal : Interfaces.C.int;\r\n    begin\r\n        hWnd := Win32.Winuser.GetDesktopWindow;\r\n        nRetVal := Win32.Winuser.MessageBox( hWnd, CP(szMessage), CP(szTitle), Win32.Winuser.MB_OK );\r\n        return 0;\r\n    end WinMain;\r\n\r\nbegin\r\n    Ada.Command_Line.Set_Exit_Status(\r\n        Ada.Command_Line.Exit_Status(\r\n            WinMain( Win32.Winmain.Get_hInstance,\r\n                     Win32.Winmain.Get_hPrevInstance,\r\n                     Win32.Winmain.Get_lpCmdline,\r\n                     Win32.Winmain.Get_nCmdShow )\r\n        )\r\n    );\r\n\r\nend HelloWindows;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

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. […]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts\/164"}],"collection":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":12,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":170,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts\/164\/revisions\/170"}],"wp:attachment":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}