Functions such as CreateProcess have labels containing pointers to structures. In C, I would simply pass NULL as a pointer to optional parameters, instead of creating a dummy structure object on the stack and passing a pointer to the mannequin.
In C #, I 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 if I try to pass NULL for the argument lpProcessAttributes or lpThreadAttributes , I get a compiler error:
Error 2 Argument 3: Cannot convert from '<null>' to 'ref Debugging.Wrappers.SECURITY_ATTRIBUTES
How to change the above function signature so that I can just pass NULL for SECURITY_ATTRIBUTES arguments without this compiler error? (And also be able to convey the real structure if I want?)
c # winapi interop pinvoke
Tim Lovell-Smith
source share