comp.lang.ada
 help / color / mirror / Atom feed
* gnat and dlls
@ 1996-05-19  0:00 Eric Anthony Spear
  1996-05-19  0:00 ` Tom Griest
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Eric Anthony Spear @ 1996-05-19  0:00 UTC (permalink / raw)



Is there any way I can write procedures in Ada, compile with gnat, and
end up with a dll, which could then be accessed by a windows program,
like visual basic?

Thanks!




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

* Re: gnat and dlls
  1996-05-19  0:00 gnat and dlls Eric Anthony Spear
@ 1996-05-19  0:00 ` Tom Griest
  1996-05-20  0:00   ` Darren C Davenport
  1996-05-20  0:00 ` Wiljan Derks
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Tom Griest @ 1996-05-19  0:00 UTC (permalink / raw)
  Cc: spear


spear@wam.umd.edu (Eric Anthony Spear) writes:
>Is there any way I can write procedures in Ada, compile with gnat, and
>end up with a dll, which could then be accessed by a windows program,
>like visual basic?

There probably is, but AFAIK no one has done this so far.  To some
degree, it depends on how general you want the solution to be.  There
are some issues with respect to making the Ada runtime a separate
DLL, and how initialization is done.

This will not be a 1-day effort.
If you are really interested in doing this, get in touch and I can
give you some pointers, if you will share the results with others.


-Tom
LabTek Corp.




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

* Re: gnat and dlls
  1996-05-19  0:00 gnat and dlls Eric Anthony Spear
  1996-05-19  0:00 ` Tom Griest
  1996-05-20  0:00 ` Wiljan Derks
@ 1996-05-20  0:00 ` John Howard
  1996-05-21  0:00 ` Doug Warner
  3 siblings, 0 replies; 7+ messages in thread
From: John Howard @ 1996-05-20  0:00 UTC (permalink / raw)



On 19 May 1996, Eric Anthony Spear wrote:
> Is there any way I can write procedures in Ada, compile with gnat, and
> end up with a dll, which could then be accessed by a windows program,
> like visual basic?

Not by only using the current GNAT system.  However, GNAT can create the 
necessary object code of DLL exported subprograms and objects (variables, 
etc.).  But a DLL is constructed differently than an executable.  And the 
linker process must be informed (traditionally via an "import library") 
of the names and locations of entities that were marked as exported.  
Traditionally, the key component in creating a DLL is the DEF file.  A 
DEF file specifies that you want to create a DLL instead of an 
executable, and defines all the exported entities and how the data 
segments are assigned.

By default, the GNAT system automatically handles the linker process.  
Consequently GNAT makes building a program look a little simpler because 
the compile-and-link steps appear to be integrated.  The traditional 
route is for a programmer to create a Make file to control every detail 
of compiling and linking for a project.  GNAT allows us to use either the 
integrated route or a traditional route.  The glitch is that GNAT 
currently lacks integrated support for DLL construction and "import 
library" linkage.  Therefore take a traditional route for DLL's with 
GNAT.

Dynamic link library facts:
A DLL is not an executable.  A DLL lacks a "main() function" and a 
stack.  A DLL uses the same stack as the application.  The purpose of a 
DLL is to provide code and/or resources that can be used by more than one 
process.  In general, subprograms that could reside in an application can 
be placed into a DLL.

Both 16-bit DLL's and 32-bit DLL's exist.  16-bit DLL's are more 
difficult to handle when the Data Segment does not equal the Stack 
Segment.  For 32-bit DLL's, the Data Segment always equals the Stack 
Segment.  DLL's can work in various operating systems including IBM OS/2, 
MS Windows, and DOS.

------------------------------------------------------------------------
-- John Howard <jhoward@sky.net>                       -- Team Christ --
--   New American Standard Bible  (Psalm 22:30-31)                    --
--     Posterity will serve Him;                                      --
--     It will be told of the Lord to the coming generation.          --
--     They will come and will declare His righteousness              --
--     To a people who will be born, that He has performed it.        --
------------------------------------------------------------------------




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

* Re: gnat and dlls
  1996-05-19  0:00 ` Tom Griest
@ 1996-05-20  0:00   ` Darren C Davenport
  0 siblings, 0 replies; 7+ messages in thread
From: Darren C Davenport @ 1996-05-20  0:00 UTC (permalink / raw)



Cygnus has made some tools to make dll's with gcc(++). Could those be adapted
to use with gnat?

Darren





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

