Problem using DLLs (debug mode)

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.
svillalbaAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
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
 
MukkiCommented:
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
 
jkrCommented:
>>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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
mblatCommented:
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
 
mblatCommented:
Sorry jrk - we posted latest comments at the same time - if it is the answer it is yours.
0
 
jkrCommented:
Well, I explained the problem 15min earlier :o)
0
 
jkrCommented:
Thank you --- WHY in all the world a "C"?
0
 
svillalbaAuthor Commented:
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
 
mblatCommented:
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
 
svillalbaAuthor Commented:
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
 
MoondancerCommented:
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
 
MoondancerCommented:
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
 
mblatCommented:
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
 
MoondancerCommented:
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
 
svillalbaAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.