title: C# register external dll callback
body: <p>I use Visual Studio Community 2015 and Visual C#.
  I'm in trouble in order to have a signature Pad to work.
  This Pad is connected via USB and a &quot;dll&quot; is provided in order to get the signatures.</p>
  <p>I'm used to work with WinDev but I think there's a problem with callbacks...
  So I decided to try with C# but since I'm a beginner I'm in trouble.</p>
  <p>I created a project, allowed &quot;unsafe&quot; code, nd coded my first function which is to initialize the Pad.
  It works well, since there's no complex types for this call.
  It thickens with callback pointers.</p>
  <p>Here's the documentation extract for the procedure declaration provided by the manufacturer:<br />
  --- The one which works :</p>
  <pre><code>Format: BYTE uSign300_OpenHid(UINT auiVid, UINT auiPid)
  Parameter: auiVid The Vendor ID
  auiPid The Product ID
  Return: BYTE : 0=FAIL, 1=SUCCESS (these are constants defined earlier)
  Example: uSign300_OpenHid(0x0ACD,0x1320);
  </code></pre>
  <p>--- The two which cause me troubles</p>
  <pre><code>Function: uSign300_AddPointHandle
  Description: Register a call-back function for StartCapture function, the function will be called when receiving signature data
  Format: **BYTE uSign300_AddPointHandle(PSIGN_FUNC func,LPVOID pParam)**
  Parameter: func The name of call-back function
  The format of PSIGN_FUNC is typedef void **(WINAPI *PSIGN_FUNC)(int*,int, LPVOID)**
  The first parameter is data buffer
  The second parameter is the length of data.
  Please see demo code for more information.
  pParam The current pointer
  Return: 0=FAIL
  Example: uSign300_AddPointHandle(point_handle,this);
  </code></pre>
  <p>And my code:</p>
  <pre><code>namespace uSign300ns
  {
  
      public static class retcode
      {
          public const byte SUCCESS = 0x01;
          public const byte FAIL = 0x01;
          public static char sdialog;
      }
  
      unsafe public class uSign300
      {
          const string _dllLocation = &quot;uSign300Kit.dll&quot;;
          [DllImport(_dllLocation)]
          public static extern byte uSign300_OpenHid(uint auiVid, uint auiPid);
          [DllImport(_dllLocation)]
          public static extern bool uSign300_Close();
          [DllImport(_dllLocation)]
          public static extern byte uSign300_ClearSignature();
          [DllImport(_dllLocation)]
          public static extern byte uSign300_AddPointHandle(void* func, void* pParam);
          [DllImport(_dllLocation)]
          public static extern byte uSign300_StartCapture(byte f_Mode, byte f_Interval, byte s_Red, byte s_Green, byte s_Blue, byte b_Red, byte b_Green, byte b_Blue);
          [DllImport(_dllLocation)]
          public static extern byte uSign300_ExitCapture();
          [DllImport(_dllLocation)]
          public static extern byte uSign300_ControlLED(byte leftLED, byte rightLED);
  
          //
          // --- Méthode d'initialisation
          public static bool __uSign_000_Connect()
          {
              bool bRet = false;
              byte nRet;
              nRet = uSign300_OpenHid(0x0ACD, 0x1320);
              if (nRet == retcode.SUCCESS)
              {
                  bRet = true;
              }
              if (bRet)
              {
                  // on éteint les LEDs
                  uSign300_ControlLED(0x00, 0x00);
              }
  
              return bRet;
          }
  
  
          private void __uSign_callback(void* __ptr_data, int datalen, void* __ptr_dialog)
          {
              MessageBox.Show(&quot;Callback appelée&quot;);
          }
  
  
          public static bool __uSign_100_StartThreadedCapture()
          {
              bool bRet;
              byte nRet;
              //void* __ptr_callback;
              //string sChaine;
              nRet = uSign300_ClearSignature();
  
              // enregistrer la callback
              fixed (char* __ptr_dialog = &amp;retcode.sdialog) {
                  uSign300_AddPointHandle(__uSign_callback, __ptr_dialog);
              }
  
             
  
              bRet = true;
              return bRet;
          }
      }
  }
  </code></pre>
  <p>And here, the sample code in C provided by the manufacturer</p>
  <pre><code>void __stdcall point_handle (int *buf, int rev, LPVOID pParam)
  {   
  
      for(int i = 0; i &lt; rev;)
      {
              int point_x;
              int point_y;
              point_x = buf[i++];
              point_y = buf[i++]; 
      }
  }
  
  void OnStartcapturing() 
  {
      uSign300_AddPointHandle(point_handle,this); 
      AfxBeginThread(ThreadProc_Capture, this);
  }
  </code></pre>
  <p>I'm not able to have the compilation working.</p>