Click here to Skip to main content
15,886,740 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Disabling popup menu item [SOLVED] Pin
David Crow12-Jan-11 8:54
David Crow12-Jan-11 8:54 
AnswerRe: Disabling popup menu item Pin
Niklas L12-Jan-11 21:18
Niklas L12-Jan-11 21:18 
QuestionRe: Disabling popup menu item Pin
David Crow14-Jan-11 3:20
David Crow14-Jan-11 3:20 
AnswerRe: Disabling popup menu item [modified] Pin
Niklas L16-Jan-11 20:47
Niklas L16-Jan-11 20:47 
AnswerRe: Disabling popup menu item Pin
JohnCz14-Jan-11 12:56
JohnCz14-Jan-11 12:56 
Questionpreallocating logging files for performance purposes Pin
Alan Kurlansky12-Jan-11 4:36
Alan Kurlansky12-Jan-11 4:36 
AnswerRe: preallocating logging files for performance purposes Pin
Richard MacCutchan12-Jan-11 5:05
mveRichard MacCutchan12-Jan-11 5:05 
AnswerRe: preallocating logging files for performance purposes [modified] Pin
Andrew Brock12-Jan-11 5:15
Andrew Brock12-Jan-11 5:15 
You need to seek to what you want to be the end of the pre-allocated space, then set the EOF marker, then seek back to the start so you are writing from the beginning of the file, like so

HANDLE hFile = CreateFile("C:\\test", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
	SetFilePointer(hFile, 4 * 1024 * 1024, NULL, SEEK_SET); //seek to 4MB (pre-allocate 4MB)
	SetEndOfFile(hFile); //set the EOF to pre-allocate the space
	SetFilePointer(hFile, 0, NULL, SEEK_SET); //seek back to the start for writing
	//write to the file with WriteFile()
	CloseHandle(hFile);
}


Edit:
I missed part 3...
quite simply seek to the end of the data in the file to append to it.
SetFilePointer(hFile, 0, NULL, SEEK_END); //If you want to append to the end of the entire file (including after the pre-allocated space)
SetFilePointer(hFile, nDataLength, NULL, SEEK_SET); //if you are keeping track of the length of the data you have written to the file with the variable nDataLength


Writing to a file is pretty straight forward. You just need a buffer and the length of data you are writing
LPSTR szWrite = "hello world";
DWORD nLength = strlen(szWrite);
DWORD nBytesWritten;
WriteFile(hFile, szWrite, nLength, &nBytesWritten, NULL);
CloseHandle(hFile);


If you are writing strings in unicode you need to multiply the length by sizeof(wchar_t) or sizeof(TCHAR)

Finally, All file writes (and reads) are sequential for all APIs that I know of. It moves the file pointer to the end of the data you have just written (or read)
modified on Wednesday, January 12, 2011 11:23 AM

AnswerRe: preallocating logging files for performance purposes Pin
jschell12-Jan-11 8:39
jschell12-Jan-11 8:39 
Questionhow to show bookmarks in a popupmenu? Pin
yogish29312-Jan-11 0:47
yogish29312-Jan-11 0:47 
AnswerRe: how to show bookmarks in a popupmenu? Pin
Richard MacCutchan12-Jan-11 1:09
mveRichard MacCutchan12-Jan-11 1:09 
GeneralRe: how to show bookmarks in a popupmenu? Pin
yogish29312-Jan-11 1:38
yogish29312-Jan-11 1:38 
GeneralRe: how to show bookmarks in a popupmenu? Pin
Richard MacCutchan12-Jan-11 1:42
mveRichard MacCutchan12-Jan-11 1:42 
GeneralRe: how to show bookmarks in a popupmenu? Pin
yogish29312-Jan-11 1:57
yogish29312-Jan-11 1:57 
GeneralRe: how to show bookmarks in a popupmenu? Pin
Richard MacCutchan12-Jan-11 2:20
mveRichard MacCutchan12-Jan-11 2:20 
GeneralRe: how to show bookmarks in a popupmenu? Pin
Maximilien12-Jan-11 2:54
Maximilien12-Jan-11 2:54 
AnswerRe: how to show bookmarks in a popupmenu? Pin
User 742933812-Jan-11 1:14
professionalUser 742933812-Jan-11 1:14 
QuestionHow to create a Floating Image over another Image ? Pin
002comp12-Jan-11 0:46
002comp12-Jan-11 0:46 
AnswerRe: How to create a Floating Image over another Image ? Pin
Cool_Dev12-Jan-11 1:23
Cool_Dev12-Jan-11 1:23 
GeneralRe: How to create a Floating Image over another Image ? Pin
002comp12-Jan-11 1:52
002comp12-Jan-11 1:52 
GeneralRe: How to create a Floating Image over another Image ? Pin
Cool_Dev12-Jan-11 2:22
Cool_Dev12-Jan-11 2:22 
QuestionGet Document IDispatch in native C++ (possibly using MFC ActiveX Control) [modified] Pin
T210211-Jan-11 21:37
T210211-Jan-11 21:37 
Questionhelp on control update from worker thread Pin
ashwani_gupt11-Jan-11 21:07
ashwani_gupt11-Jan-11 21:07 
AnswerRe: help on control update from worker thread Pin
Cedric Moonen11-Jan-11 21:13
Cedric Moonen11-Jan-11 21:13 
GeneralRe: help on control update from worker thread Pin
ashwani_gupt11-Jan-11 21:31
ashwani_gupt11-Jan-11 21:31 

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.