How can the return error code be specified on application exit? If this were a VC++ application, I could use the SetLastError(ERROR_ACCESS_DENIED)
-- return GetLastError()
APIs. Is there a way to do this in C#?
static int Main(string[] args)
{
Tool.Args = args;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Download_Tool());
return Tool.ErrorCode;
}
How can the Tool.ErrorCode
value be set intelligably? If I try something like Tool.ErrorCode = ERROR_ACCESS_DENIED
, I get an error, "The name ERROR_ACCESS_DENIED does not exist in the current context." Thanks.
ADDITIONAL INFORMATION
My example is over-simplified. Is there a way to something like this:
Tool.ErrorCode = ERROR_ACCESS_DENIED;
return Tool.ErrorCode;
...which generates a compile-error, rather than this:
Tool.ErrorCode = 5;
return Tool.ErrorCode;
...which works, but uses a "magic number." I'd like to avoid the use of magic numbers.