comp.lang.ada
 help / color / mirror / Atom feed
* Translating a VB dll header to Ada
@ 2007-04-11 19:48 vienapl
  2007-04-12  8:06 ` Dmitry A. Kazakov
  2007-04-12 11:34 ` gautier_niouzes
  0 siblings, 2 replies; 17+ messages in thread
From: vienapl @ 2007-04-11 19:48 UTC (permalink / raw)


Greetings,
I'm a really unexperienced programmer who trying to call a dll from
Ada code. It compiles properly, but after some function calls I get
the following error: raised PROGRAM_ERROR :
EXCEPTION_ACCESS_VIOLATION.

The VB code is the following:

---------------------------------------------------------------------------------------------------
Attribute VB_Name = "modWindower"
Option Explicit
'Text Helper: (MMF Name = "WindowerMMFTextHandler")

Public Declare Function CreateTextHelper Lib
"WindowerHelper.dll" (ByVal name As String) As Long
Public Declare Sub DeleteTextHelper Lib "WindowerHelper.dll" (ByVal
helper As Long)

Public Declare Sub CTHCreateTextObject Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String)
Public Declare Sub CTHDeleteTextObject Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String)

Public Declare Sub CTHSetText Lib "WindowerHelper.dll" (ByVal helper
As Long, ByVal name As String, ByVal text As String)
Public Declare Sub CTHSetVisibility Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String, ByVal visible As Boolean)
Public Declare Sub CTHSetFont Lib "WindowerHelper.dll" (ByVal helper
As Long, ByVal name As String, ByRef font As Byte, ByVal height As
Integer)
Public Declare Sub CTHSetColor Lib "WindowerHelper.dll" (ByVal helper
As Long, ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal
g As Byte, ByVal b As Byte)
Public Declare Sub CTHSetLocation Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String, ByVal x As Single, ByVal y As
Single)
Public Declare Sub CTHSetBold Lib "WindowerHelper.dll" (ByVal helper
As Long, ByVal name As String, ByVal bold As Boolean)
Public Declare Sub CTHSetItalic Lib "WindowerHelper.dll" (ByVal helper
As Long, ByVal name As String, ByVal italic As Boolean)
Public Declare Sub CTHSetBGColor Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String, ByVal a As Byte, ByVal r As
Byte, ByVal g As Byte, ByVal b As Byte)
Public Declare Sub CTHSetBGBorderSize Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String, ByVal pixels As Single)
Public Declare Sub CTHSetBGVisibility Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal name As String, ByVal visible As Boolean)
Public Declare Sub CTHSetRightJustified Lib
"WindowerHelper.dll" (ByVal helper As Long, ByVal name As String,
ByVal justified As Boolean)

Public Declare Sub CTHFlushCommands Lib "WindowerHelper.dll" (ByVal
helper As Long)

'Keyboard Helper: (MMF Name = "WindowerMMFKeyboardHandler")

Public Declare Function CreateKeyboardHelper Lib
"WindowerHelper.dll" (ByVal name As String) As Long
Public Declare Sub DeleteKeyboardHelper Lib
"WindowerHelper.dll" (ByVal helper As Long)

Public Declare Sub CKHSetKey Lib "WindowerHelper.dll" (ByVal helper As
Long, ByVal key As Byte, ByVal down As Boolean)
Public Declare Sub CKHBlockInput Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal block As Boolean)
Public Declare Sub CKHSendString Lib "WindowerHelper.dll" (ByVal
helper As Long, ByVal data As String)

'Console Helper: (MMF Name = "WindowerMMFConsoleHandler")

Public Declare Function CreateConsoleHelper Lib
"WindowerHelper.dll" (ByVal name As String) As Long
Public Declare Sub DeleteConsoleHelper Lib "WindowerHelper.dll" (ByVal
helper As Long)

Public Declare Function CCHIsNewCommand Lib
"WindowerHelper.dll" (ByVal helper As Long) As Boolean
Public Declare Function CCHGetArgCount Lib "WindowerHelper.dll" (ByVal
helper As Long) As Integer
Public Declare Sub CCHGetArg Lib "WindowerHelper.dll" (ByVal helper As
Long, ByVal index As Integer, ByVal buffer As String)
---------------------------------------------------------------------------------------------------

My Ada header looks like this:

---------------------------------------------------------------------------------------------------
with Interfaces.C;

package adawindowerhelper is

  pragma Linker_Options ("-lwindowerhelper");

  -- 'Text Helper: (MMF Name = "WindowerMMFTextHandler")

  function CreateTextHelper (name : in Interfaces.C.Char_Array) return
Interfaces.C.long; --DWORD
  pragma Import (C, CreateTextHelper, External_Name =>
"CreateTextHelper");

  procedure DeleteTextHelper (helper : in Interfaces.C.long);
  pragma Import (C, DeleteTextHelper, External_Name =>
"DeleteTextHelper");


  procedure CTHCreateTextObject (helper : in Interfaces.C.long;
                                 name : in Interfaces.C.Char_Array);
  pragma Import (C, CTHCreateTextObject, External_Name =>
"CTHCreateTextObject");

  procedure CTHDeleteTextObject (name : in Interfaces.C.Char_Array);
  pragma Import (C, CTHDeleteTextObject, External_Name =>
"CTHDeleteTextObject");


  procedure CTHSetText
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    text   : in Interfaces.C.Char_Array);
  pragma Import (C, CTHSetText, External_Name => "CTHSetText");

  procedure CTHSetVisibility
   (helper  : in Interfaces.C.long;
    name    : in Interfaces.C.Char_Array;
    visible : in Interfaces.C.int); --BOOL
  pragma Import (C, CTHSetVisibility, External_Name =>
"CTHSetVisibility");

  procedure CTHSetFont
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    font   : in Interfaces.C.Char_Array;
    height : Interfaces.C.short); --INT
  pragma Import (C, CTHSetFont, External_Name => "CTHSetFont");

  procedure CTHSetColor
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    A      : in Interfaces.C.unsigned_char; --UCHAR
    R      : in Interfaces.C.unsigned_char;
    G      : in Interfaces.C.unsigned_char;
    B      : in Interfaces.C.unsigned_char);
  pragma Import (C, CTHSetColor, External_Name => "CTHSetColor");

  procedure CTHSetLocation
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    x      : in Interfaces.C.C_float; --Single?
    y      : in Interfaces.C.C_float);
  pragma Import (C, CTHSetLocation, External_Name =>
"CTHSetLocation");

  procedure CTHSetBold
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    bold   : in Interfaces.C.int); --BOOL
  pragma Import (C, CTHSetBold, External_Name => "CTHSetBold");

  procedure CTHSetItalic
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    italic : in Interfaces.C.int); --BOOL
  pragma Import (C, CTHSetItalic, External_Name => "CTHSetItalic");

  procedure CTHSetBGColor
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    A      : in Interfaces.C.unsigned_char;
    R      : in Interfaces.C.unsigned_char;
    G      : in Interfaces.C.unsigned_char;
    B      : in Interfaces.C.unsigned_char);
  pragma Import (C, CTHSetBGColor, External_Name => "CTHSetBGColor");

  procedure CTHSetBGBorderSize
   (helper : in Interfaces.C.long;
    name   : in Interfaces.C.Char_Array;
    pixels : in Interfaces.C.C_Float);
  pragma Import (C, CTHSetBGBorderSize, External_Name =>
"CTHSetBGBorderSize");

  procedure CTHSetBGVisibility
   (helper  : in Interfaces.C.long;
    name    : in Interfaces.C.Char_Array;
    visible : in Interfaces.C.int);
  pragma Import (C, CTHSetBGVisibility, External_Name =>
"CTHSetBGVisibility");

  procedure CTHSetRightJustified
   (helper    : in Interfaces.C.long;
    name      : in Interfaces.C.Char_Array;
    justified : in Interfaces.C.int);
  pragma Import (C, CTHSetRightJustified, External_Name =>
"CTHSetRightJustified");


  procedure CTHFlushCommands (helper : in Interfaces.C.long);
  pragma Import (C, CTHFlushCommands, External_Name =>
"CTHFlushCommands");

  -- 'Keyboard Helper: (MMF Name = "WindowerMMFKeyboardHandler")

  function CreateKeyboardHelper (name : in Interfaces.C.Char_Array)
