comp.lang.ada
 help / color / mirror / Atom feed
* Problems Linking With a C++ Lib
@ 2015-11-05 23:57 Aurele
  2015-11-06  0:05 ` Jeffrey R. Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Aurele @ 2015-11-05 23:57 UTC (permalink / raw)


Hi all, I've developed a DirectInput Windows wrapper library in C and I'm trying to link it with an Ada main (Adacore GPS environment) but I keep getting the following error: 

undefined reference to `DI_InitDirectInput@8'

I used C to develop this wrapper because its uses DirectX "API Methods" which is not supported in Ada (well at least I think its not). The wrapper is simple and implemented using MS Visual Studio.  Here is the C code sample:

extern "C" {																	
int DI_InitDirectInput( HWND hWnd, HINSTANCE hInstance );
int DI_InitDirectInput( HWND hWnd, HINSTANCE hInstance )
  {
  ...
  };
}

In Ada, I've created the following spec for the library:

package DI is
  function DI_InitDirectInput( hW    : hWnd; 
                               hInst : hInstance ) return Bool;
private
    pragma import( C, DI_InitDirectInput, "DI_InitDirectInput" );
end DI;

I use the following linker switches when building the main body:

  package Linker is
    for Default_Switches ("ada") use ( "-LE:\Lib", "-lDirectInput" );
  end Linker;

GPS (or the builder) finds the library but not the reference.  The library works well if I use the ObjectAda IDE to build the main.

Any thoughts?


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

* Re: Problems Linking With a C++ Lib
  2015-11-05 23:57 Problems Linking With a C++ Lib Aurele
@ 2015-11-06  0:05 ` Jeffrey R. Carter
  2015-11-06  0:11   ` Aurele
  2015-11-09 18:35 ` jsquirek
  2015-11-09 20:52 ` Aurele
  2 siblings, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2015-11-06  0:05 UTC (permalink / raw)


On 11/05/2015 04:57 PM, Aurele wrote:
> 
> extern "C" {																	
> int DI_InitDirectInput( HWND hWnd, HINSTANCE hInstance );
> int DI_InitDirectInput( HWND hWnd, HINSTANCE hInstance )
>   {
>   ...
>   };
> }
> 
> GPS (or the builder) finds the library but not the reference.  The library works well if I use the ObjectAda IDE to build the main.
> 
> Any thoughts?

Where is the 'extern "C"' code located?

-- 
Jeff Carter
"Unix and C are the ultimate computer viruses."
Richard Gabriel
99


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

* Re: Problems Linking With a C++ Lib
  2015-11-06  0:05 ` Jeffrey R. Carter
@ 2015-11-06  0:11   ` Aurele
  2015-11-06  0:56     ` Jeffrey R. Carter
  0 siblings, 1 reply; 13+ messages in thread
From: Aurele @ 2015-11-06  0:11 UTC (permalink / raw)



> Where is the 'extern "C"' code located?
> 
> -- 
> Jeff Carter
> "Unix and C are the ultimate computer viruses."
> Richard Gabriel
> 99

The extern "C" is located at the very beginning,  after the include:

#define DIRECTINPUT_VERSION 0x0300
#include <WINDOWS.H>
#include <CTYPE.H>
#include <DINPUT.H>
extern "C" {	
   :
   :
}

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

* Re: Problems Linking With a C++ Lib
  2015-11-06  0:11   ` Aurele
@ 2015-11-06  0:56     ` Jeffrey R. Carter
  2015-11-06  1:27       ` Aurele
  0 siblings, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2015-11-06  0:56 UTC (permalink / raw)


On 11/05/2015 05:11 PM, Aurele wrote:
> 
> 
> The extern "C" is located at the very beginning,  after the include:

The very beginning of what?

-- 
Jeff Carter
"Unix and C are the ultimate computer viruses."
Richard Gabriel
99


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

* Re: Problems Linking With a C++ Lib
  2015-11-06  0:56     ` Jeffrey R. Carter
@ 2015-11-06  1:27       ` Aurele
  2015-11-06  1:59         ` Jeffrey R. Carter
  0 siblings, 1 reply; 13+ messages in thread
From: Aurele @ 2015-11-06  1:27 UTC (permalink / raw)



> The very beginning of what?
> 
> -- 
> Jeff Carter
> "Unix and C are the ultimate computer viruses."
> Richard Gabriel
> 99

extern "C" is placed at the beining of the C wrapper (from which the Lib is built). See line 5 below:

#define DIRECTINPUT_VERSION 0x0300
#include <WINDOWS.H>
#include <CTYPE.H>
#include <DINPUT.H>
extern "C" {
int DI_InitDirectInput( HWND hWnd, HINSTANCE hInstance );
int DI_InitDirectInput( HWND hWnd, HINSTANCE hInstance ) 
  {
   ...
  }
}

Note, I get similar problem with #define DIRECTINPUT_VERSION 0x0800

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

* Re: Problems Linking With a C++ Lib
  2015-11-06  1:27       ` Aurele
