title: Wrap a DLL into Java
body: <p>I've got some code to talk to a hardware device on windows which is working in C++.  The code does something pretty simple to react to a button push on the device and I have this compiled into a dll with an observer that is called when the button is pushed.  I now need to interface this with a big Java program.  </p>
  
  <p>I was intending to use JNA but it only works with C and I cannot see how to do this with an Observer pattern in C.  I've looked into using BridJ and SWIG (both of which cliam to work on C++ DLLs) to create an interface to the compiled dll (with the associated header file) but BridJ creates huge amounts of files (in JNAeratorStudio) and then stops with an error and I cannot see how to get started on Windows with SWIG (I'm using Visual Studio Express rather than full Visual Studio).</p>
  
  <p>Does anyone know of a tutorial on integrating a C++ DLL with a Java Program - SWIG looks pretty promising but the tutorials are 'swampy'.  </p>
  
  <p>I've put some simple C code to talk to the DLL below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  #include "DeepFocusControlDll.h"
  
  using namespace std;
  using namespace DeepFocusControl;
  
  class MyObserver : public DeepFocusControl::DeepFocusObserver{
      void Event(){
          printf("***Button Pushed***");
      }
  };
  
  int main()
  {
      DeepFocusControl::AVA6Control* dfc = new DeepFocusControl::AVA6Control();
      MyObserver* observer = new MyObserver();
      dfc-&gt;AddObserver(observer);
      bool connected = dfc-&gt;IsConnected();
      printf("Connected %s\n", (connected)?"true":"false");
      bool connectresult = dfc-&gt;Connect();
      printf("Connecting %s\n", (connectresult)?"true":"false");
      connected = dfc-&gt;IsConnected();
      printf("Connected %s\n", (connected)?"true":"false");
      dfc-&gt;SetHardwareAppLaunch(false);
      char waitChar;
      cin &gt;&gt; waitChar;
      dfc-&gt;SetHardwareAppLaunch(true);
      dfc-&gt;RemoveObserver(observer);
      dfc-&gt;Disconnect();
      printf("Disconnected\n");
      cin &gt;&gt; waitChar;
  }
  </code></pre>
  
  <p>If anyone knows a simpler way to use an observer pattern on this I can happily recode the C side too.</p>