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
Solved

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

Posted on 2004-09-07
7
895 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

839 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