return Interfaces.C.long;
  pragma Import (C, CreateKeyboardHelper, External_Name =>
"CreateKeyboardHelper");

  procedure DeleteKeyboardHelper (helper : in Interfaces.C.long);
  pragma Import (C, DeleteKeyboardHelper, External_Name =>
"DeleteKeyboardHelper");


  procedure CKHSetKey
   (helper : Interfaces.C.long;
    key    : Interfaces.C.unsigned_char;
    down   : Interfaces.C.int);
  pragma Import (C, CKHSetKey, External_Name => "CKHSetKey");

  procedure CKHBlockInput (helper : Interfaces.C.long; block :
Interfaces.C.int);
  pragma Import (C, CKHBlockInput, External_Name => "CKHBlockInput");

  procedure CKHSendString (helper : Interfaces.C.long; data : in
Interfaces.C.Char_Array);
  pragma Import (C, CKHSendString, External_Name => "SCKHendString");

  -- 'Console Helper: (MMF Name = "WindowerMMFConsoleHandler")

  function CreateConsoleHelper (name : in Interfaces.C.Char_Array)
return Interfaces.C.long;
  pragma Import (C, CreateConsoleHelper, External_Name =>
"CreateConsoleHelper");

  procedure DeleteConsoleHelper (helper : in Interfaces.C.long);
  pragma Import (C, DeleteConsoleHelper, External_Name =>
"DeleteConsoleHelper");


  function CCHIsNewCommand (helper : Interfaces.C.long) return
Interfaces.C.int; --BOOL
  pragma Import (C, CCHIsNewCommand, External_Name =>
"CCHIsNewCommand");

  function CCHGetArgCount (helper : Interfaces.C.long) return
Interfaces.C.short; --SHORT
  pragma Import (C, CCHGetArgCount, External_Name =>
"CCHGetArgCount");

  procedure CCHGetArg
   (helper : Interfaces.C.long;
    index  : Interfaces.C.short;
    data   : in Interfaces.C.Char_Array);
  pragma Import (C, CCHGetArg, External_Name => "CCHGetArg");

end adawindowerhelper;
---------------------------------------------------------------------------------------------------

And the test code follows:

---------------------------------------------------------------------------------------------------
with adawindowerhelper; use adawindowerhelper;
with Ada.Text_IO;       use Ada.Text_IO;
with Interfaces.C;

procedure test is
  TextHelperID : Interfaces.C.long;
  c            : Character;
begin
  TextHelperID := CreateTextHelper
(Interfaces.C.To_C("WindowerMMFTextHandler"));
  Put_Line ("CreateTextHelper: Ok");
  CTHCreateTextObject (TextHelperID, Interfaces.C.To_C("Object"));
  Put_Line ("CTHCreateTextObject: Ok");
  CTHSetText (TextHelperID, Interfaces.C.To_C("Object"),
Interfaces.C.To_C("This is a sample text object."));
  Put_Line ("CTHSetText: Ok");
  CTHSetColor (TextHelperID, Interfaces.C.To_C("Object"), 255, 255,
255, 255);
  Put_Line ("CTHSetColor: Ok");
  CTHSetLocation (TextHelperID, Interfaces.C.To_C("Object"), 100.0,
100.0);
  Put_Line ("CTHSetLocation: Ok");
  CTHSetVisibility (TextHelperID, Interfaces.C.To_C("Object"), 0);
  Put_Line ("CTHSetVisibility: Ok");
  CTHFlushCommands (TextHelperID);
  Put_Line ("CTHFlushCommands: Ok");
  Get_Immediate (c);
  DeleteTextHelper (TextHelperID);
  Put_Line ("DeleteTextHelper: Ok");
  CTHFlushCommands (TextHelperID);
  Put_Line ("CTHFlushCommands: Ok");
  Get_Immediate (c);
end test;
---------------------------------------------------------------------------------------------------

On execution, I get the following:

CreateTextHelper: Ok
CTHCreateTextObject: Ok
CTHSetText: Ok
CTHSetColor: Ok

raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION

I have no clue what's wrong, googled around a lot and read several
times the GNAT user's guide (I'm using GNAT GAP 2005). Any help will
be appreciated. Thank you in advance.




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

* Re: Translating a VB dll header to Ada
  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 11:34 ` gautier_niouzes
  1 sibling, 1 reply; 17+ messages in thread
From: Dmitry A. Kazakov @ 2007-04-12  8:06 UTC (permalink / raw)


On 11 Apr 2007 12:48:30 -0700, vienapl@hotmail.com wrote:

> I'm a really unexperienced programmer who trying to call a dll from
> Ada code. It compiles properly, but after some function calls I get
> the following error: raised PROGRAM_ERROR :
> EXCEPTION_ACCESS_VIOLATION.
> 
> The VB code is the following:

I am not an expert in VB, but for what it is worth

1. Microsoft changes VB permanently, you should really mention the version
number of the Beast. (:-))

2. The VBs I dealt with didn't used C convention. In your sources I see

   pragma Import (C, ...);

This means a C convention (cdecl in Windows terms), but it should be
stdcall instead:

   pragma Import (stdcall, ...); -- If you are using GNAT

3. Passing strings from/to VB is a mess. I don't remember the details,
sorry. Maybe others could comment on that.

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



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

* Re: Translating a VB dll header to Ada
  2007-04-11 19:48 Translating a VB dll header to Ada vienapl
  2007-04-12  8:06 ` Dmitry A. Kazakov
@ 2007-04-12 11:34 ` gautier_niouzes
  2007-04-12 14:24   ` vienapl
  1 sibling, 1 reply; 17+ messages in thread
From: gautier_niouzes @ 2007-04-12 11:34 UTC (permalink / raw)


Did you try GNATCOM for that ?

- For download, you have to look there
  http://www.gnavi.org/source/gnatcom/
or maybe there (although that version seems older)
  http://sourceforge.net/project/showfiles.php?group_id=121876

- Run the install script or at least build /tools/bindcom.adb

- When bindcom is built, run:

bindcom WindowerHelper.dll WindowerHelper

and you have your Ada interface automatically (a set of packages, with
comments etc.)
or an error message if the required information is missing. At least,
it is worth a try...

HTH
G.




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

* Re: Translating a VB dll header to Ada
  2007-04-12  8:06 ` Dmitry A. Kazakov
@ 2007-04-12 14:17   ` vienapl
  2007-04-12 17:16     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 17+ messages in thread
From: vienapl @ 2007-04-12 14:17 UTC (permalink / raw)


Although the header I'm trying to translate is in VB6, I guess that
the dll itself wasn't written with VB, but C++ instead. I actually
also have availible the C header for it (http://pastebin.ca/436394),
but I thought that the VB one was easier to understand and translate
for somoene who only used a bit of Ada. In fact, if I try to build the
test executable using Stdcall, I get compilation errors (undefined
references to the functions). So I guess the C calling conention is
right on this one.

On Apr 12, 10:06 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On 11 Apr 2007 12:48:30 -0700, vien...@hotmail.com wrote:
>
> > I'm a really unexperienced programmer who trying to call a dll from
> > Ada code. It compiles properly, but after some function calls I get
> > the following error: raised PROGRAM_ERROR :
> > EXCEPTION_ACCESS_VIOLATION.
>
> > The VB code is the following:
>
> I am not an expert in VB, but for what it is worth
>
> 1. Microsoft changes VB permanently, you should really mention the version
> number of the Beast. (:-))
>
> 2. The VBs I dealt with didn't used C convention. In your sources I see
>
>    pragma Import (C, ...);
>
> This means a C convention (cdecl in Windows terms), but it should be
> stdcall instead:
>
>    pragma Import (stdcall, ...); -- If you are using GNAT
>
> 3. Passing strings from/to VB is a mess. I don't remember the details,
> sorry. Maybe others could comment on that.
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de





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

* Re: Translating a VB dll header to Ada
  2007-04-12 11:34 ` gautier_niouzes
@ 2007-04-12 14:24   ` vienapl
  0 siblings, 0 replies; 17+ messages in thread
