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;}
}

Write a text file with Visual Studio
unknown311
Kuphryn
Tigger99
Jez9999
Kuphryn
Ska Software
Michael Ruminer
Hi, well, nost so good news. Now I am writing the file. The new problem is that in that way (*sizeof(TCHAR)) each character is written as 2 characters, the other is a white space. That is not what I a want to do. I thought the problem was that I am using LPWSTR instead of LPSTR (the original type of the Microsoft sample) but if I change my code as shown below I only get a compiling error:
error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'LPSTR' to 'LPWSTR'
This is my new code
if(dwText1Length > 0)
{
LPSTR pszText;
DWORD dwBufferSize1 = dwText1Length + 1;
pszText = (LPSTR)GlobalAlloc(GPTR, dwBufferSize1);
if(pszText != NULL)
{
if(GetWindowText(hEdit1, pszText, dwBufferSize1)) //Here's the error and the parameter with problems is pszText
{
DWORD dwWritten;
if(WriteFile(hDestFile, pszText, dwBufferSize1*sizeof(wchar_t), &dwWritten, NULL))
bSuccess = TRUE;
}
}
}
GraemeH
tschissler