LPCTSTR in main() and then being able to pass it to OpenDrive(). Great!
"Gerry Hickman" wrote:
Hi,
I have the following code:
const TCHAR* const filename = _T("\\\\.\\PhysicalDrive2");
HANDLE hDevice = CreateFile(filename,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
This seems to work, but the first line is messy, is there a more simple
way to write it?
You mean content? Perheps not so messy, I think :) This is what you have to
have.
I eventually want to allocate the 'filename' variable in main() and pass
it to a function which will use CreateFile(), what's the best way to set
that up?
You've already allocated it. What is missing is the function to pass the
string to.
It's simple;
HANDLE OpenDrive(LPCTSTR szDrive)
{
return CreateFile(szDrive,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
}
// then inside main;
LPCTSTR filename = _T("\\\\.\\PhysicalDrive2");
HANDLE hDrive = OpenDrive(filename);