<分区>
函数如CreateProcess具有指向结构的指针的签名。在 C 中,我只是将 NULL
作为可选参数的指针传递,而不是在堆栈上创建一个虚拟结构对象并将指针传递给该虚拟对象。
在 C# 中,我将其声明为 (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);
但是如果我尝试为 lpProcessAttributes
参数或 lpThreadAttributes
参数传递 null
,我会得到一个编译器错误:
Error 2 Argument 3: cannot convert from '<null>' to 'ref Debugging.Wrappers.SECURITY_ATTRIBUTES'
如何修改上述函数签名,以便我可以只为 SECURITY_ATTRIBUTES 参数传递 null
,而不会出现此编译器错误? (如果我愿意,还可以传递一个真实的结构吗?)