Solved

execution error : Invalid Address specified to RtlValidateHeap( 003F0000, 00379488 )

Posted on 2004-09-07
7
882 Views
Last Modified: 2012-05-05
I work on a project in which I use an external library which allows me to control a device.
In the documentation of the library, they say that we have to set "use runtime libraries" to "multithreaded dll" in project->settings->code generation

Before I added this library I used the runtime library "multithreaded". I kept this option because people at my work who used the same library as the one I want to add made it work with this setting.

The problem that I face is that when I execute my program (with the "multithreaded" option) I get the following execution error :
HEAP[name.exe]: Invalid Address specified to RtlValidateHeap( 003F0000, 00379488 )

I have read in msdn and other places that this could be due to the fact that I use the "multithreaded" runtime library instead of "multithreaded dll", so I tried to change that and now I get the following linker's errors :

libcmtd.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
...
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "libcmtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

So I tried to ignore the libraries "msvcrtd.lib", "libcmtd.lib", but it created linking errors (unresolved external symbols) in libraries included in my projects.

Could anyone suggest me something to solve this ? Could it be possible to either solve the linking problem with the "multithreaded dll" runtime library, or either suppress the execution error (the heap thing) with the "multithreaded" runtime library ?

Thanks for your help




 
0
Comment
Question by:zazarb
  • 3
  • 3
7 Comments
 
LVL 13

Assisted Solution

by:SteH
SteH earned 500 total points
ID: 11996193
The linking errors come from the fact that now multithreaded (libcmtd) and multithreaded dll (msvcrtd) versions of the same (C Run Time) libraries are used. Only one is needed: the msvcrtd.lib should be included and libcmtd should be ommited. Can it be that other parts of that project are still using multithreaded non dll versions of the CRT libs?

The other problem is in connection with this: the heap has different blocks; one is used for multithreaded and another for dll version of the allocation functions. Allocations with one function can't be deallocated with a function from the other lib.
0
 

Author Comment

by:zazarb
ID: 11996706
Thanks for your answer, but when I ignore libcmtd.lib only (with the"debug multithreaded dll" runtime library), I still get a linking error :
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
nafxcwd.lib(olelink.obj) : error LNK2001: unresolved external symbol __mbctype
libcimtd.lib(filebuf.obj) : error LNK2001: unresolved external symbol ___pioinfo
name.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
0
 
LVL 13

Assisted Solution

by:SteH
SteH earned 500 total points
ID: 11996810
There are two choices to make for including CRT libraries:
single threaded, multi threaded and multi threaded dll is one list of choices. The other list is:
without STL, STL or old style STL support.
libcimtd.lib is old style STL (iostream support [#include <iostream.h>]) for multithreaded static linking.
nafxcwd is the mfc static link library.

It seems that you need to sort out what librarries are needed. Dependency walker is a great help when used on compiled (or better linked) code.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:zazarb
ID: 12090838
I have found out new things concerning the problem I have.
I use a library which handles a commercial device. This library is supposed to work only in multithreaded dll.
I use another library for my project which works only in multithreaded -non dll.

I managed to make my program work in release version, the linker error happen only in debug version. It is a hassle if I want to debug other parts of my app...
So I wondered : is there a way to work in debug version, and specify that a specific subpart of the project must be considered in its release version ? (For example, is it completely stupid to use the release versions of the commercial library in debug mode ?).
Thanks


0
 
LVL 13

Accepted Solution

by:
SteH earned 500 total points
ID: 12100157
You want get a debut version of the commercial library in most cases anyhow. So NO, its not stupid at all.

The bigger problem is to match CRT calls: A free from MT DLL will likely not work on pointer malloced with the static MT version (Same for new and delete). So you have to put the allocation and deallocation in parts with the same CRT version. This could be done by creating a DLL with the same convention as the part it inlcudes; ie create DLL statically linked MT and call the other library only from this DLL. The remainder of your app should then be MT DLL and can safely call the commercial DLL.

Differences in commercial and release version of libraries and you app should only manifest in the place where an error is detected. In debug some can be caught by ASSERTs, others by memory guards added whereas in the release version you likely find them when hitting a bad memory which doesn't need to be related to the actual position it occured.
0
 

Author Comment

by:zazarb
ID: 12306183
Actually I was able to solve the problem, but by cheating with the commercial lib (ie finding other libs that could replace it where there were memory leaks). I guess the pb really came from internal pbs in the lib, which forced you to work in a specific configuration...
Thanks anyways for the info given in the posts, I learned things I didn't know.



0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

10 Experts available now in Live!

Get 1:1 Help Now