【发布时间】:2015-09-10 05:39:37
【问题描述】:
我有以下代码,其中 ShellExecuteEx 在执行时返回布尔值 true 或 false。我通过将其转换为字符串将其分配给类级别变量。
strShellCallStatus = ShellExecuteEx(ref info).ToString();
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
public static void exev()
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "open";
info.lpFile = "c:\\windows\\notepad.exe";
info.nShow = 5;
info.fMask = 0x440;
info.hwnd = IntPtr.Zero;
strShellCallStatus = ShellExecuteEx(ref info).ToString();
}
我应该担心 ShellExecuteEx 返回空值吗?如果是这样,我想使用以下语句:
strShellCallStatus = Convert.ToString(ShellExecuteEx(ref info));
【问题讨论】:
-
bool怎么可能是null? -
为什么需要返回一个NULL值,要么执行,要么不执行。