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 i want to redirecting functions using pointers only and i get 2 errors

hello i want to redirecting functions using pointers only and i get 2 errors

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
10 Posts 3 Posters 0 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

    #include #include #include #include #include #include #include #include #include #include #pragma comment(lib, "glu32.lib") #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "winmm.lib") #define Client_GLDRAWELEMENTS 0x4E5DA2 typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices ); DWORD g_dwGlDrawElements = NULL; void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices ) { // Here you can filter any textures using g_pszTextureName CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices ); } // Redirect bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved) { if(dwReason == DLL_PROCESS_ATTACH) { g_dwGlDrawElements = *( DWORD * )Client_GLDRAWELEMENTS; *( DWORD * )Client_GLDRAWELEMENTS = PtrToUlong( glDrawElementsHook ); return true; } else if(dwReason == DLL_PROCESS_DETACH) { } return false; } Here are the errors thnx if any could help me C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2065: 'CAST' : undeclared identifier C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2275: 'GLDRAWELEMENTS_TYPE' : illegal use of this type as an expression C:\Documents and Settings\ivor\Desktop\project\main.cpp(27) : see declaration of 'GLDRAWELEMENTS_TYPE'

    C enhzflepE 2 Replies Last reply
    0
    • N nah1337

      #include #include #include #include #include #include #include #include #include #include #pragma comment(lib, "glu32.lib") #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "winmm.lib") #define Client_GLDRAWELEMENTS 0x4E5DA2 typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices ); DWORD g_dwGlDrawElements = NULL; void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices ) { // Here you can filter any textures using g_pszTextureName CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices ); } // Redirect bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved) { if(dwReason == DLL_PROCESS_ATTACH) { g_dwGlDrawElements = *( DWORD * )Client_GLDRAWELEMENTS; *( DWORD * )Client_GLDRAWELEMENTS = PtrToUlong( glDrawElementsHook ); return true; } else if(dwReason == DLL_PROCESS_DETACH) { } return false; } Here are the errors thnx if any could help me C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2065: 'CAST' : undeclared identifier C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2275: 'GLDRAWELEMENTS_TYPE' : illegal use of this type as an expression C:\Documents and Settings\ivor\Desktop\project\main.cpp(27) : see declaration of 'GLDRAWELEMENTS_TYPE'

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Please format your code properly using the "code block" tag and using the '<' and '>' symbols just above the emoticons. Your code is unreadable.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • N nah1337

        #include #include #include #include #include #include #include #include #include #include #pragma comment(lib, "glu32.lib") #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "winmm.lib") #define Client_GLDRAWELEMENTS 0x4E5DA2 typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices ); DWORD g_dwGlDrawElements = NULL; void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices ) { // Here you can filter any textures using g_pszTextureName CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices ); } // Redirect bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved) { if(dwReason == DLL_PROCESS_ATTACH) { g_dwGlDrawElements = *( DWORD * )Client_GLDRAWELEMENTS; *( DWORD * )Client_GLDRAWELEMENTS = PtrToUlong( glDrawElementsHook ); return true; } else if(dwReason == DLL_PROCESS_DETACH) { } return false; } Here are the errors thnx if any could help me C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2065: 'CAST' : undeclared identifier C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2275: 'GLDRAWELEMENTS_TYPE' : illegal use of this type as an expression C:\Documents and Settings\ivor\Desktop\project\main.cpp(27) : see declaration of 'GLDRAWELEMENTS_TYPE'

        enhzflepE Offline
        enhzflepE Offline
        enhzflep
        wrote on last edited by
        #3

        Try changing the glDrawElementsHook function as follows:

        void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
        {
        GLDRAWELEMENTS_TYPE *myFunc;

        myFunc = MessageBox;   // \*\*\*\*\* Change this to reflect the name of the function you want to call \*\*
        (\*myFunc)(iMode, iCount, iType, pvIndices );
        

        }

        You just need to change the indicated line so it points to the correct function Here's a trivial example:

        typedef int ( WINAPI msgBoxFunc_Type )( HWND hwnd, LPCSTR, LPCSTR, UINT);

        void DrawOKMB( char *title, char *text )
        {
        msgBoxFunc_Type *myFunc;
        myFunc = MessageBox;
        (*myFunc)(NULL, text, title, MB_OK);
        }

        N 1 Reply Last reply
        0
        • enhzflepE enhzflep

          Try changing the glDrawElementsHook function as follows:

          void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
          {
          GLDRAWELEMENTS_TYPE *myFunc;

          myFunc = MessageBox;   // \*\*\*\*\* Change this to reflect the name of the function you want to call \*\*
          (\*myFunc)(iMode, iCount, iType, pvIndices );
          

          }

          You just need to change the indicated line so it points to the correct function Here's a trivial example:

          typedef int ( WINAPI msgBoxFunc_Type )( HWND hwnd, LPCSTR, LPCSTR, UINT);

          void DrawOKMB( char *title, char *text )
          {
          msgBoxFunc_Type *myFunc;
          myFunc = MessageBox;
          (*myFunc)(NULL, text, title, MB_OK);
          }

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

          Thnx for very good post but still i got 1 error main.cpp C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2275: 'GLDRAWELEMENTS_TYPE' : illegal use of this type as an expression C:\Documents and Settings\ivor\Desktop\project\main.cpp(27) : see declaration of 'GLDRAWELEMENTS_TYPE' it should be this i dunno why the code block ignores it includes should be stdio.h detours.h vector tlhelp32.h mmsystem.h process.h math.h

          #include
          #include
          #include
          #include
          #include
          #include
          #include
          #include
          #include
          #include

          #pragma comment(lib, "glu32.lib")
          #pragma comment(lib, "opengl32.lib")
          #pragma comment(lib, "winmm.lib")

          #define Client_GLDRAWELEMENTS 0x4E5DA2

          typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices );
          DWORD g_dwGlDrawElements = NULL;

          void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
          {

          GLDRAWELEMENTS_TYPE *CAST;
          CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
          }

          // Redirect

          bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved)
          {
          if(dwReason == DLL_PROCESS_ATTACH)
          {
          g_dwGlDrawElements = *( DWORD * )Client_GLDRAWELEMENTS;
          *( DWORD * )Client_GLDRAWELEMENTS = PtrToUlong( glDrawElementsHook );

          	return true;
          }
          else if(dwReason == DLL\_PROCESS\_DETACH)
          {
          }
          return false;
          

          }

          enhzflepE 1 Reply Last reply
          0
          • N nah1337

            Thnx for very good post but still i got 1 error main.cpp C:\Documents and Settings\ivor\Desktop\project\main.cpp(35) : error C2275: 'GLDRAWELEMENTS_TYPE' : illegal use of this type as an expression C:\Documents and Settings\ivor\Desktop\project\main.cpp(27) : see declaration of 'GLDRAWELEMENTS_TYPE' it should be this i dunno why the code block ignores it includes should be stdio.h detours.h vector tlhelp32.h mmsystem.h process.h math.h

            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include

            #pragma comment(lib, "glu32.lib")
            #pragma comment(lib, "opengl32.lib")
            #pragma comment(lib, "winmm.lib")

            #define Client_GLDRAWELEMENTS 0x4E5DA2

            typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices );
            DWORD g_dwGlDrawElements = NULL;

            void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
            {

            GLDRAWELEMENTS_TYPE *CAST;
            CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
            }

            // Redirect

            bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved)
            {
            if(dwReason == DLL_PROCESS_ATTACH)
            {
            g_dwGlDrawElements = *( DWORD * )Client_GLDRAWELEMENTS;
            *( DWORD * )Client_GLDRAWELEMENTS = PtrToUlong( glDrawElementsHook );

            	return true;
            }
            else if(dwReason == DLL\_PROCESS\_DETACH)
            {
            }
            return false;
            

            }

            enhzflepE Offline
            enhzflepE Offline
            enhzflep
            wrote on last edited by
            #5

            Ahr - that thing with the #includes being cut from the post - when you're editing the post, you have to go through and replace all instances of < & > with the characters supplied when you hit the < or > buttons below the edit box. If you don't, text between < and > will be treated as an HTML block. (not just plain text) As for the code - it's the whole CAST thing that's giving rubbish results

            void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
            {
            GLDRAWELEMENTS_TYPE *CAST;
            CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
            }

            Here, like this, I believe. - Just chuck the CAST away and use the function pointer like I suggested earlier.

            void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
            {
            ( g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
            }

            N 1 Reply Last reply
            0
            • enhzflepE enhzflep

              Ahr - that thing with the #includes being cut from the post - when you're editing the post, you have to go through and replace all instances of < & > with the characters supplied when you hit the < or > buttons below the edit box. If you don't, text between < and > will be treated as an HTML block. (not just plain text) As for the code - it's the whole CAST thing that's giving rubbish results

              void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
              {
              GLDRAWELEMENTS_TYPE *CAST;
              CAST( GLDRAWELEMENTS_TYPE, g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
              }

              Here, like this, I believe. - Just chuck the CAST away and use the function pointer like I suggested earlier.

              void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
              {
              ( g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
              }

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

              It says the following error if i try above C:\Documents and Settings\ivor\Desktop\project\main.cpp(40) : error C2064: term does not evaluate to a function

              void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
              {
              ( g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
              }

              enhzflepE 1 Reply Last reply
              0
              • N nah1337

                It says the following error if i try above C:\Documents and Settings\ivor\Desktop\project\main.cpp(40) : error C2064: term does not evaluate to a function

                void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
                {
                ( g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
                }

                enhzflepE Offline
                enhzflepE Offline
                enhzflep
                wrote on last edited by
                #7

                Ok, please forgive me - I never really had a close look at all of the code together. Have a look at the definition of g_dwGlDrawElements, it's defined as a DWORD?!? I can't see all of the code in your first post because of the issue with the < and > characters, but if you'd care to post the whole lot I'll take another look at it. I did find some code like yours, over here: http://forum.gamedeception.net/showthread.php?p=100284[^] They might be good value when it comes to looking at this problem. About 1/2 way down, somebody mentions that the code is just performing the same basic function as GetProcAddress, though their code actually overwrites pointers, etc, etc. I had immediately thought of this function when I found out your code need function pointers. It's usually a pretty neat and clean thing to do. In any case, you can chuck a zip over at savefile.com or post the whole code here and I'll take another peek.

                N 1 Reply Last reply
                0
                • enhzflepE enhzflep

                  Ok, please forgive me - I never really had a close look at all of the code together. Have a look at the definition of g_dwGlDrawElements, it's defined as a DWORD?!? I can't see all of the code in your first post because of the issue with the < and > characters, but if you'd care to post the whole lot I'll take another look at it. I did find some code like yours, over here: http://forum.gamedeception.net/showthread.php?p=100284[^] They might be good value when it comes to looking at this problem. About 1/2 way down, somebody mentions that the code is just performing the same basic function as GetProcAddress, though their code actually overwrites pointers, etc, etc. I had immediately thought of this function when I found out your code need function pointers. It's usually a pretty neat and clean thing to do. In any case, you can chuck a zip over at savefile.com or post the whole code here and I'll take another peek.

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

                  Ok i uploaded the c++ source and packed it with rar. here is the link i really appriciate if it could be start working. http://www.savefile.com/files/1793888[^]

                  enhzflepE 1 Reply Last reply
                  0
                  • N nah1337

                    Ok i uploaded the c++ source and packed it with rar. here is the link i really appriciate if it could be start working. http://www.savefile.com/files/1793888[^]

                    enhzflepE Offline
                    enhzflepE Offline
                    enhzflep
                    wrote on last edited by
                    #9

                    Well here's what I've got. It compiles, but I've no idea if it's any good. It all depends on what is sitting at 0x4E5DA2 in memory.

                    #include <windows.h>
                    #include <stdio.h>
                    //#include <detours.h>
                    #include <gl/gl.h>
                    #include <gl/glu.h>
                    #include <math.h>
                    #include <process.h>
                    #include <mmsystem.h>
                    #include <tlhelp32.h>
                    #include <vector>

                    #pragma comment(lib, "glu32.lib")
                    #pragma comment(lib, "opengl32.lib")
                    #pragma comment(lib, "winmm.lib")

                    #define Client_GLDRAWELEMENTS 0x4E5DA2

                    typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices );

                    GLDRAWELEMENTS_TYPE g_dwGlDrawElements = NULL;

                    void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
                    {
                    ( g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
                    }

                    bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved)
                    {
                    if(dwReason == DLL_PROCESS_ATTACH)
                    {
                    g_dwGlDrawElements = *( GLDRAWELEMENTS_TYPE * )Client_GLDRAWELEMENTS;
                    *( DWORD*)Client_GLDRAWELEMENTS = PtrToUlong(glDrawElementsHook );
                    return true;
                    }
                    else if(dwReason == DLL_PROCESS_DETACH)
                    {
                    }
                    return false;
                    }

                    N 1 Reply Last reply
                    0
                    • enhzflepE enhzflep

                      Well here's what I've got. It compiles, but I've no idea if it's any good. It all depends on what is sitting at 0x4E5DA2 in memory.

                      #include <windows.h>
                      #include <stdio.h>
                      //#include <detours.h>
                      #include <gl/gl.h>
                      #include <gl/glu.h>
                      #include <math.h>
                      #include <process.h>
                      #include <mmsystem.h>
                      #include <tlhelp32.h>
                      #include <vector>

                      #pragma comment(lib, "glu32.lib")
                      #pragma comment(lib, "opengl32.lib")
                      #pragma comment(lib, "winmm.lib")

                      #define Client_GLDRAWELEMENTS 0x4E5DA2

                      typedef void ( WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices );

                      GLDRAWELEMENTS_TYPE g_dwGlDrawElements = NULL;

                      void WINAPI glDrawElementsHook( GLenum iMode, GLsizei iCount, GLenum iType, const GLvoid *pvIndices )
                      {
                      ( g_dwGlDrawElements )( iMode, iCount, iType, pvIndices );
                      }

                      bool WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, PVOID pvReserved)
                      {
                      if(dwReason == DLL_PROCESS_ATTACH)
                      {
                      g_dwGlDrawElements = *( GLDRAWELEMENTS_TYPE * )Client_GLDRAWELEMENTS;
                      *( DWORD*)Client_GLDRAWELEMENTS = PtrToUlong(glDrawElementsHook );
                      return true;
                      }
                      else if(dwReason == DLL_PROCESS_DETACH)
                      {
                      }
                      return false;
                      }

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

                      thnx for the help i try it later im on school now but il post the result !

                      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