@ 2015-11-06  1:59         ` Jeffrey R. Carter
  2015-11-06  3:07           ` Aurele
  0 siblings, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2015-11-06  1:59 UTC (permalink / raw)


On 11/05/2015 06:27 PM, Aurele wrote:
> 
> 
> extern "C" is placed at the beining of the C wrapper (from which the Lib is built). See line 5 below:

So this is in a different file from the C++? What is the name of the file it's in?

-- 
Jeff Carter
"Unix and C are the ultimate computer viruses."
Richard Gabriel
99

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

* Re: Problems Linking With a C++ Lib
  2015-11-06  1:59         ` Jeffrey R. Carter
@ 2015-11-06  3:07           ` Aurele
  2015-11-06  3:33             ` Jeffrey R. Carter
  0 siblings, 1 reply; 13+ messages in thread
From: Aurele @ 2015-11-06  3:07 UTC (permalink / raw)


> So this is in a different file from the C++? What is the name of the file it's in?

Maybe my initial explanation was not clear.  Let me try again...

There is one (1) C++ file (the wrapper) from which I build a Lib (DirectInput.Lib). The Lib contains external references for C++ procedure.   From Ada, I then try to "import" (and use) the said C++ Library procedures. But when building the Ada executable. I get unresolved Lib procedure (Adacore GPS cannot find my C++ procedure in the C++ Library). 

Do you use Adacore GPS? Is there a way I can post a demo project here ?  

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

* Re: Problems Linking With a C++ Lib
  2015-11-06  3:07           ` Aurele
@ 2015-11-06  3:33             ` Jeffrey R. Carter
  2015-11-06  3:57               ` Aurele
  2015-11-06  4:28               ` Aurele
  0 siblings, 2 replies; 13+ messages in thread
From: Jeffrey R. Carter @ 2015-11-06  3:33 UTC (permalink / raw)


On 11/05/2015 08:07 PM, Aurele wrote:
> 
> There is one (1) C++ file (the wrapper) from which I build a Lib (DirectInput.Lib). The Lib contains external references for C++ procedure.   From Ada, I then try to "import" (and use) the said C++ Library procedures. But when building the Ada executable. I get unresolved Lib procedure (Adacore GPS cannot find my C++ procedure in the C++ Library). 
> 
> Do you use Adacore GPS? Is there a way I can post a demo project here ?  

Can you directly link the object files for the extern-C wrapper and the C++
library and get it to work that way?

-- 
Jeff Carter
"Unix and C are the ultimate computer viruses."
Richard Gabriel
99

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

* Re: Problems Linking With a C++ Lib
  2015-11-06  3:33             ` Jeffrey R. Carter
@ 2015-11-06  3:57               ` Aurele
  2015-11-06  4:28               ` Aurele
  1 sibling, 0 replies; 13+ messages in thread
From: Aurele @ 2015-11-06  3:57 UTC (permalink / raw)


On Thursday, November 5, 2015 at 10:33:31 PM UTC-5, Jeffrey R. Carter wrote:
> On 11/05/2015 08:07 PM, Aurele wrote:
> > 
> > There is one (1) C++ file (the wrapper) from which I build a Lib (DirectInput.Lib). The Lib contains external references for C++ procedure.   From Ada, I then try to "import" (and use) the said C++ Library procedures. But when building the Ada executable. I get unresolved Lib procedure (Adacore GPS cannot find my C++ procedure in the C++ Library). 
> > 
> > Do you use Adacore GPS? Is there a way I can post a demo project here ?  
> 
> Can you directly link the object files for the extern-C wrapper and the C++
> library and get it to work that way?
> 
> -- 
> Jeff Carter
> "Unix and C are the ultimate computer viruses."
> Richard Gabriel
> 99

Hum, I'll try that tomorrow. Thanks

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

* Re: Problems Linking With a C++ Lib
  2015-11-06  3:33             ` Jeffrey R. Carter
  2015-11-06  3:57               ` Aurele
@ 2015-11-06  4:28               ` Aurele
  2015-11-07  3:10                 ` Aurele
  1 sibling, 1 reply; 13+ messages in thread
From: Aurele @ 2015-11-06  4:28 UTC (permalink / raw)


