473,473 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

overriding C runtime functions with my own implementation

I have the following:
1.A C++ dll (with no managed code whatsoever) compiled with visual C++ 2005
that links to libcmt.lib as its runtime library.
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 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.
Jan 16 '07 #1
3 1843
Hi Jonathan!
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?
See my CRT-Improvement:
http://www.codeproject.com/cpp/improved2005crt.asp

Greetings
Jochen
Jan 16 '07 #2
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
Jan 16 '07 #3
Jonathan Wilson wrote:
I have the following:
1.A C++ dll (with no managed code whatsoever) compiled with visual C++
2005 that links to libcmt.lib as its runtime library.
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 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.
If you define the function in your source files, they take precedence
over any same named library function.

Try this:

#include <stdio.h>

int printf (const char *format, ...)
{
// blank implementation
return 0;
}

int main (int argc, char *argv[])
{
print("Hello world!");
}

then compile it and see if it uses your function or library.

If you cannot relink the project, you should look into API hooking. It's
a hacker technique that relies on overwriting JMP instructions in DLL
import table. Google it up.

Roman
Jan 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Edward Diener | last post by:
Is it possible for a derived class to override a property and/or event of its base class ?
3
by: David Chandler | last post by:
Let me try to describe the situation as clearly as I can. In namespace XXX I have a class PARENT with the following public functions: virtual void foo( const char* stringBuf ); // set...
1
by: Xiangliang Meng | last post by:
Hi, all. When reading C++ books, I'm alway confused by those terms "redefining functions", "overloading functions" and "overriding functions". Please give me some comments on those terms....
11
by: Michael | last post by:
Hi, As an exercise, I created a class C that duplicates a value x thus having x_val1 and x_val2 I also overrided the + operator so that if I have z = x + y (x,y and z belong class C) then + ...
2
by: franklini | last post by:
hello people i. can anybody help me, i dont know what is wrong with this class. it has something to do with the me trying to override the input output stream. if i dont override it, it works fine....
15
by: Susan Baker | last post by:
Hello everybody, I'm new to C++ (I have some C background). I've read up on this topic a few times but it just dosen't seem to be sinking in. 1. Whats the difference between overloading and...
3
by: Eric Chaves | last post by:
Hi fellows, According to the C# language specification (10.5.3), Every virtual method has a "most derived implementation" determined by a 3-step rule. If I invoke the virtual method from a normal...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.