Click here to Skip to main content
15,894,170 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionLoading PDF file in picture control Pin
Pryabu25-Nov-09 0:17
Pryabu25-Nov-09 0:17 
QuestionHow can I restrict a CListViewCtrl for column resizing . Pin
pandit8424-Nov-09 23:52
pandit8424-Nov-09 23:52 
AnswerRe: How can I restrict a CListViewCtrl for column resizing . Pin
Adam Roderick J25-Nov-09 0:06
Adam Roderick J25-Nov-09 0:06 
AnswerRe: How can I restrict a CListViewCtrl for column resizing . Pin
JohnCz7-Dec-09 18:45
JohnCz7-Dec-09 18:45 
Questionconvert wav file to text file Pin
soo preety24-Nov-09 23:43
soo preety24-Nov-09 23:43 
AnswerRe: convert wav file to text file [modified] Pin
Adam Roderick J24-Nov-09 23:52
Adam Roderick J24-Nov-09 23:52 
AnswerRe: convert wav file to text file Pin
«_Superman_»25-Nov-09 8:35
professional«_Superman_»25-Nov-09 8:35 
QuestionReplacing virtual function address with global function address Pin
abhay4u24-Nov-09 21:54
abhay4u24-Nov-09 21:54 
Hi,

I've created a class containing a virtual function. Using pointer, I want to replace virtual function with a global function, but it gives memory access violation. So my question is that

whether it is possible to replace virtual function with global function?
How can we achieve this?

Please note that I am new to C++ and using MS VC++.

Here is the code...
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

typedef void(*Fun)();
void f(void *pThis)
{
printf("other function\n");
}

class Test {
public:
virtual void fn() {
cout << "I m virtaul fn" << endl;
}

virtual ~Test() {}
};

int main() {
Test obj;
Fun pFun = (Fun)*(int*)*(int*)(&obj);
pFun();

//replacing virtual function.
int *pInt = (int*)&obj;
*(int*)*pInt = (int)f; // gives memory voilation

pFun = (Fun)(int*)*(int*)*(int*)(&obj);
pFun();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thank you
AnswerRe: Replacing virtual function address with global function address Pin
Cedric Moonen24-Nov-09 22:02
Cedric Moonen24-Nov-09 22:02 
AnswerRe: Replacing virtual function address with global function address Pin
Adam Roderick J24-Nov-09 22:13
Adam Roderick J24-Nov-09 22:13 
GeneralRe: Replacing virtual function address with global function address Pin
abhay4u24-Nov-09 22:35
abhay4u24-Nov-09 22:35 
GeneralRe: Replacing virtual function address with global function address Pin
T210224-Nov-09 22:48
T210224-Nov-09 22:48 
AnswerRe: Replacing virtual function address with global function address Pin
Richard MacCutchan24-Nov-09 22:56
mveRichard MacCutchan24-Nov-09 22:56 
AnswerRe: Replacing virtual function address with global function address Pin
CPallini24-Nov-09 23:08
mveCPallini24-Nov-09 23:08 
AnswerRe: Replacing virtual function address with global function address Pin
Stuart Dootson24-Nov-09 23:34
professionalStuart Dootson24-Nov-09 23:34 
GeneralRe: Replacing virtual function address with global function address Pin
abhay4u25-Nov-09 16:48
abhay4u25-Nov-09 16:48 
QuestionHow to set Proxy Module in the MFC dialog ? Pin
wangningyu24-Nov-09 21:36
wangningyu24-Nov-09 21:36 
QuestionGetSaveFileName Problem Pin
002comp24-Nov-09 20:32
002comp24-Nov-09 20:32 
AnswerRe: GetSaveFileName Problem Pin
CPallini24-Nov-09 20:57
mveCPallini24-Nov-09 20:57 
AnswerRe: GetSaveFileName Problem Pin
KarstenK24-Nov-09 21:09
mveKarstenK24-Nov-09 21:09 
Question[Message Deleted] Pin
eswar pothula24-Nov-09 19:27
eswar pothula24-Nov-09 19:27 
AnswerRe: is it possible to convert wav file to text file using vc++6.0 Pin
Cedric Moonen24-Nov-09 20:32
Cedric Moonen24-Nov-09 20:32 
General[Message Deleted] Pin
eswar pothula24-Nov-09 22:25
eswar pothula24-Nov-09 22:25 
GeneralRe: is it possible to convert wav file to text file using vc++6.0 Pin
Cedric Moonen24-Nov-09 23:04
Cedric Moonen24-Nov-09 23:04 
QuestionRe: is it possible to convert wav file to text file using vc++6.0 Pin
CPallini24-Nov-09 20:49
mveCPallini24-Nov-09 20:49 

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.