title: Platform Invoke for Newland barcode scanner
body: <p>I am attempting to access a Newlands scanner using Platform Invoke from a c# program.
  It should be relatively straight forward.
  I set up my P/Invoke and and call it.</p>
  
  <pre><code>[DllImport("NLcpfw.dll", EntryPoint = "cpfw_open", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
          public static extern IntPtr cpfw_open(string pwStrPort,
                                                       string pwStrParam,
                                                       int nMode);
  
  public static void CallFromHere(){
              IntPtr hDev = cpfw_open("udp", "", CPFW_OM_NORMAL);
              //GCHandle handle = GCHandle.Alloc(HNLCPFW, GCHandleType.Pinned);
              System.Diagnostics.Debug.Assert(hDev != null);
              NewlandInterface.cpfw_close(hDev);
  
      }
  </code></pre>
  
  <p>Some how it is not picking it up.
  I get a BadImageFormatException was unhandled
  Make sure it is a valid managed assembly
  Make sure you have supplied a correct path for the assembly</p>
  
  <p>The C++ header reads</p>
  
  <pre><code>__declspec(dllimport) HNLCPFW WINAPI cpfw_open(WCHAR *pwStrPort, WCHAR *pwStrParam, int nMode = CPFW_OM_NORMAL);
  
  
  typedef struct
  {
      void* hDev;
      int nMode;
      PNLCPFW_PLUG_API DevAPI;
      HINSTANCE hPlugDll;
      void *exData;
  }NLCPFW,*HNLCPFW;
  </code></pre>
  
  <p>I'm assuming it is ok just to take a IntPtr  in my p\Invoke code.</p>
  
  <p>Any ideas as to why this is happening would be much appreciated.
  I have copied all of the dll's in with the exe. In this case these are
  NLcpfw.dll, cpfw_udp.dll, cpfw_tcp.dll,cpfw_hidpos.dll etc</p>
  
  <p>Thanks leppie I need to change the platform to X86</p>