How to pass NULL to a COM interface method parameter if it is defined as [In, Out] ref int pchEaten ?
For example, consider the following interface:
[ComImport, Guid ("000214E6-0000-0000-C000-000000000046")] [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)] internal interface IShellFolder { void ParseDisplayName ( [In] IntPtr hwnd, [In] IBindCtx pbc, [In, MarshalAs (UnmanagedType.LPWStr)] string pszDisplayName, [In, Out] ref uint pchEaten, [Out] out PIDLIST ppidl, [In, Out] ref SFGAO pdwAttributes);
MSDN says the following about the pchEaten parameter: a pointer to a ULONG value that receives the number of characters of the display name that has been parsed. If your application does not need this information, set pchEaten to NULL and no value will be returned. The pdwAttributes parameter pdwAttributes also be set to NULL.
However, when I ParseDisplayName method from C #, I see no way to pass a null value to the ref parameter.
If I called functions from a DLL, I could import the function several times: one with the IntPtr parameter, IntPtr with the correct signature, and choose the overload depending on whether I need to send and receive values. However, if I try to import the same method several times into COM, it will not work, since the order of the methods is critical and the function pointers will be offset.
Question : How to make it possible to call a COM method with both a value and a NULL value in / out?
Note : this is just an example. I know that I can create a dummy variable, pass it to the ref parameter and ignore the return value. However, the behavior of the method may depend on whether the value is NULL, a non-zero value can lead to performance degradation, etc., so I would like to avoid this.