How to access VPTR in my program?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2009
Posts: 17
Reputation: vivekarora is an unknown quantity at this point 
Solved Threads: 0
vivekarora vivekarora is offline Offline
Newbie Poster

How to access VPTR in my program?

 
0
  #1
Aug 30th, 2009
Hello Friends,

As we know, when we have virtual function in our class, compiler smartly puts vptr(virtual table pointer) in our class to access correct function at run time.
Can i access this vptr in my program, to use/manipulate this directly?

Regards,
Vivek
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 903
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 144
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: How to access VPTR in my program?

 
0
  #2
Aug 30th, 2009
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 17
Reputation: vivekarora is an unknown quantity at this point 
Solved Threads: 0
vivekarora vivekarora is offline Offline
Newbie Poster

Re: How to access VPTR in my program?

 
0
  #3
Aug 30th, 2009
Hi,

That was an amazing article to go through & a great insight. Thanks alot for sharing this.
Can you share me more details :

1) Following is puzzling me:
( (void (*)()) vptr[0] )();

I am sure we can split this in multiple instrcutions to make it more user readable?
Can you help by splitting so that it is understandable to me?

2) I checked this program in "Microsoft Visual C++ 2005", but i could not get the value of "n", even if the __asm instructions are present. It seems "Microsoft Visual C++ 2005" does not use ECX register for this pointer. Is it so?

Regards,
Vivek
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 134
Reputation: Frederick2 has a spectacular aura about Frederick2 has a spectacular aura about Frederick2 has a spectacular aura about 
Solved Threads: 14
Frederick2 Frederick2 is offline Offline
Junior Poster

Re: How to access VPTR in my program?

 
0
  #4
Aug 30th, 2009
Spent a lot of time working with that some time ago. Here's a daniweb link...

http://www.daniweb.com/forums/thread144510.html

Also, here's a link to some of my tutorials using C, C++ and PowerBASIC where I pretty much take COM memory apart and look close at VTables, VTable pointers, function pointers, calling class member functions using function pointers derived from VPtrs, and the like...

http://www.jose.it-berater.org/smffo...hp?board=362.0
Last edited by Frederick2; Aug 30th, 2009 at 5:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 134
Reputation: Frederick2 has a spectacular aura about Frederick2 has a spectacular aura about Frederick2 has a spectacular aura about 
Solved Threads: 14
Frederick2 Frederick2 is offline Offline
Junior Poster

Re: How to access VPTR in my program?

 
0
  #5
Sep 2nd, 2009
( (void (*)()) vptr[0] )();
This term...

((void(*)())

is a cast prefaced in front of this function pointer call...

vptr[0] )();

The function pointer call is calling a function at this address...

vptr[0]

...and the function itself is such that it takes no parameters, i.e., 'void', and returns nothing, i.e., return is void.

The cast in front of this function address is simply necessary to inform the compiler that,

a) it is a function pointer call that returns void;
b) it uses __cdecl;
c) it is a function pointer call and there are no parameters.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 147
Reputation: Laiq Ahmed will become famous soon enough Laiq Ahmed will become famous soon enough 
Solved Threads: 20
Laiq Ahmed Laiq Ahmed is offline Offline
Junior Poster

Re: How to access VPTR in my program?

 
0
  #6
Sep 3rd, 2009
when I was learning this topic. I followed the very good series of articles on code project, check the below link
Hope above helps.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC