From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,21e05550ecbdb108 X-Google-Attributes: gid103376,public From: "Jerry van Dijk" Subject: Re: Quickie question (I hope)... Date: 1998/11/13 Message-ID: <01be0f59$f07ecb60$0100007f@aptiva>#1/1 X-Deja-AN: 411616760 References: <72i7j0$sqa@sjx-ixn9.ix.netcom.com> X-Notice: should be reported to postmaster@ibm.net X-Complaints-To: postmaster@ibm.net X-Trace: 13 Nov 1998 23:04:43 GMT, 139.92.166.148 Organization: JerryWare Newsgroups: comp.lang.ada Date: 1998-11-13T00:00:00+00:00 List-Id: > How do I do an IMPORT_VALUED_PROCEDURE pragma w/GNAT? > Or is that not necessary? > > I want to import and use the NT routine GetComputerNameA > from Kernel32. I know how to link against K32, but I can't > figure out the import. I suppose you are not using the Win32 binding. In that case, remember that kernel32 is a dll, so binding to it requires the StdCall convention. Also, the Win32 API requires data of less than 128 byte to be passed by copy instead of the usual pass by reference. See my homepage for more info. Here is one of many ways to use this function: pragma C_Pass_By_Copy (128); with System; with Ada.Text_IO; with Interfaces.C; procedure Demo is package C renames Interfaces.C; use type C.size_t; function Get_Computer_Name return String is MAX_COMPUTERNAME_LENGTH : constant := 15; Size : C.size_t := MAX_COMPUTERNAME_LENGTH + 1; Buffer : C.char_array (1 .. Size + 1) := (others => C.nul); function GetComputerName (Buffer : C.char_array; Size : System.Address) return Integer; pragma Import (StdCall, GetComputerName, "GetComputerNameA"); dummy : integer; begin dummy := GetComputerName (Buffer, Size'Address); return C.To_Ada (Buffer); end Get_Computer_Name; begin Ada.Text_IO.Put_Line ("Computer name: " & Get_Computer_Name); end Demo; -- -- Jerry van Dijk | Leiden, Holland -- Team Ada | email: jdijk@acm.org -- Ada & Win32: http://stad.dsl.nl/~jvandyk