Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Access Violation Quandry

Posted on 1998-06-06
Medium Priority
Last Modified: 2013-11-19
Question by:oceanic
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
LVL 11

Expert Comment

ID: 1316128
Function calls don't randomly happen. You've either got a bogus version of your DLL lying around someplace (perhaps locked in memory by an instance of your app that crashed and wasn't terminated correctly), or you're linking with the wrong import LIB files, or your code is really explicitly or explicitly calling the function.

Those are the only possible causes; you have to figure out which one is happening and remedy it. If you haven't found it yet, you're not looking hard enough, or not looking at the right places.

B ekiM


Author Comment

ID: 1316129
You don't suppose I could find a problem beyond your reach?  My first instinct was to be unprofessional and simply say, "bite me".  I will refrain from making it official, and simply point out that after I read your unhelpful (and arrogantly rude) reply, I went immediately and rebooted my system (to make sure and clear the "bogus" dll that somehow survived other reboots in between all those days I have spent on this problem).  I then proceeded to the "Find->Files or Folders..." option on the Start menu and located each and every last copy of *all* of my DLLs and deleted them.  I then performed another search for *all* of my .LIB files and deleted them.  Again, anywhere they existed on my entire system, I deleted them.  I then removed the blindfold from my eyes and turned my chair around 180 degrees to face my monitor.  I also plugged in and turned on my monitor, to make sure that the code which I had typed in over the last several weeks was something I was familiar with; I didn't find any "explicit calls to functions" (in your words) where I hadn't intended them.  I then walked out in the backyard and looked around *real hard* to see if maybe my code problem was under any rocks (because I hadn't looked under rocks, just in trees so far).  Didn't find it.  Gee, I was shocked.

Read my original message again.  I already answered every one of your "suggestions".

My code still got the same Access Violation in the same exact place after having done another full rebuild (and of course after all those steps I listed for you above).  But maybe I haven't looked hard enough...

Oh, I'm open to input and help, but in my opinion your reply was neither.  For other readers, let me state for the record that it may be something I have overlooked, but the problem has forced me to spend many hours "weeding out" the simpler possible (and probable) causes.  I am seeking an answer from someone who has experienced the same phenomenon.  Maybe it's a strange bug in MFC, as there have been plenty of them over the years.  If anyone else has any ideas, please let me know.  I figured from the beginning that I would need to provide more detail or examples, as it is not a simple problem.  If it was, I wouldn't have posted my first request.

And advice to the "experts" (especially any self-proclaimed ones)...don't reply to a question as if someone is an idiot.  Maybe they've spent days and weeks on the issue, losing sleep over it and maybe they happen to know what they're doing in general.  Geez, maybe they do...

If I heed no other advice, I should at least stop ranting now.  I may have started a fire that shouldn't be burning here, and for that I apologize, but I know I am not the first to ask an honest question and get something worse than a wrong answer.
LVL 11

Expert Comment

ID: 1316130
You say you don't call tis function at all?
OK, consider the following random thoughts:

Maybe you make indirect function calls (via a function pointer) and the pointer got garbled somehow and now points to the wrong address?

Maybe you overflow an object's bounds, overwriting it's vtable in the process?

You have the source to MFC.  Why don't you put a breakpoint in CView::OnCmdMsg() near line 171 and see what's going on?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Accepted Solution

alexo earned 750 total points
ID: 1316131
OK, got it.

The line that fails is probably (MSVC 4.2: VIEWCORE.CPP, line 171):
    bHandled = m_pDocument->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

The m_pDocument member pointer got trashed somewhere and calling a function through it gives an address that happens to be the address of your function.  (Another option is that the "this" pointer of the CView is invalid at the time of the call, which complicates matters).

Anyway, seems that your problem lies earlier in the call chain or even before, in another method altogether.  Try watching m_pDocument while single stepping.

Author Comment

ID: 1316132

Thanks for the reply.  I am going to give the things you suggest a try.  The only one I can mark off the list right away is the "pointer to function".  I am not currently using any in my code at the moment.  As for the rest of your ideas, I will try to post my findings when I get a chance to work with the code again (in between work hours this week).

