C++ Offset function inside Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RandomUser
    New Member
    • Jan 2013
    • 1

    C++ Offset function inside Class

    Hello, thanks for reading, i usually use this method for accesing functions in executables, the code is executed from a DLL (always works, except when the function are inside of a class, even tho is public):

    .h:

    Code:
    typedef int (*pgObjViewportClose) (OBJECTSTRUCT* gObj);
    extern pgObjViewportClose gObjViewportClose;
    .cpp

    Code:
    pgObjViewportClose gObjViewportClose = (pgObjViewportClose) 0x04F1940;
    That works, but i can't get it to work if the accesing function is inside of a class, i get Unhandled Exception while trying to access a function inside a class, is there a way to do it?.

    Thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You can't call functions inside of a class unless you have an object or the function is static.

    Code:
    class A
    {
       public:
         void Mbr1();
         static Funct();
    };
    
    A obj;
      obj.Mbr1();  //OK
      A::Funct();  //OK. static functions don't require an object
      A::Mbr1();   //NOT OK. Won't compile.
    Also you mention DLL. A DLL is a Microsoft C artifact where you use GetProcAddress and that requires you inhibit the mangler in C++ in order to find your function or you export the mangled name using a .def file.

    Comment

    Working...