Solved

Loading the local msvcrt.dll instead of the system one

Posted on 2000-03-01
4
622 Views
Last Modified: 2013-12-03
I am experiencing problems with an MFC executable built in VC6.  It needs to make use of DLLs that were built with VC4.1.  I am getting Access Violations at odd times, and I strongly suspect that there is an incompatibility between the exe and the DLLs that is causing heap corruption somehow - a couple of MSDN articles mention that this can happen when VC6 and VC4 programs share the same VC4 version of msvcrt.dll.

What I notice is that the VC6 executable, even though it has the msvcrt.dll version 6 in its local directory, is nevertheless using the msvcrt.dll version 4 that is in the system directory.  Other processes are using the version 4 DLL.  What I want is to make my VC6 program use the VC6 msvcrt.dll that is in its directory.  

I understand that normally, even if DLL 'X' is loaded in a process, another process will still load its local version of DLL 'X'.  Is this different for msvcrt.dll?  Is there a way around this?   I am using NT Server 4.

0
Comment
Question by:mcglinchey
  • 2
4 Comments
 
LVL 1

Expert Comment

by:JMu
ID: 2573327
To solve this problem, don't use msvcrt.lib. Use libcmt.lib for Release version and libcmtd.lib for Debug version. This includes the RTL into your application.

JMu
0
 

Author Comment

by:mcglinchey
ID: 2573347
This sounds like a good idea, but I was under the impression that MFC applications can only be linked with the run-time msvcrt.dll.  When I go Project->Settings->C/C++->"Use run-time library" and choose "multithreaded" instead of "multithreaded DLL", then the compiler complains with:

"fatal error C1189: #error :  Please use the /MD switch for _AFXDLL builds"

Is there another way to statically link with the C run-time libs?
0
 
LVL 1

Expert Comment

by:JMu
ID: 2573405
C++ code generation: Use run-time library: Multithreaded

Link Input: add libcmt.lib to Object/library modules.

Build your application. If linker shows duplicate symbol errors, add msvcrt.lib to Ignore libraries. I have never tried this.

BTW. I always check Ignore all default libraries, if I write non-MFC application.

JMu
0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 2574773
INFO: Windows NT Uses KnownDLLs Registry Entry to Find DLLs
http://support.microsoft.com/support/kb/articles/Q164/5/01.asp
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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