943,738 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1894
  • C++ RSS
Aug 30th, 2009
0

How to access VPTR in my program?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vivekarora is offline Offline
17 posts
since Aug 2009
Aug 30th, 2009
0

Re: How to access VPTR in my program?

Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Aug 30th, 2009
0

Re: How to access VPTR in my program?

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vivekarora is offline Offline
17 posts
since Aug 2009
Aug 30th, 2009
0

Re: How to access VPTR in my program?

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.
Reputation Points: 244
Solved Threads: 31
Posting Whiz
Frederick2 is offline Offline
330 posts
since Jul 2008
Sep 2nd, 2009
0

Re: How to access VPTR in my program?

Quote ...
( (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.
Reputation Points: 244
Solved Threads: 31
Posting Whiz
Frederick2 is offline Offline
330 posts
since Jul 2008
Sep 3rd, 2009
0

Re: How to access VPTR in my program?

when I was learning this topic. I followed the very good series of articles on code project, check the below link
Hope above helps.
Reputation Points: 113
Solved Threads: 20
Junior Poster
Laiq Ahmed is offline Offline
147 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: gdb cannot acces memory at 0x0
Next Thread in C++ Forum Timeline: What can I do better? C++ Homework





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC