calling CreateFile, specifying FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE.
- by alexander-daniels
Before I describe my problem, here is a description of the program I'm writting:
This is a C++ application.
The purpose of my program is to create file on RAM memory.
I read that if specify FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE when creating file it will be loaded direct to the RAM memory.
One of blogs that talk about is this one: http://blogs.msdn.com/larryosterman/archive/2004/04/19/116084.aspx
I have built a mini-program, but it not achieves the goal. Instead, it creates a file on hard-drive on directory I specify.
Here's my program:
void main ()
{
LPCWSTR str = L"c:\temp.txt";
HANDLE fh = CreateFile(str,GENERIC_WRITE,0,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,NULL);
if (fh == INVALID_HANDLE_VALUE)
{
printf ("Could not open TWO.TXT");
return;
}
DWORD dwBytesWritten;
for (long i=0; i<20000000; i++)
{
WriteFile(fh, "This is a test\r\n", 16, &dwBytesWritten, NULL);
}
return;
}
I think there problem in CreateFile function, but I can't fix it. Please help me.