J
Jon
I want to fill an edit control from a text file. I need help debugging
a couple of runtime errors: "Stack around the variable txtFromFile was
corrupted" and an access violation in ReadFile(). Ideas?
/////////////////////////////////////////////////////////////////////////////////
char szFileName[MAX_PATH] = "";
LPCSTR txtFromFile;
DWORD bytestoread = 1024;
DWORD bytesread;
if (LOWORD(wParam) == ID_BROWSE)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hDlg;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files
(*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if (GetOpenFileName(&ofn))
{
HANDLE hFile = CreateFile(szFileName, GENERIC_READ, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (ReadFile(hFile, &txtFromFile, bytestoread, &bytesread,
NULL))
{
SetDlgItemText(hDlg, IDC_EDIT1, txtFromFile);
}
CloseHandle(hFile);
return true;
}
}
/////////////////////////////////////////////////////////////////////////////////
a couple of runtime errors: "Stack around the variable txtFromFile was
corrupted" and an access violation in ReadFile(). Ideas?
/////////////////////////////////////////////////////////////////////////////////
char szFileName[MAX_PATH] = "";
LPCSTR txtFromFile;
DWORD bytestoread = 1024;
DWORD bytesread;
if (LOWORD(wParam) == ID_BROWSE)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hDlg;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files
(*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if (GetOpenFileName(&ofn))
{
HANDLE hFile = CreateFile(szFileName, GENERIC_READ, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (ReadFile(hFile, &txtFromFile, bytestoread, &bytesread,
NULL))
{
SetDlgItemText(hDlg, IDC_EDIT1, txtFromFile);
}
CloseHandle(hFile);
return true;
}
}
/////////////////////////////////////////////////////////////////////////////////