From: vienapl @ 2007-04-12 14:24 UTC (permalink / raw)


I have used GNATCOM for GWindows before, but unfortunately, that
didn't work. I get:

GNATCOM.ERRORS.COM_ERROR
HRESULT (2147654730) : Error loading type library/DLL.

Thank you, anyways.

On Apr 12, 1:34 pm, gautier_niou...@hotmail.com wrote:
> Did you try GNATCOM for that ?
>
> - For download, you have to look there
>  http://www.gnavi.org/source/gnatcom/
> or maybe there (although that version seems older)
>  http://sourceforge.net/project/showfiles.php?group_id=121876
>
> - Run the install script or at least build /tools/bindcom.adb
>
> - When bindcom is built, run:
>
> bindcom WindowerHelper.dll WindowerHelper
>
> and you have your Ada interface automatically (a set of packages, with
> comments etc.)
> or an error message if the required information is missing. At least,
> it is worth a try...
>
> HTH
> G.





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

* Re: Translating a VB dll header to Ada
  2007-04-12 14:17   ` vienapl
@ 2007-04-12 17:16     ` Dmitry A. Kazakov
  2007-04-13 15:25       ` vienapl
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry A. Kazakov @ 2007-04-12 17:16 UTC (permalink / raw)


On 12 Apr 2007 07:17:46 -0700, vienapl@hotmail.com wrote:

> Although the header I'm trying to translate is in VB6, I guess that
> the dll itself wasn't written with VB, but C++ instead. I actually
> also have availible the C header for it (http://pastebin.ca/436394),

In that header the functions you are using are all inlined. What is in the
DLL then?

For 'void *' I would use System.Address rather than Interfaces.C.long, but
on a 32-bit machine they must be same.

procedure CTHDeleteTextObject should have helper parameter.

procedure CTHSetFont should have height as Interfaces.C.int.

Otherwise it looks OK.

Are you sure that you are using the thingy properly?

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



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

* Re: Translating a VB dll header to Ada
  2007-04-12 17:16     ` Dmitry A. Kazakov
@ 2007-04-13 15:25       ` vienapl
  2007-04-13 16:55         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 17+ messages in thread
From: vienapl @ 2007-04-13 15:25 UTC (permalink / raw)


I posted this once already, but after several hours it seems to not
show up, so I'm posting it again.

Thank you for the parameter corrections, I edited them, but the
problem persists.

I'm quite sure I'm not using the API in a wrong manner, here is a C++
example of how it should be used: http://pastebin.ca/437367 and here a
VB6 one: http://pastebin.ca/437369 .

This thing is getting me really confused. Would some debug information
help?

Thank you, again, for your help.

On Apr 12, 7:16 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On 12 Apr 2007 07:17:46 -0700, vien...@hotmail.com wrote:
>
> > Although the header I'm trying to translate is in VB6, I guess that
> > the dll itself wasn't written with VB, but C++ instead. I actually
> > also have availible the C header for it (http://pastebin.ca/436394),
>
> In that header the functions you are using are all inlined. What is in the
> DLL then?
>
> For 'void *' I would use System.Address rather than Interfaces.C.long, but
> on a 32-bit machine they must be same.
>
> procedure CTHDeleteTextObject should have helper parameter.
>
> procedure CTHSetFont should have height as Interfaces.C.int.
>
> Otherwise it looks OK.
>
> Are you sure that you are using the thingy properly?
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de





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

* Re: Translating a VB dll header to Ada
  2007-04-13 15:25       ` vienapl
@ 2007-04-13 16:55         ` Dmitry A. Kazakov
  2007-04-14  1:05           ` vienapl
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry A. Kazakov @ 2007-04-13 16:55 UTC (permalink / raw)


On 13 Apr 2007 08:25:29 -0700, vienapl@hotmail.com wrote:

> I posted this once already, but after several hours it seems to not
> show up, so I'm posting it again.
> 
> Thank you for the parameter corrections, I edited them, but the
> problem persists.
> 
> I'm quite sure I'm not using the API in a wrong manner, here is a C++
> example of how it should be used: http://pastebin.ca/437367 and here a
> VB6 one: http://pastebin.ca/437369 .

