Method with return value as boolean

74 views Asked by At

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));
1

There are 1 answers

0
kamil-mrzyglod On BEST ANSWER

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.