title: A call to PInvoke function xxx has unbalanced the stack
body: <p>I am using C DLL in C# code (.net 4.0) in a console application and facing issue. 
  When I call the C method it raises the below exception.</p>
  
  <pre><code>"A call to PInvoke function 'ProcessFilesC' 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."
  </code></pre>
  
  <p>Here is the C code</p>
  
  <pre><code>    int ProcessFilesC(
          char **p_FilesOrDirs,
          ImageInfoC **p_vecImageInfo,
          int ***p_vecStackIndexes,
          RectC ***p_vecFaces
      );    
  </code></pre>
  
  <p>Here is my C# code</p>
  
  <pre><code>    [DllImport(@"..\ref\myCApp.dll", CallingConvention = CallingConvention.StdCall)]
      unsafe private static extern UInt16 ProcessFilesC(
                 String[] p_FilesOrDirs,
                 ref ImageInfoC[] p_vecImageInfo,
                 out Int32[] p_vecStackIndexes,
                 out RectC[] p_vecFaces
              );
  
  
      public unsafe struct ImageInfoC
      {            
          public String resizedFilePath;      //char*   (in C)
          public Byte isUsable;               //unsigned char (in C)
          public UInt32 imageId;              //long int in (in C)
          public UInt16 stackIndex;           //int (in C)
          public Boolean isBestPhoto;         //unsigned char  (in C)
      }
  </code></pre>
  
  <p>Below is C# code to call the method</p>
  
  <pre><code>    unsafe
          {
               iResult = ProcessFilesC(
                                p_FilesOrDirs,          // Value getting passed to DLL
                                ref p_vecImageInfo,
                                out p_vecStackIndexes,
                                out p_vecFaces
                          );
               Console.WriteLine("ProcessFilesC Complete");
          }
  </code></pre>
  
  <p>When code reaches here, I can see that method is processing as it prints in console but after processing, it raises the mentioned exception.</p>
  
  <p>I guess this is due to C DLL is trying to write values in output/ref parameters. 
  I am not getting where is the issue or what's the wrong in my code. </p>
  
  <p>Please note that I have already uncheck option "Suppress JIT optimization on module load"  at Tools -> Options -> Debugging -> General</p>
  
  <p>Please help as soon as poosible.</p>
  
  <p>Thanks for spending to valuable time to read this post.</p>
  
  <p>Thanks,
  Kiran</p>