I noticed last night that my tree ctrl class correctly inserts an item into the ctrl (without the access violation occurring) when I don't pass a CDatabase pointer to the overloaded constructor.  However, when I revert the code to how I want it to work, passing a CDatabase pointer, I get the weird access violation.  The CDatabase object itself is a public member of my CDocument.  I am doing a TreeCtrl->Function(&(m_pDoc->m_Database)) type of call.  The m_pDoc is initialized in my view:OnCreate function.  I don't know if this sheds any more light on the issue.

Also, I had many times stopped at breakpoints in the MFC source, and the access violation seems to happen when the window is being brought to the front of the z-order (which it then jumps to the same exact function in my database dll).  I didn't pursue this any further because it seems a symptom rather than the cause, but I will try and get more specifics.

Thanks again,

Author Comment

ID: 1316133
Correction to my response...the tree ctrl doesn't have an "overloaded constructor" as I mention.  (I typed the reply before I was fully awake.)  The tree ctrl has an overloaded *function* I am calling to populate it.  I am still using the GetTreeCtrl() call to get ahold of the tree ctrl.

LVL 11

Expert Comment

ID: 1316134
1. I was talking about the m_pDocument member of the CVeiw class (or one of it's descendants).

2. MFC uses virtual functions (which are really glorified pointers to functions) all over the place.  One overrun and you get the symptoms you mention.

Author Comment

ID: 1316135
Yes...a "public" apology to mikeblas for my earlier response (June 6, 1998).  mikeblas has helped me -- and others no doubt -- before and I would like to acknowledge (in hindsight) that I responded way too defensively and probably misinterpreted his reply.  I had spent many hours pulling my hair out over the related issue to no avail and was, I suppose, a bomb with a short fuse.

mikeblas, if you will accept my professional and sincere apology, I would appreciate it.

LVL 11

Expert Comment

ID: 1316136
I'm not sure: can you possibly see it from the "self-proclaimed expert's" side?  (Maybe the 10 months you've waited has provided you with some clarity.)

We have to walk the thinnest line. The information in your blitzkreig reply really wasn't in your original question: you never mentioned rebooting, or working for days, or deleting extra DLL copies, for example.

You mentioned that you did find in files; sure--but how am I to know you've done it correctly? I don't know you, or where you work, or what you know or don't know. How many times do you think I've answered questions from people who say they can't find the implementation of a particular MFC function because they don't know (or think to) search *.INL files? It's not outside of the realm of possibilities!

And so, I made a response that seemed appropriate. You didn't tell me what you'd done to solve the problem, and some of what you told me was (in my eyes) suspect. I had to start from square one.

When you answer questions like this, in whatever forum you answer them, you run the risk of insulting the questioner by asking questions that are too advanced, as well. I've been flamed many times by people who thought I was just out to embarrass them by suggesting they do things that they "obviously didn't understand".

Welp, how am I to know? In this case, you didn't tell me. So, I had to go with an assumption.  My other alternative is to ask you what you've done so far--and that's frequently interpreted as rude, too.

Would you do the same thing to your auto mechanic?

"It stalls."


"Bit me!  Obviously, it stalls when it's _running_!"

Welp, that doesn't give the mechanic the information he needs to know to formulate a diagnosis. Is the mechanic a pit chief talking to a seasoned NASCAR driver, or is it the Honda mechanic trying to help someone who's never touched a wrench?

I made the response I did because your question made the problem sound as if you were suffering from a random, unobservable event beyond your control. It turns out, you're not; and I pointed that out. Seperating a frustrated, emotional reaction (like yours) from the real facts is tremendously important in scientific fields, like this one.

I've been flamed like this before. Sometimes worse, sometimes not as bad. (Search for "blaszczak near prick" on DejaNews, for instance.) Somehow, I manage to find the strength to continue helping people, usually by reminding myself that the flamer doesn't know what life looks like from the tops of my shoes.

Of course, it's never very long before someone again proves my tenacity to be foolish, like someone who insists on cooking when they're tired of the heat in the kitchen.
.B ekiM


Author Comment

ID: 1316137
Again...sorry for the misunderstanding (and perhaps the grief).  The 10 months was simply the amount of time I stayed off of experts-exchange and yes, it did give me a better look at how I had way over-reacted.  I can understand your desire to clarify your approach to my original question, but whatever the case I wanted to sincerely apologize.

Honestly, I still didn't figure what was going on with the code because I didn't know any other places to look or things to try.  I got to the end of my endurance with it and decided to start the project over after some redesign.  By the time I get it developed, it'll be running on VC++ 8.5 or something...

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question