-1

I have the below code where ShellExecuteEx return a boolean value true or false when executed. And i am assigning that to a class level variable by converting it to string.

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();
}

Should I concern about ShellExecuteEx returning null value ? If so I want to use the below statement:

strShellCallStatus = Convert.ToString(ShellExecuteEx(ref info));
krrishna
  • 2,050
  • 4
  • 47
  • 101

1 Answers1

2

As long as ShellExecuteEx signature is not bool? ShellExecuteEx(), you shouldn't be scared that it will return null because bool is a value type with a default false.

Simply - a method with signature bool ShellExecuteEx() cannot return null cause it wouldn't even compile.

kamil-mrzyglod
  • 4,948
  • 1
  • 20
  • 29