Well, C++ uses the class instead of plain functions.

It is possible to make bindings to C++ classes. GNAT has pragmas for that.

> This thing is getting me really confused. Would some debug information
> help?

Yes. You can try to determine where exactly it crashes by inspecting the
stack. You can also check the stack frames to ensure that the call
convention is respected.

But first, is it CTHSetLocation which makes troubles or other procedures as
well? If you commented that call out, would the rest crash?

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



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

* Re: Translating a VB dll header to Ada
  2007-04-13 16:55         ` Dmitry A. Kazakov
@ 2007-04-14  1:05           ` vienapl
  2007-04-14  7:17             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 17+ messages in thread
From: vienapl @ 2007-04-14  1:05 UTC (permalink / raw)


The program crashes even if I comment that out, when debugging what I
get is:

Program received signal SIGSEGV, Segmentation fault.
0x10002f19 in WindowerHelper!?SetText@CTextHelper@@QAEXPAD0@Z ()

even if the program got past that function without crashing. I don't
understand why.

Please, forgive my lack of experience.

On Apr 13, 6:55 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On 13 Apr 2007 08:25:29 -0700, vien...@hotmail.com wrote:
>
> > I posted this once already, but after several hours it seems to not
> > show up, so I'm posting it again.
>
> > Thank you for the parameter corrections, I edited them, but the
> > problem persists.
>
> > I'm quite sure I'm not using the API in a wrong manner, here is a C++
> > example of how it should be used:http://pastebin.ca/437367and here a
> > VB6 one:http://pastebin.ca/437369.
>
> Well, C++ uses the class instead of plain functions.
>
> It is possible to make bindings to C++ classes. GNAT has pragmas for that.
>
> > This thing is getting me really confused. Would some debug information
> > help?
>
> Yes. You can try to determine where exactly it crashes by inspecting the
> stack. You can also check the stack frames to ensure that the call
> convention is respected.
>
> But first, is it CTHSetLocation which makes troubles or other procedures as
> well? If you commented that call out, would the rest crash?
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de





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

* Re: Translating a VB dll header to Ada
  2007-04-14  1:05           ` vienapl
@ 2007-04-14  7:17             ` Dmitry A. Kazakov
  2007-04-14 12:16               ` vienapl
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry A. Kazakov @ 2007-04-14  7:17 UTC (permalink / raw)


On 13 Apr 2007 18:05:18 -0700, vienapl@hotmail.com wrote:

> The program crashes even if I comment that out, when debugging what I
> get is:
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x10002f19 in WindowerHelper!?SetText@CTextHelper@@QAEXPAD0@Z ()
> 
> even if the program got past that function without crashing. I don't
> understand why.

This is probably a symptom of parameters mismatch. If you do just
CreateTextHelper and DeleteTextHelper, does it work?

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



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

* Re: Translating a VB dll header to Ada
  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
  0 siblings, 2 replies; 17+ messages in thread
From: vienapl @ 2007-04-14 12:16 UTC (permalink / raw)


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.

On Apr 14, 9:17 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On 13 Apr 2007 18:05:18 -0700, vien...@hotmail.com wrote:
>
> > The program crashes even if I comment that out, when debugging what I
> > get is:
>
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x10002f19 in WindowerHelper!?SetText@CTextHelper@@QAEXPAD0@Z ()
>
> > even if the program got past that function without crashing. I don't
> > understand why.
>
> This is probably a symptom of parameters mismatch. If you do just
> CreateTextHelper and DeleteTextHelper, does it work?
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de





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

* Re: Translating a VB dll header to Ada
  2007-04-14 12:16               ` vienapl
