Solved

Problem using DLLs (debug mode)

Posted on 2002-04-30
15
331 Views
Last Modified: 2013-11-20
I have a problem with a DLL in debug mode. When the application that use the DLL starts (in debug mode), it crashes showing the message Debug Assertion Failed.  Program .... Expression: _CtrlIsValidHeapPointer(pUserData).
In release mode the application works correctly (the DLL is in release mode too).
The error is caused by an ASSERT sentence (only available in debug mode).

I would like to know what is the reason of this error, and how I could resolve it.
0
Comment
Question by:svillalba
  • 4
  • 4
  • 3
  • +2
15 Comments
 
LVL 1

Expert Comment

by:Mukki
ID: 6981019
I had a similar problem with one DLL. It was build for release mode. Debug allocation routines are different for Release and Debug builds. I turned off debug allocation routines for debug builds.
Check _AFX_NO_DEBUG_CRT define.

Hope that helps.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6981049
>>I would like to know what is the reason of this error, and how I could resolve it.

The reason is that you are trying to free memory that was allocated in another module. Each exe/dll has it's own allocator/heap unless you change the project settings to use the CRT as a DLL. The memory you are tryng to free is from a different heap, thus the assertion. In Release mode, you'll have a memory leak.
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 6981115
BTW: To avoid that, select "Use Runtime Library: Multithreaded DLL" for both the applcation and the DLL - this makes both load the CRT as a DLL, so they share the same allocators.
0
 
LVL 4

Expert Comment

by:mblat
ID: 6981117
Assuming you are using VC++.

I had simular problem, the reason for it was that I was using different type of MFC DLL for .exe and .dll.

Go to Project->Settings->C++

In category "Code generation" make sure that you using same "run-time library" for all of mudules in your project.

Hope it helps.
0
 
LVL 4

Expert Comment

by:mblat
ID: 6981124
Sorry jrk - we posted latest comments at the same time - if it is the answer it is yours.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6981135
Well, I explained the problem 15min earlier :o)
0
 
LVL 86

Expert Comment

by:jkr
ID: 6981183
Thank you --- WHY in all the world a "C"?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:svillalba
ID: 6981218
Thank you for your answer and sorry for the "C". I didn't mind to choose an "A", but I think "C" is more appropriate. mblat tells me how to resolve the problem (project -> settings -> C++ and so on), whereas you only tell me the reason of the error.
0
 
LVL 4

Expert Comment

by:mblat
ID: 6981255
you know jrk - I kind of glad that that you answered this question first.  :-)

to svillalba:

jrk gave you THE answer.  If you thought that my comment provided you with usefull info you should've gave me some points, either by posting it as separate question or by splitting points you already allocated.  Not to lower grade on perfectly good answer....
0
 

Author Comment

by:svillalba
ID: 6981293
I don't understand why I should have gave an "A" to jrk. I'm grateful to jrk, Mukki and you for your answer. But I thought a "C" was the most appropriate option, that's all. I don't know why is so important.
I accepted his answer because was earlier than yours, but I think your answer is more complete.
Another thing, I don't know how to split points (I didn't know that was possible to do it). I think it was a very good option. As for the other option (posting a separate question) I'm not agree with you, because I think is not a good idea to make blank questions only for points. It's annoying for another users.

Thanks again.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6981766
svillalba -->  Greetings, I see you are fairly new to this site, and some clarification is needed.

The goal is for you to get what you need and to award the first expert who gives you the solution which helps you achieve that goal.  Everyone here strives to deliver "A" level (excellent) information and no one I know of appreciates receiving the lowest grade we have, which is the "C" grade.  In fact, it is always requested that if you feel you have received less than "A" level results, that you let the participating experts know this before you close and grade a question so that they can add what you need to achieve excellence.  The points you assign to a question are always the same, but the points which flow to the experts are a direct result of the grade given.  Example:  100 point question and A = 400 expert points, b = 300, C=200.  Equally important is the fact that some expert look at Asker's grading history and if they see low grades in history, choose not to step in and help.  The total information contained in this question clearly is "A" level information.  Once a questions has been graded, it moves to our PAQ where others can access the information to get help.  Few would consider looking at a "C" question if "A" questions exist, so the grades have even more of an impact than noted earlier.

Any time more than one expert helps you we are happy to process "point splits" for their contributions.  This is done frequently and absolutely the right way to go.  Perhaps that is what should have been done here, and assuming so, I can correct this.

Please check these links for more site-related guidance.
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
http://www.experts-exchange.com/jsp/infoMemberAgreement.jsp

I have changed this grade, and will await a response to process a point split/share adjustment.

Moondancer - EE Moderator
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6981780
Points for Mukki -> http://www.experts-exchange.com/jsp/qShow.jsp?qid=20295576
Points for mblat -> http://www.experts-exchange.com/jsp/qShow.jsp?qid=20295577

I have processed these points for the other two participants here, and did not charge the Asker for these adjustments.

Moondancer - EE Moderator
0
 
LVL 4

Expert Comment

by:mblat
ID: 6981787
Just a small clarification here:  I wasn't asking for any points split, I consider jrk answer complete enough.

I was just pointing to svillalba, that that was an option.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6982204
Understood, I processed the point shares nonetheless for contributions made here and did not charge svillalba.  svillalba now had been advised that Point Split options exist and that to request one, a zero point question in Community Support will receive Moderator assistance.
Moondancer - EE Moderator
0
 

Author Comment

by:svillalba
ID: 6987962
I have read the right method to point the answers and I am agree with Moondancer, mblat and jkr. I should have pointed the question with an "A". Sorry for my mistake and thank you for the explanation.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now