Click here to Skip to main content
15,928,207 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionIs the Microsoft Foundation Class (MFC) for me? Pin
~Ronin27-Sep-04 12:53
~Ronin27-Sep-04 12:53 
AnswerRe: Is the Microsoft Foundation Class (MFC) for me? Pin
Christian Graus27-Sep-04 13:51
protectorChristian Graus27-Sep-04 13:51 
GeneralRe: Is the Microsoft Foundation Class (MFC) for me? Pin
David Crow28-Sep-04 4:42
David Crow28-Sep-04 4:42 
GeneralI Give Up - Time/Date Help Pin
otrcomm27-Sep-04 12:26
otrcomm27-Sep-04 12:26 
GeneralRe: I Give Up - Time/Date Help Pin
PJ Arends27-Sep-04 14:20
professionalPJ Arends27-Sep-04 14:20 
GeneralRe: I Give Up - Time/Date Help Pin
Sujan Christo27-Sep-04 19:22
Sujan Christo27-Sep-04 19:22 
General"Overload" malloc Pin
Boniolopez27-Sep-04 11:30
Boniolopez27-Sep-04 11:30 
GeneralRe: "Overload" malloc Pin
Jörgen Sigvardsson27-Sep-04 12:00
Jörgen Sigvardsson27-Sep-04 12:00 
I'm not sure if this technique is possible in Windows, but it is under Unix with ELF loaders.

Write a shared library (.so - equivalent to .dll in Windows), in which you define extern "C" void* malloc(size_t s). Then have the shared library to be preloaded before all other DLLs are loaded. Then the linker will not link the system malloc since it has already been loaded.

To chain your malloc with the system's malloc, you simply load the system shared library dynamically in your shared library, and retrieve the pointer to the system's malloc.

So, in your DLL you will have code kind of like this:
void* (*real_malloc)(size_t);
 
DllMain() {
   HANDLE h = LoadLibrary("whichever_dll_that_contains_malloc.dll");
   real_malloc = (void*(*)(size_t))GetProcAddress("malloc");
}
 
extern "C" __declspec(dllexport) void* malloc(size_t s) {
   do_some_stuff();
   void* ptr = real_malloc(s);
   return do_something_more_perhaps(s);
}
Then have the linker preload this DLL. I'm not sure it's possible in Windows, but I have a hunch it is. I know it's possible to hijack DLLs, and that's basically what this is. Needless to say, you'll need to link against the runtime dynamically.

--
Suche Wissen über Alles.

Der Student

GeneralSorting issue with MMC on Win2000 Pin
SandeepN27-Sep-04 11:06
SandeepN27-Sep-04 11:06 
GeneralRe: Sorting issue with MMC on Win2000 Pin
David Crow28-Sep-04 4:46
David Crow28-Sep-04 4:46 
GeneralRe: Sorting issue with MMC on Win2000 Pin
SandeepN28-Sep-04 5:33
SandeepN28-Sep-04 5:33 
GeneralNeed help detecting switching users Pin
DeepT27-Sep-04 10:26
DeepT27-Sep-04 10:26 
GeneralRe: Need help detecting switching users Pin
SandeepN27-Sep-04 11:09
SandeepN27-Sep-04 11:09 
GeneralRe: Need help detecting switching users Pin
DeepT27-Sep-04 11:16
DeepT27-Sep-04 11:16 
GeneralRe: Need help detecting switching users Pin
Blake Miller27-Sep-04 11:27
Blake Miller27-Sep-04 11:27 
GeneralRe: Need help detecting switching users Pin
Michael Dunn27-Sep-04 13:37
sitebuilderMichael Dunn27-Sep-04 13:37 
GeneralRe: Need help detecting switching users Pin
shaileshkumar27-Sep-04 20:53
shaileshkumar27-Sep-04 20:53 
GeneralRe: Need help detecting switching users Pin
DeepT28-Sep-04 4:02
DeepT28-Sep-04 4:02 
GeneralAnother idea... Pin
DeepT28-Sep-04 5:59
DeepT28-Sep-04 5:59 
Generalusing string instead of char Pin
lordmickel27-Sep-04 10:01
lordmickel27-Sep-04 10:01 
GeneralRe: using string instead of char Pin
l a u r e n27-Sep-04 13:33
l a u r e n27-Sep-04 13:33 
GeneralRe: using string instead of char Pin
lordmickel27-Sep-04 13:40
lordmickel27-Sep-04 13:40 
GeneralRe: using string instead of char Pin
lordmickel27-Sep-04 13:41
lordmickel27-Sep-04 13:41 
GeneralRe: using string instead of char Pin
David Crow28-Sep-04 4:55
David Crow28-Sep-04 4:55 
GeneralRe: using string instead of char Pin
Michael Dunn27-Sep-04 13:41
sitebuilderMichael Dunn27-Sep-04 13:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.