473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Access violation

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

/////////////////////////////////////////////////////////////////////////////////

Nov 17 '05 #1
3 1298
Hi 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?

LPCSTR txtFromFile;
...
if (ReadFile(hFile, &txtFromFile, bytestoread, &bytesread,
NULL))


Where do you store the read-data?
txtFromFile is just a pointer...

You need to do something like:

char *szBuffer[1024];
DWORD bytesToRead = 1024;

Now you can pass "szBuffer" to ReadFile:
ReadFile(hFile, szBuffer, bytesToRead, &bytesRead, NULL)

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Jon
Thanks, got it.

Jon

Nov 17 '05 #3
Jon
Thanks, got it.

Jon

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Steven Reddie | last post by:
I understand that access violations aren't part of the standard C++ exception handling support. On Windows, a particular MSVC compiler option enables Microsoft's Structured Exception Handling...
0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
5
by: Alex | last post by:
Hello Im working on project for my college, nevermind (but it urgent :((()... So I have this code example (in VS 6.0) in main class : REAL *Input; ....
7
by: Daniel | last post by:
I want to write a method to remove the last node of the linked list. But the error "Access Violation" exists and the error point to this method. What does it means by Access Violation and how can...
0
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a...
1
by: Thomas Albrecht | last post by:
My application fails during initialization of the dlls with an ExecutionEngineException and a access violation in the MFC app. The structure of the program looks like: MFC app -> mixed DLL ->...
1
by: BillyO | last post by:
In the attached code fragment I have a buffer overflow and a memory access violation. When I run the code .Net fails to verify the IL because of the buffer overflow and I get an exception as...
2
by: Boris Fortes | last post by:
I need to unhook event receiver as result of native C++ event. It unhooks successfully, but __raise does not return and throws access violation. Visual Studio 2003 How to reproduce: Consol...
2
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.