title: PInvoke GetPackageId failing with error 122
body: <p>I am trying to PInvoke this function (GetPackageId) from kernel32.dll:
  <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh446607(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/hh446607(v=vs.85).aspx</a></p>
  
  <p>I defined the structs and imports as follows:</p>
  
  <pre><code>    [StructLayout(LayoutKind.Sequential)]
      public struct PACKAGE_ID
      {
          uint reserved;
          uint processorArchitecture;
          PACKAGE_VERSION version;
          String name;
          String publisher;
          String resourceId;
          String publisherId;
      }
  
      [StructLayout(LayoutKind.Explicit)]
      public struct PACKAGE_VERSION
      {
          [FieldOffset(0)] public UInt64 Version;
          [FieldOffset(0)] public ushort Revision;
          [FieldOffset(2)] public ushort Build;
          [FieldOffset(4)] public ushort Minor;
          [FieldOffset(6)] public ushort Major;
      }  
  
      [DllImport("kernel32.dll", EntryPoint = "GetPackageId", SetLastError = true)]
      static extern int GetPackageId(IntPtr hProcess,out uint bufferLength,out PACKAGE_ID pBuffer);
  </code></pre>
  
  <p>And calling it like this:</p>
  
  <pre><code>    PACKAGE_ID buffer = new PACKAGE_ID();
      result = GetPackageId(hProcess, out bufferLength, out buffer); 
  </code></pre>
  
  <p>However I get a return value of 122 (ERROR_INSUFFICIENT_BUFFER). I am rather new to PInvoke and am not quite sure how to proceed from here. Do I need to initialize the strings before calling the function? </p>