title: DLLImport attribute PInvokeStackImbalance error
body: <p>I am attempting to call an unmanaged dll from vb (VS2013 Express) using the dllImport attribute as follows: </p>
  
  <pre><code>&lt;DllImport("armdll32.dll", setlasterror:=True, charset:=CharSet.Ansi)&gt;
  Public Shared Function ArmConnect(ByVal port As Integer, ByVal baud As Long, ByRef   serialNumber As String) As Integer
  
  End Function
  </code></pre>
  
  <p>I am calling the function like this:</p>
  
  <pre><code>Dim serialNumber As String = ""
  
  Debug.WriteLine(MicroScribeWrapper.ArmConnect(0, 0, serialNumber))
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <p><em>Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\XXXX'
  Additional information: A call to PInvoke function 'MicroscribeSDKTest!MicroscribeSDKTest.MicroScribeWrapper::ArmConnect' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.</em></p>
  
  <p>The documentation from the dll help file describes the function as follows:</p>
  
  <p><em>ArmConnect detects and establishes a connection to a MicroScribe. ArmDll32/ArmDll64 will connect to the first MicroScribe device it discovers. Detection order is as follows:
  scan all USB ports at all times; 
  if called with port=0 and baud=0, scan all available serial (COM) ports and try to connect at 115200 bauds; else, scan desired serial port at desired baud rate. 
  The port number and baud rate parameters are ignored if a MicroScribe is discovered on a USB port. When using USB connections, it is sometimes desirable to connect more than one MicroScribe unit to the host computer. In applications as such, each unique unit connected can be identified by its serial number string, passed by the optional parameter serialNumber. When using this configuration, separate instances of ArmDLL need to be running for each MicroScribe unit.</em></p>
  
  <pre><code>        int ArmConnect ( int port, long baud, char *serialNumber = 0 );
  </code></pre>
  
  <p>I'm pretty sure that the problem has to do with how I am calling the ArmConnect method but everything I've tried to date has failed.</p>
  
  <p>Any help would be appreciated.</p>