Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 返回值为布尔值的方法_C#_Interop_User32 - Fatal编程技术网

C# 返回值为布尔值的方法

C# 返回值为布尔值的方法,c#,interop,user32,C#,Interop,User32,我有下面的代码,其中ShellExecuteEx在执行时返回布尔值true或false。通过将其转换为字符串,我将其分配给一个类级变量 strShellCallStatus = ShellExecuteEx(ref info).ToString(); [DllImport("shell32.dll", CharSet = CharSet.Auto)] static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo); pub

我有下面的代码,其中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));

只要
ShellExecuteEx
签名不是
bool?ShellExecuteEx()
,您不应该害怕它会返回
null
,因为
bool
是一个默认值类型
false


简单-签名为
bool ShellExecuteEx()
的方法无法返回
null
,因为它甚至无法编译。

一个
bool
怎么可能是
null
?为什么需要返回null值,要么应该执行,要么不执行。