On Thursday, November 5, 2015 at 10:33:31 PM UTC-5, Jeffrey R. Carter wrote:
> On 11/05/2015 08:07 PM, Aurele wrote:
> > 
> > There is one (1) C++ file (the wrapper) from which I build a Lib (DirectInput.Lib). The Lib contains external references for C++ procedure.   From Ada, I then try to "import" (and use) the said C++ Library procedures. But when building the Ada executable. I get unresolved Lib procedure (Adacore GPS cannot find my C++ procedure in the C++ Library). 
> > 
> > Do you use Adacore GPS? Is there a way I can post a demo project here ?  
> 
> Can you directly link the object files for the extern-C wrapper and the C++
> library and get it to work that way?
> 
> -- 
> Jeff Carter
> "Unix and C are the ultimate computer viruses."
> Richard Gabriel
> 99

Good call Jeff, the I still got unresolved external symbol when calling from an other C++ main (instead of an Ada main I mean).  Need to find the problem in the Lib.   

THANKS !


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

* Re: Problems Linking With a C++ Lib
  2015-11-06  4:28               ` Aurele
@ 2015-11-07  3:10                 ` Aurele
  0 siblings, 0 replies; 13+ messages in thread
From: Aurele @ 2015-11-07  3:10 UTC (permalink / raw)


Thanks again Jeff Carter, I was able to fix my problem in the C++ wrapper.  The DirectX input binding now works correctly when linked with the Ada calling application :-)

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

* Re: Problems Linking With a C++ Lib
  2015-11-05 23:57 Problems Linking With a C++ Lib Aurele
  2015-11-06  0:05 ` Jeffrey R. Carter
@ 2015-11-09 18:35 ` jsquirek
  2015-11-09 20:52 ` Aurele
  2 siblings, 0 replies; 13+ messages in thread
From: jsquirek @ 2015-11-09 18:35 UTC (permalink / raw)


I am very interested in your project to port Direct Input because it directly relates to my Doom 3 project. I have actually tried in the past to port it, but the fact that it is fully OOP caused too many head aches.

This is a bit off topic, but are you aware that Microsoft has deprecated Direct Input? They recommend for you to use "Raw Input" which is actually used by the Direct Input library for all its functionality. It is possible to write your own keylogger and generic controller driver with Raw Input but again it proved too be too much of a pain to finish advanced features like those. I ended up implementing the mouse and keyboard controls with Raw Input and using Window's new XInput API to deal with Xbox controllers.

Another reason to not use Direct Input is that modern Xbox controllers have a fatal flaw with the right and left trigger where data is lost and they are tied together into one value.

Here are some links you may find helpful

Current Input API:
https://github.com/AdaDoom3/AdaDoom3/blob/master/Engine/Systems/Windows/neo-system-input-import.adb
https://github.com/AdaDoom3/AdaDoom3/blob/master/Engine/neo-system-input.ads

Key Logger Attempt:
https://github.com/AdaDoom3/AdaDoom3/blob/input/Engine/Systems/Windows/neo-system-input-import.adb


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

* Re: Problems Linking With a C++ Lib
  2015-11-05 23:57 Problems Linking With a C++ Lib Aurele
  2015-11-06  0:05 ` Jeffrey R. Carter
  2015-11-09 18:35 ` jsquirek
@ 2015-11-09 20:52 ` Aurele
  2 siblings, 0 replies; 13+ messages in thread
From: Aurele @ 2015-11-09 20:52 UTC (permalink / raw)


Thanks for your thoughts and thank you for the links. Lots of good stuff there.

You are correct, DirectInput is not the way to go for input but its something I had to get out of the way to fully understand the issues at hand. But that  binding now works, for now.  

As you suggested, I started looking at processing raw input but initially I was thinking of processing the WM_INPUT Windows message. However, I had really not thought of using the XInput API and I think I will do that instead.  

I'll contact you on your email shortly.

Thanks !

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

end of thread, other threads:[~2015-11-09 20:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-05 23:57 Problems Linking With a C++ Lib Aurele
2015-11-06  0:05 ` Jeffrey R. Carter
2015-11-06  0:11   ` Aurele
2015-11-06  0:56     ` Jeffrey R. Carter
2015-11-06  1:27       ` Aurele
2015-11-06  1:59         ` Jeffrey R. Carter
2015-11-06  3:07           ` Aurele
2015-11-06  3:33             ` Jeffrey R. Carter
2015-11-06  3:57               ` Aurele
2015-11-06  4:28               ` Aurele
2015-11-07  3:10                 ` Aurele
2015-11-09 18:35 ` jsquirek
2015-11-09 20:52 ` Aurele

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