Passing NULL to ref/out parameter of a COM interface method
See the question and my original answer on StackOverflowYou can redefine the interface like this for example:
internal interface IShellFolder
{
void ParseDisplayName (
[In] IntPtr hwnd,
[In] IBindCtx pbc,
[In, MarshalAs (UnmanagedType.LPWStr)] string pszDisplayName,
IntPtr pchEaten,
[Out] out PIDLIST ppidl,
[In, Out] ref SFGAO pdwAttributes);
// ...
}
And call it like this if you want to pass null:
ParseDisplayName(...., IntPtr.Zero, ...);
Or like this if you want to pass a uint value:
IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(uint)));
uint i = 1234;
Marshal.StructureToPtr(i, p, false);
ParseDisplayName(...., p, ...);
i = (uint)Marshal.PtrToStructure(p, typeof(uint)); // read the value back
Marshal.FreeHGlobal(p);