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));
As long as
ShellExecuteEx
signature is notbool? ShellExecuteEx()
, you shouldn't be scared that it will returnnull
becausebool
is a value type with a defaultfalse
.Simply - a method with signature
bool ShellExecuteEx()
cannot returnnull
cause it wouldn't even compile.