Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Hello how should i use the this pointer if it is a function param as void *this

Hello how should i use the this pointer if it is a function param as void *this

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlounge
6 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nah1337
    wrote on last edited by
    #1

    Well the reversed class looks something like it:

    struct random_class {

    char \*something;
    
    void \_\_thiscall classfunction (void \*this);
    

    };

    So i wanna hook it like this

    void (__thiscall* classfunction)(void *this );
    void __thiscall myclassfunction(void *this )
    {
    return classfunction(this->something);
    }

    But i get 8 errors it says syntax error : missing ';' before 'this' Did i use it correctly or wrongly i didnt find on google any function that uses param as void*this???

    J S 2 Replies Last reply
    0
    • N nah1337

      Well the reversed class looks something like it:

      struct random_class {

      char \*something;
      
      void \_\_thiscall classfunction (void \*this);
      

      };

      So i wanna hook it like this

      void (__thiscall* classfunction)(void *this );
      void __thiscall myclassfunction(void *this )
      {
      return classfunction(this->something);
      }

      But i get 8 errors it says syntax error : missing ';' before 'this' Did i use it correctly or wrongly i didnt find on google any function that uses param as void*this???

      J Offline
      J Offline
      Jonathan Davies
      wrote on last edited by
      #2

      Try calling your parameter sonething other than "this". this has a special meaning (meaning: a pointer to this object) in C++.

      Z 1 Reply Last reply
      0
      • J Jonathan Davies

        Try calling your parameter sonething other than "this". this has a special meaning (meaning: a pointer to this object) in C++.

        Z Offline
        Z Offline
        zhq00001
        wrote on last edited by
        #3

        hi I don't understand Completely what you say,but the word "this" is the key word of C/C++. so it isn't declare as a variable. as follow,there is a example.I hope it is help for you. #include "stdafx.h" typedef void classfunction (void *w); struct random_class { char *something; classfunction *myfunction; }; classfunction * myclassfunction(void *w ) { return ((struct random_class *)w)->myfunction; } void printfAint(void *w) { printf("%d\n",*(int*)w); } int main(int argc, char* argv[]) { int i=10,j=20; random_class r; r.myfunction=printfAint; r.myfunction(&i); r.myfunction(&j); return 0; }

        J 1 Reply Last reply
        0
        • N nah1337

          Well the reversed class looks something like it:

          struct random_class {

          char \*something;
          
          void \_\_thiscall classfunction (void \*this);
          

          };

          So i wanna hook it like this

          void (__thiscall* classfunction)(void *this );
          void __thiscall myclassfunction(void *this )
          {
          return classfunction(this->something);
          }

          But i get 8 errors it says syntax error : missing ';' before 'this' Did i use it correctly or wrongly i didnt find on google any function that uses param as void*this???

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          The calling convention __thiscall[^] is for member functions. You can't apply it to regular global functions as you're attempting. Also, for member functions __thiscall is assumed and in general including it adds little but clutter.

          Steve

          N 1 Reply Last reply
          0
          • S Stephen Hewitt

            The calling convention __thiscall[^] is for member functions. You can't apply it to regular global functions as you're attempting. Also, for member functions __thiscall is assumed and in general including it adds little but clutter.

            Steve

            N Offline
            N Offline
            nah1337
            wrote on last edited by
            #5

            Im trying to return the char using the thispointer.

            1 Reply Last reply
            0
            • Z zhq00001

              hi I don't understand Completely what you say,but the word "this" is the key word of C/C++. so it isn't declare as a variable. as follow,there is a example.I hope it is help for you. #include "stdafx.h" typedef void classfunction (void *w); struct random_class { char *something; classfunction *myfunction; }; classfunction * myclassfunction(void *w ) { return ((struct random_class *)w)->myfunction; } void printfAint(void *w) { printf("%d\n",*(int*)w); } int main(int argc, char* argv[]) { int i=10,j=20; random_class r; r.myfunction=printfAint; r.myfunction(&i); r.myfunction(&j); return 0; }

              J Offline
              J Offline
              Jonathan Davies
              wrote on last edited by
              #6

              zhq00001 wrote:

              the word "this" is the key word of C/C++. so it isn't declare as a variable

              In your first example it is, its declared as a parameter which is a variable:

              void (__thiscall* classfunction)(void *this );
              void __thiscall myclassfunction(void *this )
              {
              return classfunction(this->something);
              }

              I'm saying try changing it to:

              void (__thiscall* classfunction)(void *pParam );
              void __thiscall myclassfunction(void *pParam )
              {
              return classfunction(pParam->something);
              }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups