comp.lang.ada
 help / color / mirror / Atom feed
* Application Crashes when linked with DLL
@ 2016-07-12 19:50 Aurele
  2016-07-12 23:08 ` rieachus
  0 siblings, 1 reply; 4+ messages in thread
From: Aurele @ 2016-07-12 19:50 UTC (permalink / raw)


Hi o/, I'm working with Gautier and we stumbled on an interesting program behavior and thought of sharing it with you for comments. We are using the latest version (2016) of Adacore GNAT programming studio. Here is the problem:  

Create a dynamic link library (DLL) and link it to an separate application. The application crashes with the message "This application as requested the runtime to terminate in an unusual way. Specifically, the problem is caused by the exception block in the application.  Remove it and all is well.

-- ****************************************************************** --
-- The DLL (Dynamic Link Library)
-- ****************************************************************** --
package Dll_Name is
  procedure DLL_Test_Procedure( s : Integer := 0 );
private
  pragma export( Ada, DLL_Test_Procedure, "DLL_Test_Procedure" );
end Dll_Name;

with Ada.Text_IO;
package body Dll_Name is
  procedure DLL_Test_Procedure( s : Integer := 0 ) is
    Item         : String (1 .. 80);
    Last         : Natural;
  begin
    Ada.Text_IO.Put( "Hello World from 'DLL_Test_Procedure'... : " );
    Ada.Text_IO.Put_Line( Integer'image( s ) );
    Ada.Text_IO.Get_Line( Item, Last );
  end DLL_Test_Procedure;
end Dll_Name;

-- The Import Spec (used by the application)
package Dll_Name_Imports is
  procedure DLL_Test_Procedure( s : Integer := 0 );
private
  pragma import( Ada, DLL_Test_Procedure, "DLL_Test_Procedure" );
end Dll_Name_Imports;

-- ****************************************************************** --
-- The Application
-- ****************************************************************** --
with Ada.Text_IO;
with Ada.Exceptions; use Ada.Exceptions;
with Dll_Name_Imports;
procedure Dll_Name_Tester is
  procedure Trace( s: String ) is
  begin
    Ada.Text_IO.Put_Line( Ada.Text_IO.Current_Error, s );
  end Trace;
begin
  -- Problem block (if removed everything works fine)
  declare
    Constraint_Error : exception;
  begin
    raise Constraint_Error with "Exception caught.";
  exception
    when Fail : Constraint_Error => Trace( Exception_Message ( Fail ) );
  end;
  -- 
  Dll_Name_Imports.DLL_Test_Procedure( 1955 ); -- This normally works fine
end Dll_Name_Tester;

-- ****************************************************************** --

The application (and the exception) work fine if its not linked with the DLL.

So I'm stumped !


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

* Re: Application Crashes when linked with DLL
  2016-07-12 19:50 Application Crashes when linked with DLL Aurele
@ 2016-07-12 23:08 ` rieachus
  2016-07-13  0:16   ` Aurele
  2016-07-13 17:06   ` Aurele
  0 siblings, 2 replies; 4+ messages in thread
From: rieachus @ 2016-07-12 23:08 UTC (permalink / raw)


On Tuesday, July 12, 2016 at 3:50:09 PM UTC-4, Aurele wrote:
> Hi o/, I'm working with Gautier and we stumbled on an interesting program behavior and thought of sharing it with you for comments. We are using the latest version (2016) of Adacore GNAT programming studio. Here is the problem:  
> 
> Create a dynamic link library (DLL) and link it to an separate application. The application crashes with the message "This application as requested the runtime to terminate in an unusual way. Specifically, the problem is caused by the exception block in the application.  Remove it and all is well.

Two things. First, the message you are seeing comes from Windows.  At least, I have seen it in other cases where a DLL failed.

Second, why are you overloading Constraint_Error?  It may be perfectly legal, but what happens when you run some code from the Ada run-time where Constraint_Error is suppressed?  Try commenting out the declaration of Constraint_Error, or do a global change of Constraint_Error in your code to something else.  The problem with renaming Constraint_Error is that in some places in the Ada run-time and environment it may be raised or referred to by name, and in other cases implicitly such as out of range assignments or pragma Suppress.


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

* Re: Application Crashes when linked with DLL
  2016-07-12 23:08 ` rieachus
@ 2016-07-13  0:16   ` Aurele
  2016-07-13 17:06   ` Aurele
  1 sibling, 0 replies; 4+ messages in thread
From: Aurele @ 2016-07-13  0:16 UTC (permalink / raw)



Re: "overloading Constraint_Error", the same thing happens no mater the name you give the exception.  

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

* Re: Application Crashes when linked with DLL
  2016-07-12 23:08 ` rieachus
  2016-07-13  0:16   ` Aurele
@ 2016-07-13 17:06   ` Aurele
  1 sibling, 0 replies; 4+ messages in thread
From: Aurele @ 2016-07-13 17:06 UTC (permalink / raw)



Actually, both the Ada DLL and the calling application have to be Binded using the shared GNAT Run time switch.  Then the exceptions work ok.


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

end of thread, other threads:[~2016-07-13 17:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12 19:50 Application Crashes when linked with DLL Aurele
2016-07-12 23:08 ` rieachus
2016-07-13  0:16   ` Aurele
2016-07-13 17:06   ` Aurele

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