this pBuffer NULL tell me that I am not able to read that sectors ... why ? The program is running as admin and sVolume is feed by _T("\\\\.\\F:"), first TRACE macro printed is a prove that is OK that part. SetFilePointer is used to position the reading part, and I intend to setup offset to the beginning, right ?
Your pBuffer value is NULL, so you are trying to read data into the memory address 0 - you have to allocate some space to read the data into and use that for your pBuffer value. For 512 bytes a stack-based array should do the trick.
pBuffer NULL tell me that I am not able to read that sectors
No, pBuffer = NULL; tells you that you have not allocated any space to pBuffer. And don't use void* unless you are trying to allocate nothing.
You can allocate space either of the following ways.
unsignedchar* pBuffer = newunsignedchar[dwLen]; // allocate some space for the data to be read into
unsignedchar buffer[dwLen]; // allocate on the stack
ReadFile(hVolume, buffer, dwLen, &dwNum, NULL);
It is just the same as OpenFile behind the scenes so nothing to do with CFile. Your call probably fails because you are not including the share flags in your call to CFile::Open(), which are required when trying to access a device.
As others have pointed out, the issue is with pBuffer not associated with any allocated memory.
In addition to this, I would like to point out one more flaw in your code, although it doesn't matter in this case.
The third parameter to SetFilePointer[^] must be an address of a LONG variable. PLONG does not declare a LONG variable. It's only a pointer to a LONG variable.
Here SetFilePointer will actually try to write to memory 0.
What you need to do is declare a LONG variable and provide its address -
LONG highValue; SetFilePointer(..., ..., &highValue, ...);
You can also pass a nullptr, if you're not intersted in that value.
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013)