Write a text file with Visual Studio
Hi, I am trying to write a function thats save to a text file the text I wrote in an EditBox of my main dialog. I tried many ways but the only approach that seems to work is through the code that I detail below. Still I could not write down the whole text, the last three characters are not written!!!, What I am doing wrong?. Is there any way of doing this more easily?. I am using Visual Studio C++ 2005 Express Edition and if i try to use fopen compiler tell me is a deprecated method, so I don't want to use it.
Thanks in advance.
HRESULT RecordAuxTextData(HWND hDlg)
{
HANDLE hDestFile = INVALID_HANDLE_VALUE;
BOOL bSuccess = FALSE;
// Open destination filehDestFile = CreateFile (TEXT(
"c:\\RASITSonidos\\myfile.txt"), GENERIC_READ|GENERIC_WRITE, 0,0, CREATE_ALWAYS, 0, 0);
if (INVALID_HANDLE_VALUE == hDestFile){
return FALSE ;}
else{
// Obtengo el contenido del textboxDWORD dwTextLength;
HWND hEdit = GetDlgItem(hDlg, IDC_EDIT1);
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength > 0){
LPWSTR pszText;
DWORD dwBufferSize = dwTextLength + 1;
pszText = (LPWSTR)GlobalAlloc(GPTR, dwBufferSize);
if(pszText != NULL){
if(GetWindowText(hEdit, pszText, dwBufferSize)){
DWORD dwWritten;
if(WriteFile(hDestFile, pszText, dwBufferSize, &dwWritten, NULL))bSuccess = TRUE;
}
//GlobalFree((HGLOBAL)pszText);}
}
CloseHandle(hDestFile);
return S_OK;}
}

