Functions such as CreateProcess have signatures taking several pointers to structs. In common C programming I would likely pass NULL as a pointer for the optional parameters, instead of creating a temporary struct object on the stack and passing a reference.
In C#, I have declared it as (p/invoke)
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CreateProcess(
string lpApplicationName,
string lpCommandLine,
ref SECURITY_ATTRIBUTES lpProcessAttributes,
ref SECURITY_ATTRIBUTES lpThreadAttributes,
bool bInheritHandles,
CreateProcessFlags dwProcessCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
ref PROCESS_INFORMATION lpProcessInformation);
But when I try to pass null as the lpProcessAttributes argument or lpThreadAttributes argument, I get a compiler error:
Error 2 Argument 3: cannot convert from '<null>' to 'ref Debugging.Wrappers.SECURITY_ATTRIBUTES'
I would like to know how to modify the above function signature so that I can pass null for the SECURITY_ATTRIBUTES arguments without this compiler error. (But preferably can also decide to pass a real struct if I want to).