ErrnoException in Windows

novice2 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 1 08:39:27 PST 2015


Could you, please, help me to understand, why code:

////////////////
import std.c.windows.windows;
import std.exception: ErrnoException;
import std.stdio: writefln;
import std.string: toStringz;

void main ()
{
   CreateFileA(toStringz("nonexisting file name"), GENERIC_READ, 
FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 
null);
   auto ex = new ErrnoException("CreateFileA");
   writefln("ex.errno=%d, ex.msg=%s, lasterror=%d", ex.errno, 
ex.msg, GetLastError());
}
////////////////

prints:
ex.errno=0, ex.msg=CreateFileA (No error), lasterror=2

I wanted it will be:
ex.errno=2, ex.msg=CreateFileA (File not found), lasterror=2


More information about the Digitalmars-d-learn mailing list