We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,464 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to access VPTR in my program?

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

5
Contributors
6
Replies
2 Years
Discussion Span
10 Months Ago
Last Updated
7
Views
vivekarora
Newbie Poster
17 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
Skill Endorsements: 3

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

vivekarora
Newbie Poster
17 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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/smfforum/index.php?board=362.0

Frederick2
Posting Whiz
330 posts since Jul 2008
Reputation Points: 244
Solved Threads: 31
Skill Endorsements: 0

( (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.

Frederick2
Posting Whiz
330 posts since Jul 2008
Reputation Points: 244
Solved Threads: 31
Skill Endorsements: 0

when I was learning this topic. I followed the very good series of articles on code project, check the below link

http://www.codeproject.com/KB/atl/atl_underthehood_.aspx

Hope above helps.

Laiq Ahmed
Junior Poster
148 posts since Jun 2006
Reputation Points: 113
Solved Threads: 20
Skill Endorsements: 0
AliceJohn123
Newbie Poster
2 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0749 seconds using 2.72MB