Skip to content

Instantly share code, notes, and snippets.

@pcapriotti
Created June 7, 2012 15:35
Show Gist options
  • Save pcapriotti/2889480 to your computer and use it in GitHub Desktop.
Save pcapriotti/2889480 to your computer and use it in GitHub Desktop.
CreateFile example
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE h = CreateFile(
"bar.txt",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_TEMPORARY,
NULL);
if (h == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
printf("err %d\n", err);
return 1;
}
printf("%p\n", h);
int fd = _open_osfhandle(h, 0);
printf("fd %d\n", fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment