Jonathan Wilson wrote:
I have the following:
This doesn't appear to be a dotnet (e.g. C++/CLI or managed C++)
question, so would be better in microsoft.public.vc.language. Anyway:
1.A C++ dll (with no managed code whatsoever) compiled with visual C++
2005 that links to libcmt.lib as its runtime library.
libcmt.lib is the static multithreaded CRT, right?
and 2.A piece of binary code (also compiled with visual C++ 2005) that I
cant change or have changed which calls a certain c runtime function
(for arguments sake, lets call it xyz)
What do you mean by a 'piece of binary code'? Do you mean a VC++2005
..obj file? A static library? An exe or dll?
If it's an obj or lib, does you C++ dll have any relationship to it? For
example, does the DLL need to call functions in this binary code?
What I want to do is to tell the linker "don't use the implementation of
xyz inside libcmt.lib, use the implementation of xyz inside myobj.obj
instead." Is this possible? If so, how?
Note that this has to be something that can be done automatically
without any extra human steps other than the usual "build-build
solution" and it must not require modifying the visual C++ install (e.g.
recompiling or modifying the CRT is out of the question) or the binary
part mentioned above.
Ok, I think you have some compiled code (a .lib or .obj which I'll call
X) which contains some functions you need to call from your DLL. Right?
If that's the case, you can do this:
Create a second DLL which includes exported functions that are wrappers
for the required functions of X. This DLL links statically with X, and
includes myobj.c (or .obj). This DLL includes X in the linker settings
as well as libcmt.lib (using /MT). Finally, to resolve any multiple
definition errors, use /FORCE:MULTIPLE in the linker commandline - the
one defined in the project (myobj.c) should take precedence.
Now your DLL can just link to this, and is completely isolated from the
hacking that is used in the second DLL, but note that they will have
separate CRT heaps and other CRT state, so don't go allocating memory in
one DLL and freeing it in the other.
Tom