title: C++/CLI Convert tracking handle into native pointer for Win32?
body: <p>The following code works when called from C#, but it seems inefficient because I take the data
  from the managed world, make local native copies of it, call the Win32 function, and then copy
  the data back into managed parameters, which are returned to the caller.</p>
  
  <p>Is there a way to accomplish the following?</p>
  
  <p>1) Pass the blittable UInt32 reference parameters directly to the Win32 call?  Please note
     that this Win32 call updates values, which I want to return to the caller (i.e. theSerialNumber)    In essense, can I pin_ptr the UInt32 reference parameter (i.e. theSerialNumber) as  LPDWORD that
     the native function can use and directly update its value?</p>
  
  <p>2) Pass the StringBuilder buffers directly to the native function?  I imagine that I would
     need to set StringBuilder.Capacity = MAX_PATH+1;  But, I have no idea how to pin_ptr to
     its internal buffer, which the native function would use and update.</p>
  
  <p>I have been experimenting, searching, and banging my head on these questions for hours, so
  I really would appreciate your helP!</p>
  
  <p>Thanks,</p>
  
  <p>Mike</p>
  
  <hr>
  
  <pre><code>void MCVolume::VolumeInformation(String^ theRootPathName, 
              StringBuilder^% theVolumeName, 
              UInt32% theSerialNumber, 
              UInt32% theMaxComponentLength, 
              MEFileSystemFeature% theFileFlags, 
              StringBuilder^% theFileSystemName)
  {
  
  pin_ptr&lt;const wchar_t&gt; rootPathName = PtrToStringChars(theRootPathName);
  
  wchar_t volumeName[MAX_PATH+1];
  memset(volumeName, 0x0, MAX_PATH+1);
  wchar_t fileSystemName[MAX_PATH+1];
  memset(fileSystemName, 0x0, MAX_PATH+1);
  DWORD serialNumber = 0;
  DWORD fileFlags = 0;
  DWORD maxComponentLength = 0;
  
  //pin_ptr&lt;DWORD&gt; serialNumber = &amp;theSerialNumber;
  
  if (GetVolumeInformationW(rootPathName, 
              volumeName, 
              MAX_PATH+1,
              &amp;serialNumber,
              &amp;maxComponentLength, 
              &amp;fileFlags, 
              fileSystemName,
              MAX_PATH+1) == false)                                   
  {
      // Handle error
      throw gcnew Exception("GetVolumeInformationW failed.");
  }
  
  // Send back results...
  theVolumeName = gcnew StringBuilder(marshal_as&lt;String^&gt;(volumeName));
  theSerialNumber = serialNumber;
  theMaxComponentLength = maxComponentLength;
  theFileFlags = (MEFileSystemFeature) fileFlags;
  theFileSystemName =  gcnew StringBuilder(marshal_as&lt;String^&gt;(fileSystemName));
  </code></pre>