Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - C++ Virtual Table
Author:Arkon
Category:Win32API
File Size:640 Bytes
Uploaded at:27-Nov-02 08:17:47 pm
Description:
  Shows how to call a method of a class in C++ using directly the virtual pointers table of the class (Under Visual C++ 6 only).
  
// It works for VC6 implementations, didn't check in other compilers!
#include <windows.h>
class CTest
{
 public:
 virtual void bla()
 {
  MessageBox(NULL, "bla1", "CTest", 0);
 }
 virtual void bla2()
 {
  MessageBox(NULL, "bla2", "CTest", 0);
 }
 virtual void bla3()
 {
  MessageBox(NULL, "bla3", "CTest", 0);
 }
};

typedef (*lpfunc)(void* thisptr);
lpfunc func;

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
 CTest* ct = new CTest;
 DWORD *pvtbl = (DWORD*)ct;
 DWORD *vtbl = (DWORD*)*pvtbl;
 func = (lpfunc)vtbl[1];
 func(ct);
 delete ct;
 return 0;
}
User Contributed Comments(None)
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[116850]
2D Rotated Rectangles Collision Detection[88945]
Keyboard Hook[77238]
UDP[65796]
HTTP Proxy[41186]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11557]
PS2 Mouse Driver[6953]
Wave Format Player[5788]
Reading FAT12[5615]
CodeGuru[5355]


All rights reserved to RageStorm © 2009