comp.lang.ada
 help / color / mirror / Atom feed
* Ada to Interfacing C# (Urgent)
@ 2006-03-24 18:30 Hakan
  2006-03-25  0:32 ` Jeffrey R. Carter
  0 siblings, 1 reply; 7+ messages in thread
From: Hakan @ 2006-03-24 18:30 UTC (permalink / raw)


I have been using a library written in Ada 95 for a while. (source code
available in Ada 95 and is written by someone else)
I have built an ADA DLL by using GNAT compiler for  Windows using this
library and
written some wrapper code in .Net 2003 with C#  which calls services
from the ADA DLL.
My problem is I get and "Object Reference Not set to an istance.."
error (or Access Violation error) in the Visual Studio 2003 Environment
when calling the
"Create_Exception_Ptr(ref ExcpWrp)" service given below:

The C# Code where the problem is:
[DllImport(("Mydll.dll"), CallingConvention=CallingConvention.Cdecl)]
internal static extern void Create_Exception_Ptr(ref IntPtr ExcpWrp);
public IntPtr CreatePtr()
{
   IntPtr ExcpWrp = IntPtr.Zero;
   try
{
    Create_Exception_Ptr(ref ExcpWrp);
}
catch (System.Exception ex)
{
string msg = ex.Message;
}
return ExcpWrp;
}
The corresponding Ada code is:

---spec file--
with Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
.........
package C renames Interfaces.C;
type Exception_Ptr is access all chars_ptr;
pragma Controlled(Exception_Ptr);
procedure Create_Exception_Ptr(ExceptionPtr : in out Exception_Ptr);
pragma Export (C, Create_Exception_Ptr,"Create_Exception_Ptr");

-- body file--
....
procedure Create_Exception_Ptr(ExceptionPtr : in out Exception_Ptr) is
begin
  ExceptionPtr := new Chars_Ptr;
  ExceptionPtr.all:=Null_Ptr;
  ExceptionPtr.all:=New_Char_Array(C.To_C("NULL"));
end Create_Exception_Ptr;

 Actually, the problem arised when I start using the new version of my
Ada software Library (There was no problem with the old version. The
same code in C# and Ada works fine) The new Ada software library is big
in size and has a lot of Storage Pool allocation. Not  much dynamic
memory allocation. I tried to debug the Ada DLL, but I realized the
debugger does not go inside the function at runtime and an error
message ....SEGMENTATION FAULT....secondary_stack......is given.

Does anyone has an idea to overcome this problem? Please help for this,
 I have a time constraint. (I have used both Gnat 3.15p and Gnat
5.03a1, but found no solution)
 
Thanks a lot.
 
Best regards, Hakan.




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

* Re: Ada to Interfacing C# (Urgent)
  2006-03-24 18:30 Ada to Interfacing C# (Urgent) Hakan
@ 2006-03-25  0:32 ` Jeffrey R. Carter
  2006-03-25  8:09   ` Martin Krischik
  2006-03-25  8:49   ` Hakan
  0 siblings, 2 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-03-25  0:32 UTC (permalink / raw)


Hakan wrote:
> type Exception_Ptr is access all chars_ptr;
> pragma Controlled(Exception_Ptr);

Do you not need

pragma Convention (C, Exception_Ptr);

?

> Does anyone has an idea to overcome this problem? Please help for this,
>  I have a time constraint. (I have used both Gnat 3.15p and Gnat
> 5.03a1, but found no solution)

If you have GNAT 5.03a1, you must have a support contract. I'm sure AdaCore will 
be very helpful.

-- 
Jeff Carter
"Ditto, you provincial putz?"
Blazing Saddles
86



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

* Re: Ada to Interfacing C# (Urgent)
  2006-03-25  0:32 ` Jeffrey R. Carter
@ 2006-03-25  8:09   ` Martin Krischik
  2006-03-26 17:44     ` Hakan
  2006-03-25  8:49   ` Hakan
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Krischik @ 2006-03-25  8:09 UTC (permalink / raw)


Jeffrey R. Carter wrote:

> Hakan wrote:
>> type Exception_Ptr is access all chars_ptr;
>> pragma Controlled(Exception_Ptr);
> 
> Do you not need
> 
> pragma Convention (C, Exception_Ptr);
> 
> ?
> 
>> Does anyone has an idea to overcome this problem? Please help for this,
>>  I have a time constraint. (I have used both Gnat 3.15p and Gnat
>> 5.03a1, but found no solution)
> 
> If you have GNAT 5.03a1, you must have a support contract. I'm sure
> AdaCore will be very helpful.

