Archive for the ‘Ada’ Category
-
Hello, Win32 API(Ada) World!
Posted on 6月 30th, 2012 by cx20
Win32 API(Ada)
Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
以下は Ada による Win32 API の呼出し例である。ソースコード
with Interfaces; use Interfaces; with Interfaces.C; use Interfaces.C; with System; use System; with Ada.Unchecked_Conversion; procedure Hello is function LoadLibrary (lpFileName : char_array) return Unsigned_32; pragma Import (Stdcall, LoadLibrary, "LoadLibrary", "_LoadLibraryA@4"); function GetProcAddress (hModule : Unsigned_32; lpProcName : char_array) return Address; pragma Import (Stdcall, GetProcAddress, "GetProcAddress", "_GetProcAddress@8"); type MessageBox is access function ( hWnd : Address; lpText : char_array; lpCaption : char_array; uType : Unsigned_16 ) return Integer_16; pragma Convention (Stdcall, MessageBox); function To_MessageBox is new Ada.Unchecked_Conversion (Address, MessageBox); Result : Integer_16; Library : Unsigned_32; Pointer : Address; begin Library := LoadLibrary (To_C ("user32.dll")); Pointer := GetProcAddress (Library, To_C ("MessageBoxA")); Result := To_MessageBox (Pointer) ( Null_Address, To_C ("Hello, Win32 API(Ada) World!"), To_C ("Hello, World!"), 0 ); end Hello;
コンパイル方法(GNAT)
C:¥> gnatmake hello.adb
実行結果
--------------------------- Hello, World! --------------------------- Hello, Win32 API(Ada) World! --------------------------- OK ---------------------------
-
Hello, Ada World!
Posted on 12月 30th, 2011 by cx20
Ada
Ada は米国国防総省の音頭で開発が進められたプログラミング言語である。名前の由来は世界初のプログラマと言われる Ada さんから。
構文は Pascal に似ており、また、Oracle の PL/SQL は Ada の影響を受けていると言われている。
ソースコード
with Ada.Text_Io; use Ada.Text_Io; procedure Hello is begin Put_Line ("Hello, Ada World!"); end Hello;
コンパイル方法(GNAT)
$ gnatmake hello.adb
実行結果
Hello, Ada World!