Solved

Loading the local msvcrt.dll instead of the system one

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

912 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

24 Experts available now in Live!

Get 1:1 Help Now