But is the project at hand covered by the support contract? He would not be
the first to take GNAT/Pro home for private use - I have even seen mails on
the gnat (libre) mailing list to that respect.

But wait: Home projects are not under time constraint...

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: Ada to Interfacing C# (Urgent)
  2006-03-25  0:32 ` Jeffrey R. Carter
  2006-03-25  8:09   ` Martin Krischik
@ 2006-03-25  8:49   ` Hakan
  2006-03-26  0:31     ` Jeffrey R. Carter
  1 sibling, 1 reply; 7+ messages in thread
From: Hakan @ 2006-03-25  8:49 UTC (permalink / raw)


Jeffrey,
Thanks for your response.
I had also used the pragma Controlled clause.But not worked.
We have GNAT 5.03a1, but the support contract has finished a few months
ago.
But we plan to renew the contract in the near future.

The matter is I have a time constraint. So, I  have to solve the
problem (somehow?) as soon as possible....

Hakan.

Jeffrey R. Carter wrote:
> Hakan wrote:
> > type Exception_Ptr is access all chars_ptr;
> > pragma Controlled(Exception_Ptr);
>
> Do you not need
>
> pragma Convention (C, Exception_Ptr);
>
> ?
>
> > Does anyone has an idea to overcome this problem? Please help for this,
> >  I have a time constraint. (I have used both Gnat 3.15p and Gnat
> > 5.03a1, but found no solution)
>
> If you have GNAT 5.03a1, you must have a support contract. I'm sure AdaCore will
> be very helpful.
>
> --
> Jeff Carter
> "Ditto, you provincial putz?"
> Blazing Saddles
> 86




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

* Re: Ada to Interfacing C# (Urgent)
  2006-03-25  8:49   ` Hakan
@ 2006-03-26  0:31     ` Jeffrey R. Carter
  2006-03-26  9:12       ` Hakan
  0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-03-26  0:31 UTC (permalink / raw)


Hakan wrote:
> I had also used the pragma Controlled clause.But not worked.

Pragma Controlled simply prevents garbage collection, something that is not 
likely to happen with GNAT. It has nothing to do with interfacing to C.

Pragma Convention (C, ...) tells the compiler to use the same representation for 
objects of the type that a C compiler would use. For access types, they will be 
represented as a C pointer.

-- 
Jeff Carter
"I spun around, and there I was, face to face with a
six-year-old kid. Well, I just threw my guns down and
walked away. Little bastard shot me in the ass."
Blazing Saddles
40



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

* Re: Ada to Interfacing C# (Urgent)
  2006-03-26  0:31     ` Jeffrey R. Carter
@ 2006-03-26  9:12       ` Hakan
  0 siblings, 0 replies; 7+ messages in thread
From: Hakan @ 2006-03-26  9:12 UTC (permalink / raw)


Jeffrey,

I have written pragma Controlled clause in my previous message by
mistake, actually it should be pragma Convention (C, Exception_Ptr).

Jeffrey R. Carter wrote:
> Hakan wrote:
> > I had also used the pragma Controlled clause.But not worked.
>
> Pragma Controlled simply prevents garbage collection, something that is not
> likely to happen with GNAT. It has nothing to do with interfacing to C.
>
> Pragma Convention (C, ...) tells the compiler to use the same representation for
> objects of the type that a C compiler would use. For access types, they will be
> represented as a C pointer.
>
> --
> Jeff Carter
> "I spun around, and there I was, face to face with a
> six-year-old kid. Well, I just threw my guns down and
> walked away. Little bastard shot me in the ass."
> Blazing Saddles
> 40




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

* Re: Ada to Interfacing C# (Urgent)
  2006-03-25  8:09   ` Martin Krischik
@ 2006-03-26 17:44     ` Hakan
  0 siblings, 0 replies; 7+ messages in thread
From: Hakan @ 2006-03-26 17:44 UTC (permalink / raw)


The subject here is not a home project and nobody takes Gnat/Pro home
for private use.

As I said our support contract has been  finished a few months ago.But
we plan to renew the contract in the near future

The problem is we have an important demo for our customer nearby..
So I have to solve the problem somehow and  very quickly.




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

end of thread, other threads:[~2006-03-26 17:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-24 18:30 Ada to Interfacing C# (Urgent) Hakan
2006-03-25  0:32 ` Jeffrey R. Carter
2006-03-25  8:09   ` Martin Krischik
2006-03-26 17:44     ` Hakan
2006-03-25  8:49   ` Hakan
2006-03-26  0:31     ` Jeffrey R. Carter
2006-03-26  9:12       ` Hakan

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