comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Translating a VB dll header to Ada
Date: Sat, 14 Apr 2007 17:30:57 +0200
Date: 2007-04-14T17:30:03+02:00	[thread overview]
Message-ID: <4tn69i24hl6w$.ns08mtjy7afs.dlg@40tude.net> (raw)
In-Reply-To: 1176552993.629014.137900@y80g2000hsf.googlegroups.com

On 14 Apr 2007 05:16:33 -0700, vienapl@hotmail.com wrote:

> Yes, it does work with only those two functions.
> 
> I don't know which parameter could be wrong on the CTHSetText
> function. If I change a Char_Array for a WChar_Array I get a raised
> PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION instead, but the debugger
> prompts the same message.

OK, C++ code you have referred to, looks quite ..., so let me suggest a bit
offending thing. What if they copy pointers to strings?

So what happens if you allocate the string passed to CTHSetText statically:

   Object_Text : Interfaces.C.Char_Array :=
       Interfaces.C.To_C ("Object");
begin
   ...
   CTHSetText (TextHelperID, Object_Text);
       -- CTHSetText remembers a pointer to Object_Text, which has to
       -- exist as long as the library may dereference it
   ...

Another suggestion. If CTHSetText actually takes a pointer to a dynamically
allocated string which will be freed later somewhere inside the library.
Then CTHSetText should be declared like this:

   procedure CTHSetText
     (Helper : System.Address; Name_Ptr : Interfaces.C.Strings.chars_ptr);
   pragma Import (C, CTHSetText, ...);

and used as:

   CTHSetText (TextHelperID, Interfaces.C.Strings.New_String ("Object"));
       -- CTHSetText takes care of the memory allocated

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2007-04-14 15:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-11 19:48 Translating a VB dll header to Ada vienapl
2007-04-12  8:06 ` Dmitry A. Kazakov
2007-04-12 14:17   ` vienapl
2007-04-12 17:16     ` Dmitry A. Kazakov
2007-04-13 15:25       ` vienapl
2007-04-13 16:55         ` Dmitry A. Kazakov
2007-04-14  1:05           ` vienapl
2007-04-14  7:17             ` Dmitry A. Kazakov
2007-04-14 12:16               ` vienapl
2007-04-14 14:01                 ` Philippe Bertin
2007-04-14 15:30                 ` Dmitry A. Kazakov [this message]
2007-04-14 21:37                   ` vienapl
2007-04-15 14:03                     ` vienapl
2007-04-15 15:32                       ` Dmitry A. Kazakov
2007-04-18 18:47                       ` Tarjei T. Jensen
2007-04-12 11:34 ` gautier_niouzes
2007-04-12 14:24   ` vienapl
replies disabled

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