* Re: gnat and dlls
  1996-05-19  0:00 gnat and dlls Eric Anthony Spear
  1996-05-19  0:00 ` Tom Griest
@ 1996-05-20  0:00 ` Wiljan Derks
  1996-05-22  0:00   ` gnat and dlls: ObjectAda Dave Wood
  1996-05-20  0:00 ` gnat and dlls John Howard
  1996-05-21  0:00 ` Doug Warner
  3 siblings, 1 reply; 7+ messages in thread
From: Wiljan Derks @ 1996-05-20  0:00 UTC (permalink / raw)



Eric Anthony Spear wrote:
> 
> Is there any way I can write procedures in Ada, compile with gnat, and
> end up with a dll, which could then be accessed by a windows program,
> like visual basic?
> 

I wanted the same thing and I actually managed to do this. Finally I had a piece
of ada code (with tasking stuff inside) and I could call procedure in it from
visual basic.
I encountered several problem however:
  - The first think I tried was using the dlltool from cygnus.
    I run into trouble becuase you must also use the cygnus
    linker to link the dll. Trouble with that is that it is
    not able to link to MS libraries as the ld from labtek.
    so finally it meant it was not usable.
    The ld from labtek can also not link a dll.
    For that reason I switched to the MS linker. You can setup
    gnat on NT so that it uses that linker.
  - Finally I made an ada package with a task inside.
    To link it I first made a program that calls a procedure from
    that package using the ms linker. This gives you an .gp file
    that contains a link script for that program.
    Then you can use gnatbind to generate a c file that just does
    an initialisation. (use gnatbind with -n option).
    You can the edit the .gp file and remove the obj for the
    main program you originally had and add the object for the
    generated c bind code. That code contains an adainit procedure
    that initializes the ada environment.
    The you can link using the addapted .gp file and use the same
    options and arguments that are normally used when linking with
    the ms linker. (just try -v options and you will see them when
    you normally link a program.) Beside those you must also specify the
    -dll option and the -def:dll.def option.
    In my case the dll.def file contained:

LIBRARY
	dll
EXPORTS 
	_addint@8
	_dll_entry@12
	_trydll_init@0

     The MS linker then generates the the dll in one step. You can find the
     ms linker on ftp.microsoft.com somewhere. It is a bugfix for an old linker
     and it actually works. You will not get decent error messages from it when
     there is an error however bcuase it is incomplete. Up to now I had not
     change to try it with msvc.

     Using NT 4.0 is easy because it allows you to peek inside .dll and .exe
     files using the explorer right mouse button. It will show you the
     entry points that are in there.


The code that I use to try this is attached at the end of this
message. I just put in a task that increments a variable periodically.
This allows you to show all features from the visual basic program.
In visual basic I declare the functions as:

Private Declare Function addint Lib "\users\wiljan\ada\trydll\dll" Alias "_addint@8" (ByVal a As 
Long, ByVal b As Long) As Long
Private Declare Sub initdll Lib "\users\wiljan\ada\trydll\dll" Alias "_trydll_init@0" ()

I had to put a few extra procedure in my package it to make the
linker happy:
   - Routine main and main_priotity. This are required when you want to link ada code.
   - dll_entry. I linked this in the dll as the entry point for the dll.
     (more on that one later)
   - two routine which I called later from visual basic: addint and trydll_init
I originally wanted to make a dll which initialises itself automatically.
This is done on NT becuase the entry point is called when a process attaches to a
dll. In that case b=1. This however did not work. Probably some deadlock arizes
becuase of the tasking inside the ada code. It looks like:
   - Because of the dll load the initialisation creates a task and waits on it.
   - Probably the taks needs to wait for the dll initialisation before it can
     be run, hence the deadlock that occurs in this situation.
     everything works fine when not using tasking in the package.
I know it is a big hack, but when first calling the init function once from
visual basic everything worked fine.
A last problem that I had was when exiting the visual basic program.
It simply does not apear form the system (the form did). This is becuase of the
tasking still some threads are running which causes the program not to exit.
This is a general problem when using ada programs with tasking. I think it is
best to simply call exitprocess (i do not know if that is the right name) directly.

Lets hope Labtek addapt the linker a bit so that things will get much simpler
in the near future. For visual basic it is a must that you link packages into
a dll, but also for the run time it whould be nice to be able to put stuff
into a dll somehow. To make a general solution for this is not that trival however.

Wiljan


package trydll is

function addint(a,b:integer) return integer;
function dll_entry(a,b,c:integer) return integer;
procedure trydll_init;

pragma convention(stdcall,addint);
pragma convention(stdcall,dll_entry);
pragma convention(stdcall,trydll_init);
pragma export(C,addint,"addint");
pragma export(C,dll_entry,"dll_entry");
pragma export(C,trydll_init,"trydll_init");

end trydll;
package body trydll is

glob:integer:=0;

function addint(a,b:integer) return integer is
begin
   return a+b+glob;
end addint;

procedure adainit;
pragma import(C,adainit,"adainit");

procedure trydll_init is
begin
   adainit;
end trydll_init;

adainit_done:boolean:=false;

function dll_entry(a,b,c:integer) return integer is
begin
   if b=1 and not adainit_done then
--      adainit;
      adainit_done:=true;
   end if;
   return 1;
end dll_entry;

task increment;
task body increment is
begin
   loop
      delay 1.0;
      glob:=glob+1;
   end loop;
end increment;

procedure main;
pragma export(C,main,"main");
procedure main is
begin
   null;
end main;

function main_priority return integer;
pragma export(C,main_priority,"__main_priority");
function main_priority return integer is
begin
   return -1;
end main_priority;

end trydll;




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

* Re: gnat and dlls
  1996-05-19  0:00 gnat and dlls Eric Anthony Spear
                   ` (2 preceding siblings ...)
  1996-05-20  0:00 ` gnat and dlls John Howard
@ 1996-05-21  0:00 ` Doug Warner
  3 siblings, 0 replies; 7+ messages in thread
