Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Override windows function in mixed c and c++ program

Posted on 2008-10-13
4
Medium Priority
?
418 Views
Last Modified: 2013-12-14
I have an application that has both c and c++ files. I have written some functions that I want to over ride some windows functions, namely Registry calls. For example i have a function called my_RegCreateEx and what I want is that when my code calls RegCreateEx I want the call to go to my_RegCreateEx and not the windows default RegCreateEx found in winreg.h.

I have created my_RegCreateEx() function call in a cpp file and used the extern "c" in the my header file, call it my_reg.h. Also in another header file, call it my_functions.h I have a defined as follows:
#define my_RegCreateEx RegCreateEx. Now in any cpp file that I have:
#include "my_functions.h"
#include "my_reg.h"
where I have a call to RegCreateEx() the code will go to my function my_RegCreateEx() as expected but in any C files where I have a RegCreateEx() call it goes to the windows function, which I do not want.

I need help where no matter what type of file, C or C++, the RegCreateEx call will always go to my_RegCreateEx call.

Thanks for you help
0
Comment
Question by:atomicgs12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22709340
Can you show the exact header files you are using ?

Didn't you also mean :

        #define RegCreateEx my_RegCreateEx

instead of :

        #define my_RegCreateEx RegCreateEx

?
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 2000 total points
ID: 22709359
Hi atomicgs12,

I don't know if I really understand, but at least I think this is wrong:

#define my_RegCreateEx RegCreateEx

I would think you need something like this, best in the header where my_RegCreateEx is declared:

// after declaration of my_RegCreateEx
#undef RegCreateEx
#define RegCreateEx my_RegCreateEx

Hope that helps,

if not please post more of the code, including the declaration of my_RegCreateEx.

ZOPPO
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 22709362
you need to define a new function as RegCreateExA
//include both windows header file and your header file.
#include ....

#ifdef OWN_REGCREATE
#define RegCreateExA my_RegCreateEx
#else
#define RegCreateExA RegCreateEx
#endif

In your codes, call RegCreateExA directly and do not care about which one is called.
0
 
LVL 8

Expert Comment

by:Pramod Bugudai
ID: 22783533
Hi atomicgs12,
                            this is one general idea that whenever you are using some c language function with some C++ type function you need to define like this:

#ifdef __cplusplus
extern "C"
{
#endif
           //C type function
           int add(int,int);
           int multiply(int,int);
#ifdef __cplusplus
};
#endif

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

610 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