@ 2007-04-14 14:01                 ` Philippe Bertin
  2007-04-14 15:30                 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 17+ messages in thread
From: Philippe Bertin @ 2007-04-14 14:01 UTC (permalink / raw)


Passing a string to a C-written DLL (a "char *") is to be used from
within VB by redeclaring that argument's type 'ByVal' rather than
'ByRef' (I know, it sounds rather absurd). This means one is tempted
to specify that argument as an 'in' argument, in Ada. However, if the
C-written DLL writes into that string (albeit only *changing*, not
necessarily lengthen it), I think you can indeed have an access
violation ...

In other words : is your problem still the same when specifying string
arguments as 'in out' ?

Kind regards,

PhB




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

* Re: Translating a VB dll header to Ada
  2007-04-14 12:16               ` vienapl
  2007-04-14 14:01                 ` Philippe Bertin
@ 2007-04-14 15:30                 ` Dmitry A. Kazakov
  2007-04-14 21:37                   ` vienapl
  1 sibling, 1 reply; 17+ messages in thread
From: Dmitry A. Kazakov @ 2007-04-14 15:30 UTC (permalink / raw)


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



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

* Re: Translating a VB dll header to Ada
  2007-04-14 15:30                 ` Dmitry A. Kazakov
@ 2007-04-14 21:37                   ` vienapl
  2007-04-15 14:03                     ` vienapl
  0 siblings, 1 reply; 17+ messages in thread
From: vienapl @ 2007-04-14 21:37 UTC (permalink / raw)


That is the correct answer, it works!

Thank you a lot Philippe and Dmitry.

However, now I'm having trouble with the

  procedure CKHSendString (helper : System.Address; data : in
Interfaces.C.Char_Array);
  pragma Import (C, CKHSendString, External_Name => "CKHSendString");

function. It doesn't raise an exception, but it does not seem to do
anything at all. It works fine when used from the VB6 or C++ samples.

Thank you so much, again.

On Apr 14, 5:30 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On 14 Apr 2007 05:16:33 -0700, vien...@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. Kazakovhttp://www.dmitry-kazakov.de





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

* Re: Translating a VB dll header to Ada
  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
  0 siblings, 2 replies; 17+ messages in thread
From: vienapl @ 2007-04-15 14:03 UTC (permalink / raw)


Sorry, I quoted the wrong message as the solution, changing the string
to "in out" instead of only "in" is what avoided the access violation,
as Philippe Bertin suggested.

I don't seem to be able to get the CKHSendString function to work...




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

* Re: Translating a VB dll header to Ada
  2007-04-15 14:03                     ` vienapl
@ 2007-04-15 15:32                       ` Dmitry A. Kazakov
  2007-04-18 18:47                       ` Tarjei T. Jensen
  1 sibling, 0 replies; 17+ messages in thread
From: Dmitry A. Kazakov @ 2007-04-15 15:32 UTC (permalink / raw)


On 15 Apr 2007 07:03:26 -0700, vienapl@hotmail.com wrote:

> Sorry, I quoted the wrong message as the solution, changing the string
> to "in out" instead of only "in" is what avoided the access violation,
> as Philippe Bertin suggested.
> 
> I don't seem to be able to get the CKHSendString function to work...

That works with a different object though. Make sure that you don't mix
them:

type CTextHelper is new System.Address;
type CKeyboardHelper is new System.Address;

function CreateKeyboardHelper
  (name : access Interfaces.C.Char_Array) return CKeyboardHelper;
procedure CKHSendString
 (helper : CKeyboardHelper; string : in out Interfaces.C.Char_Array);
...

And I would really try to find some documentation on the DLL. If "in out"
solved the problem, and they indeed change the string contents, you better
know how exactly.

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



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

* Re: Translating a VB dll header to Ada
  2007-04-15 14:03                     ` vienapl
  2007-04-15 15:32                       ` Dmitry A. Kazakov
@ 2007-04-18 18:47                       ` Tarjei T. Jensen
  1 sibling, 0 replies; 17+ messages in thread
From: Tarjei T. Jensen @ 2007-04-18 18:47 UTC (permalink / raw)


<vienapl@hotmail.com> wrote :
> Sorry, I quoted the wrong message as the solution, changing the string
> to "in out" instead of only "in" is what avoided the access violation,
> as Philippe Bertin suggested.
>
> I don't seem to be able to get the CKHSendString function to work...
>

Does the DLL require initialization before you can use it? Some libraries 
do.


greetings,





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

end of thread, other threads:[~2007-04-18 18:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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