From: Doug Warner @ 1996-05-21  0:00 UTC (permalink / raw)



>>>>> "Tom" == Tom Griest <griest-tom@cs.yale.edu> writes:
>>>>> "Eric" == Eric Anthony Spear <spear@wam.umd.edu> writes:

    Eric> Is there any way I can write procedures in Ada, compile with
    Eric> gnat, and end up with a dll, which could then be accessed by a
    Eric> windows program, like visual basic?

    Tom> There probably is, but AFAIK no one has done this so far.  To
    Tom> some degree, it depends on how general you want the solution
    Tom> to be.  There are some issues with respect to making the Ada
    Tom> runtime a separate DLL, and how initialization is done.

I don't know anything about windows & dlls, but it was pretty easy to
create a `hello, world' shared library for OSF/1 on an alpha.  It
looked like it wouldn't take too much work to automate the process,
but I don't know enough about gnat.

Just my $0.005,

Doug Warner
-- 
"Friends are God's apology for relatives" --- Hugh Kingsmill




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

* Re: gnat and dlls: ObjectAda
  1996-05-20  0:00 ` Wiljan Derks
@ 1996-05-22  0:00   ` Dave Wood
  0 siblings, 0 replies; 7+ messages in thread
From: Dave Wood @ 1996-05-22  0:00 UTC (permalink / raw)



Wiljan Derks wrote:
> 
> Eric Anthony Spear wrote:
> >
> > Is there any way I can write procedures in Ada, compile with gnat, and
> > end up with a dll, which could then be accessed by a windows program,
> > like visual basic?
> >
> 
> I wanted the same thing and I actually managed to do this. Finally I had a piece
> of ada code (with tasking stuff inside) and I could call procedure in it from
> visual basic.
> I encountered several problem however:

[much deleted]

Another alternative for those too faint of heart for this
approach is to wait a couple of months for ObjectAda for
Windows, which has a pretty simple and clean DLL import
and export capability.  Granted, the product won't be
free, but you'll have more time to spend with your kids.

Of course, I'm biased, but at least my opinion is free.

-- Dave Wood
-- Windows Product Manager
-- Thomson Software Products (for the time being)
-- Home of $99 Ada for Windows
-- http://www.thomsoft.com
-- ObjectAda for Windows timeline:
--     Ada 95 validatable:  Tri-Ada 1995 (done)
--     Registered validation:  December 18, 1995 (done)
--     Alpha test:  December 31, 1995 (done)
--     Beta 1 test:  February 29, 1996 (done)
--     Beta 2 test:  May 31, 1996
--     Shipping:  Summer, 1996




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

end of thread, other threads:[~1996-05-22  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-19  0:00 gnat and dlls Eric Anthony Spear
1996-05-19  0:00 ` Tom Griest
1996-05-20  0:00   ` Darren C Davenport
1996-05-20  0:00 ` Wiljan Derks
1996-05-22  0:00   ` gnat and dlls: ObjectAda Dave Wood
1996-05-20  0:00 ` gnat and dlls John Howard
1996-05-21  0:00 ` Doug Warner

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