Ai giúp tui debug đoạn mã này đi!

lamtacla

Donkey Kong
Tham gia ngày
24/10/04
Bài viết
340
Reaction score
2
Xài Visual C++ 6, mục đích là tạo 1 file và ghi 4 byte "yeah" vào đó:
Mã:
	HANDLE hFile;
	DWORD numByteWritten;
	char* buff = "Yeah";
				
	hFile = CreateFile("D:\\a.txt",     // file to create
                   GENERIC_WRITE,          // open for writing
                   0,                      // do not share
                   NULL,                   // default security
                   CREATE_ALWAYS,          // overwrite existing
                   FILE_ATTRIBUTE_NORMAL | // normal file
                   FILE_FLAG_OVERLAPPED,   // asynchronous I/O
                   NULL);                  // no attr. template

	if (hFile == INVALID_HANDLE_VALUE) return;
				
	int r = WriteFile(hFile,buff,4,&numByteWritten,NULL);
	if(r == 0) DWORD e = GetLastError();
	CloseHandle(hFile);

Đơn giản vậy thui... kô hiểu tui làm sai chổ nào mà cái file tạo ra chẳng có dữ liệu. Giá trị r hàm WriteFile trả về = 0 và Error code = 87 (ERROR_INVALID_PARAMETER). Ai biết giúp giùm tui nhé, thx nhìu.
 
Giá trị r hàm WriteFile trả về = 0 và Error code = 87 (ERROR_INVALID_PARAMETER). Ai biết giúp giùm tui nhé, thx nhìu.
Bạn có thấy là cái lỗi nó đã đưa ra ko ? Tham số bạn đã truyền vào sai rồi , coi lại đi
 
Back
Top