Solved

Loading the local msvcrt.dll instead of the system one

Posted on 2000-03-01
4
614 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

16 Experts available now in Live!

Get 1:1 Help Now