Click here to Skip to main content
15,887,453 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Using stdafx.h in multiple directories Pin
raghavr22-Mar-05 16:50
raghavr22-Mar-05 16:50 
GeneralRe: Using stdafx.h in multiple directories Pin
Blake Miller3-Mar-05 6:07
Blake Miller3-Mar-05 6:07 
Generalbluetooth programming Pin
Member 16324381-Mar-05 0:25
Member 16324381-Mar-05 0:25 
Generalwmi Pin
ozgul28-Feb-05 22:52
ozgul28-Feb-05 22:52 
GeneralRe: wmi Pin
Steve Thresher1-Mar-05 1:52
Steve Thresher1-Mar-05 1:52 
GeneralRe: wmi Pin
ozgul1-Mar-05 2:49
ozgul1-Mar-05 2:49 
GeneralRe: wmi Pin
Aamir Butt2-Mar-05 0:01
Aamir Butt2-Mar-05 0:01 
GeneralGetting a bit frustrated with Readfile/Writefile Pin
User 137680028-Feb-05 22:46
User 137680028-Feb-05 22:46 
Hi all,
I recently was helped out here and given a pointer to use Createfile/Readfile/Writefile for my direct disk access in a bit of code I'm working on...

Unfortunately, while it seems fairly straightforward, I'm having a few difficulties.

The following is my code (with all error checking and other superfluous bits removed, just for clarity - but they are really there!).

I can't for the life of me figure out why this doesn't work. It should simply:
1 - Open the A drive for reading (this does seem to happen)
2 - Open c:\file.img for writing (this does seem to happen)
3 - Read 256bytes from the A drive in to a buffer (actually only doing 256bytes during testing... what I really want it to do is get the size of the disk using GetDiskFreeSpaceEx, then use that as the size to read/write so it does the whole disk)
4 - Write these 256bytes back to c:\file.img

What ends up happening is that I get 256bytes of what appears to be random garbage written in to the file... so it's writing, but WHAT it's writing and where it's getting it from I have no idea...

It's likely the problem lies in a fundamental failure to understand how this process is supposed to work. Therefore, this is probably something insanely simple and I'm going to feel like a complete moron, but as a relative beginner in C++ (despite the scary concept that I now do it "officially" for work) I think I'm entitled to be a moron on rare occasions Wink | ;)

<br />
	//Step 1: Open the drive for reading<br />
	HANDLE hDriveRead;<br />
	hDriveRead = CreateFile(TEXT("\\\\.\\a:"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br />
 <br />
	//Step 2: Open the file for writing<br />
	HANDLE hFileWrite;<br />
<br />
	hFileWrite = CreateFile(TEXT("c:\\file.img"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);<br />
<br />
	//Step 3: Read the drive and write to the card<br />
	DWORD dwImageBuffer[256];<br />
	DWORD nBytesToCopy=256;<br />
	DWORD nBytesRead;<br />
	DWORD nBytesWritten;<br />
	ReadFile(hDriveRead, dwImageBuffer, nBytesToCopy, &nBytesRead, NULL);<br />
	//I want to perform extra processing on the file here, but lets pretend for now that I don't.<br />
	WriteFile(hFileWrite, dwImageBuffer, nBytesToCopy, &nBytesWritten, NULL);<br />
<br />
	CloseHandle(hFileWrite);<br />
	CloseHandle(hDriveRead);<br />


Any help would be greatly appreciated.
GeneralRe: Getting a bit frustrated with Readfile/Writefile Pin
Michael Dunn1-Mar-05 1:42
sitebuilderMichael Dunn1-Mar-05 1:42 
GeneralRe: Getting a bit frustrated with Readfile/Writefile Pin
User 13768001-Mar-05 8:32
User 13768001-Mar-05 8:32 
GeneralChanging colours of a combo box (reposted) Pin
Alton Williams28-Feb-05 22:31
Alton Williams28-Feb-05 22:31 
QuestionHow to get the full Path from GetDisplayName Pin
Lonely Byte28-Feb-05 22:08
Lonely Byte28-Feb-05 22:08 
AnswerRe: How to get the full Path from GetDisplayName Pin
Ravi Bhavnani1-Mar-05 4:32
professionalRavi Bhavnani1-Mar-05 4:32 
GeneralRe: How to get the full Path from GetDisplayName Pin
Lonely Byte1-Mar-05 19:40
Lonely Byte1-Mar-05 19:40 
QuestionHow to manipulate bitmap in a View? Pin
kokehqyu28-Feb-05 20:38
kokehqyu28-Feb-05 20:38 
AnswerRe: How to manipulate bitmap in a View? Pin
Selvam R28-Feb-05 22:29
professionalSelvam R28-Feb-05 22:29 
GeneralRe: How to manipulate bitmap in a View? Pin
kokehqyu1-Mar-05 13:50
kokehqyu1-Mar-05 13:50 
GeneralInitially visible dialog box Pin
Kapgan28-Feb-05 20:16
Kapgan28-Feb-05 20:16 
GeneralRe: Initially visible dialog box Pin
zhang80060528-Feb-05 20:47
zhang80060528-Feb-05 20:47 
GeneralRe: Initially visible dialog box Pin
Kapgan1-Mar-05 0:24
Kapgan1-Mar-05 0:24 
GeneralRe: Initially visible dialog box Pin
Ed K1-Mar-05 10:58
Ed K1-Mar-05 10:58 
GeneralUDP transfer Pin
Raghav SR28-Feb-05 19:21
Raghav SR28-Feb-05 19:21 
GeneralRe: UDP transfer Pin
Alexander M.,1-Mar-05 5:14
Alexander M.,1-Mar-05 5:14 
GeneralMedia Gateway's in VoIP Pin
Raghav SR28-Feb-05 19:18
Raghav SR28-Feb-05 19:18 
Generalon using SSL components Pin
ppp00128-Feb-05 15:58
ppp00128-Feb-05 15:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.