Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a problem of access violation

Status
Not open for further replies.

jayjay60

Programmer
Jun 19, 2001
97
FR
Hello everybody,

In a new application, which a dialog box application i have a message error which appears and which tell me:

" Unhandld exception in Fractal_v1_0.exe(MSVCRTD.DLL):0xC0000005:Access Violation"

(Fractal_v1_0 is the name of my project!)

So, i meet often the problem "Access Violation" caused by mistake in memory allocation for different pointers, but here i don't understand!

so if someone could help me!

thanks in advance for your answers

jayjay60
 
Do you mean you don't understand the error occurs in MSVCRTD.dll and not in your program? Well, for example try this: strcat ( NULL, NULL ); Access violation guaranteed, and it will occur in one of the C runtime libraries, because it is detected there. The real error however, is in your program. If you want help with this you must give us some code.

Marcel
 
Without seeing some code, the only thing I can think of is the following scenario:

I'll use a hypothetical function called theFunc that takes a CComboBox* as a parameter.

Assume you encounter documentation that says "pass a pointer to a CComboBox in the call to theFunc(CComboBox* pCB)"

Do NOT do the following, this more than likely will give you the cheery "Access Violation" message (This fails because the pointer is not pointing to a valid CComboBox):

CComboBox* pCB // Invalid CComboBox pointer;

theFunc(pCB); // Oops! pCB is pointing to garbage!


This is what you should do (This works because oCB will be passed in a pointer to a valid ComboBox via the address of (&) operator):

CComboBox oCB;

theFunc(&oCB);


The following will work as well. (Note the difference between this and the first example (and remember to call "delete pCB;" BEFORE pCB goes out of scope otherwise you will have a memory leak!));

CComboBox* pCB; // Invalid CComboBox pointer

pCB = new CComboBox(); // Storage is allocated here. pCB is
// now pointing to a valid CComboBox.
theFunc(pCB);



If the function truly does take a pointer and not a pointer to storage, the function should be documented as (again note the pointer to pointer declaration):

theFunc(CComboBox** pCB);



Be very careful of this type of error. It is really easy to make this mistake (and I speak from first-hand experience with this!)

Happy coding! Hope this helps. :)

*~-> EOR Candy <-~*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top