* Quickie question (I hope)...
@ 1998-11-13 0:00 Michael S. Jessop
1998-11-13 0:00 ` Jerry van Dijk
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Jessop @ 1998-11-13 0:00 UTC (permalink / raw)
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.
Thanks.
Mike
mikej@s-v.com and
jessop@mediaone.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Quickie question (I hope)...
1998-11-13 0:00 Quickie question (I hope) Michael S. Jessop
@ 1998-11-13 0:00 ` Jerry van Dijk
1998-11-16 0:00 ` Michael S. Jessop
0 siblings, 1 reply; 3+ messages in thread
From: Jerry van Dijk @ 1998-11-13 0:00 UTC (permalink / raw)
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Quickie question (I hope)...
1998-11-13 0:00 ` Jerry van Dijk
@ 1998-11-16 0:00 ` Michael S. Jessop
0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Jessop @ 1998-11-16 0:00 UTC (permalink / raw)
Jerry van Dijk wrote in message <01be0f59$f07ecb60$0100007f@aptiva>...
:> [snip]
:
: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.
Thank you, Jerry! No, I see win32 ".a" files, but I did
not have a win32-windef specification file. I am downloading
the win32 defs now. I am assuming that I am legally OK to
use them since I have professional editions of several MS
development packages (ie. VB, VS, ODE Tools, etc.)?
:Here is one of many ways to use this function:
Great! Just what I was looking for.
Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-11-16 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-13 0:00 Quickie question (I hope) Michael S. Jessop
1998-11-13 0:00 ` Jerry van Dijk
1998-11-16 0:00 ` Michael S. Jessop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox