comp.lang.ada
 help / color / mirror / Atom feed
* HELP: DLL's, parameter passing problem
@ 1999-09-27  0:00 Roger Pearse
  1999-09-28  0:00 ` John Walker
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Pearse @ 1999-09-27  0:00 UTC (permalink / raw)


I'd be grateful for a bit of help.  I'm trying to do a DLL in
Aonix ObjectAda 7.1.  I've adapted the supplied example,
and I've run into difficulties when trying
to pass and return a parameter (any parameter).  The code
runs, but the value returned seems to be random.

Can anyone tell me what I'm doing wrong?  Also, can I do
IN OUT parameters - I'd like to pass strings.

TIA

Roger Pearse

-----------USEDLL.EXE (console program)----------------
--Calling the DLL
with ada.text_io;
use ada.text_io;
with ada.integer_text_io;
use ada.integer_text_io;

procedure UseDLL is
 function DLLProc(j : integer) return integer ;
 pragma Import(DLL,DLLProc,"DLLProc");
 v,w : integer;
begin
   v := 1;
   w := 1;
   w := DLLProc(v);
   put(w);
end;
----------------------------DLL.DLL----------------

--Creating the DLL

package P is
   function DLLProc(j : integer) return integer ;
   pragma Export(DLL,DLLProc,"DLLProc");
end;
package body P is
   function DLLProc(j : integer) return integer is
       i : integer;
   begin
       i := j + 1;
       return i;
   end DLLProc;
end P;
with P;
procedure DLL is
begin
  null; -- perform any initializations here
end;

--------------------Code ends---------------------






^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: HELP: DLL's, parameter passing problem
  1999-09-27  0:00 HELP: DLL's, parameter passing problem Roger Pearse
@ 1999-09-28  0:00 ` John Walker
  0 siblings, 0 replies; 2+ messages in thread
From: John Walker @ 1999-09-28  0:00 UTC (permalink / raw)


In article <938430099.1211.0.nnrp-13.c2deb6db@news.demon.co.uk>, Roger
Pearse <rpearse@spamtrap.chieftainsys.demon.co.uk> writes
>I'd be grateful for a bit of help.  I'm trying to do a DLL in
>Aonix ObjectAda 7.1.  I've adapted the supplied example,
>and I've run into difficulties when trying
>to pass and return a parameter (any parameter).  The code
>runs, but the value returned seems to be random.
>
>Can anyone tell me what I'm doing wrong?  Also, can I do
>IN OUT parameters - I'd like to pass strings.
>
>TIA
>
>Roger Pearse

Your code worked for me.  I am using OA 7.1.2 and NT 4.0.

You can use other parameter types but be aware that convention DLL
implies DLL_cdecl.  That brings into play the recommendations in LRM B.3
(63-75) such that a string is passed as the address of the first
character and housekeeping information is lost.  Within the called
subprogram the string is seen as maximum length, witness the following
code.

----------------------------DLL.DLL----------------

--Creating the DLL

package P is
   function GetArgument (I : Integer) return Integer;
   pragma Export (DLL, GetArgument);
   function DLLProc (S : String) return Integer;
   pragma Export (DLL, DLLProc);
end;
with Ada.Text_IO;
package body P is
   function GetArgument (I : Integer) return Integer is
   begin
      return I;
   end GetArgument;
   function DLLProc (S : String) return Integer is
   begin
      Ada.Text_IO.Put_Line (S (1 .. 5));
      Ada.Text_IO.Put_Line (S (1 .. 9));
      return S'Length;
   end DLLProc;
end P;
with P;
procedure DLL is
begin
  null; -- perform any initializations here
end;

-----------USEDLL.EXE (console program)----------------
--Calling the DLL
package P is
   function GetArgument (S : String) return Integer;
   pragma Import (DLL, GetArgument);
   function DLLProc (S : String) return Integer;
   pragma Import (DLL, DLLProc);
end;

with Ada.Text_IO;
with System, Unchecked_Conversion;
with P;
procedure UseDLL is
   S : String (1 .. 9) := "123456789";
   function To_Integer is
      new Unchecked_Conversion (System.Address, Integer);
begin
   Ada.Text_IO.Put_Line (Integer'Image (
                            To_Integer(S(S'First)'Address)));
   Ada.Text_IO.Put_Line (Integer'Image (P.GetArgument (S (1 .. 5))));
   Ada.Text_IO.Put_Line ("P.DLLProc =>" &
                         Integer'Image (P.DLLProc (S)));
end;



-- 
John Walker
Email: john@jswalker.demon.co.uk
Web:   http://www.jswalker.demon.co.uk/
Tel:   +44 (0) 118 9403749




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-09-28  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-27  0:00 HELP: DLL's, parameter passing problem Roger Pearse
1999-09-28  0:00 ` John Walker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox