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. Visual Studio 2010 optimized code bug

Visual Studio 2010 optimized code bug

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studioalgorithmsperformancehelp
9 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi, Using the GetProcAdress I wanted to get the exported address of a function When it returned zero I double checked with depends.exe to ensure the function was exported I then went to assembly mode to see what happens and noticed that after the call statement a value was returned in the RAX register but there wasn't any code to move the RAX register value to my FARPROC data member I then turned optimization off #pragma optimize("",off) and the same code generated "mov FARPROC,rax" am I missing some compiler to flag to make this happen without turning optimization off Thanks Thanks

    _ L 2 Replies Last reply
    0
    • F ForNow

      Hi, Using the GetProcAdress I wanted to get the exported address of a function When it returned zero I double checked with depends.exe to ensure the function was exported I then went to assembly mode to see what happens and noticed that after the call statement a value was returned in the RAX register but there wasn't any code to move the RAX register value to my FARPROC data member I then turned optimization off #pragma optimize("",off) and the same code generated "mov FARPROC,rax" am I missing some compiler to flag to make this happen without turning optimization off Thanks Thanks

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      It would help if you could post the code in your function and some of the generated assembly code.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      F 1 Reply Last reply
      0
      • _ _Superman_

        It would help if you could post the code in your function and some of the generated assembly code.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        Here it is HMODULE hutil_module; FARPROC hercgui_addr; hutil_module = GetModuleHandle("HENGINE"); With #pragma optimize("",off) hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 000000005178D4BC lea rdx,[string "hercgui_proc" (518672B0h)] 000000005178D4C3 mov rcx,qword ptr [rsp+0E0h] 000000005178D4CB call qword ptr [__imp_GetProcAddress (5184A050h)] 000000005178D4D1 mov qword ptr [rsp+0C0h],rax with optimization on hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 00000000514CD44B lea rdx,[string "hercgui_proc" (515A42B0h)] 00000000514CD452 mov rcx,rax 00000000514CD455 call qword ptr [__imp_GetProcAddress (51587050h)] Thanks

        B 1 Reply Last reply
        0
        • F ForNow

          Here it is HMODULE hutil_module; FARPROC hercgui_addr; hutil_module = GetModuleHandle("HENGINE"); With #pragma optimize("",off) hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 000000005178D4BC lea rdx,[string "hercgui_proc" (518672B0h)] 000000005178D4C3 mov rcx,qword ptr [rsp+0E0h] 000000005178D4CB call qword ptr [__imp_GetProcAddress (5184A050h)] 000000005178D4D1 mov qword ptr [rsp+0C0h],rax with optimization on hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 00000000514CD44B lea rdx,[string "hercgui_proc" (515A42B0h)] 00000000514CD452 mov rcx,rax 00000000514CD455 call qword ptr [__imp_GetProcAddress (51587050h)] Thanks

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          Do you actually use

          hercgui_addr

          later in the code? I find that if I'm looking at optimized assembly output that if I don't actually use the value for something, the extra processing code can get discarded. At a minimum, you can dump the value to console or screen to make sure the code remains in the optimized assembly output.

          F 1 Reply Last reply
          0
          • B bob16972

            Do you actually use

            hercgui_addr

            later in the code? I find that if I'm looking at optimized assembly output that if I don't actually use the value for something, the extra processing code can get discarded. At a minimum, you can dump the value to console or screen to make sure the code remains in the optimized assembly output.

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            This is the next statement strncpy(&herc_parm[0],&hercgui_addr,8); I am running X64 I send thid address to child process

              return\_code = CreateProcess((LPCSTR) &herc\_command\[0\],    // command 
            		            (LPCSTR) &herc\_parm\[0\],         // paramter
                                            (LPCSTR) &sa,
                                            NULL,
                                            TRUE,
                                            (DWORD) NULL,
                                            NULL,
                                            NULL,
                                            &si,
                                            &pi);
            

            Later in the child process I Create a Remote thread with the parent

            snap_shot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

            process32.dwSize = sizeof(PROCESSENTRY32);

            return_cde = Process32First(snap_shot,&process32);

            pid = GetCurrentProcessId(); // Get Current process id

              while(pid != process32.th32ProcessID)
            

            {
            return_cde = Process32Next(snap_shot,&process32);
            }

            herc_process = process32.th32ParentProcessID;

            my_herc = OpenProcess(PROCESS_ALL_ACCESS,FALSE,herc_process); // Get a Handle to
            if (my_herc == NULL)
            errcd= GetLastError();

            SECURITY_ATTRIBUTES sa;
            LPVOID lparam;
            DWORD threadid;

                       sa.nLength =  sizeof(sa);
                       sa.lpSecurityDescriptor = NULL;
                       sa.bInheritHandle = TRUE;
            
            lparam = NULL;
            
                    CreateRemoteThread(my\_herc,
                                       &sa,
                                       NULL,
                                       (LPTHREAD\_START\_ROUTINE) hercgui,
                                       lparam,
                                       NULL,
                                       &threadid);
            
            1 Reply Last reply
            0
            • F ForNow

              Hi, Using the GetProcAdress I wanted to get the exported address of a function When it returned zero I double checked with depends.exe to ensure the function was exported I then went to assembly mode to see what happens and noticed that after the call statement a value was returned in the RAX register but there wasn't any code to move the RAX register value to my FARPROC data member I then turned optimization off #pragma optimize("",off) and the same code generated "mov FARPROC,rax" am I missing some compiler to flag to make this happen without turning optimization off Thanks Thanks

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              ForNow wrote:

              When it returned zero I double checked with depends.exe to ensure the function was exported

              Did you actually check what error was being generated, as described in the function's documentation[^]?

              F 1 Reply Last reply
              0
              • L Lost User

                ForNow wrote:

                When it returned zero I double checked with depends.exe to ensure the function was exported

                Did you actually check what error was being generated, as described in the function's documentation[^]?

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                Richard look at what happens When I turn optimazation off and check for an error no code is generated for the if (hercgui_addr = NULL) one wierd complier On aonther issue my assignment at work I was able to resolve the 800A30EC I think thats it by Doing app.GetActiveWorkBook however txt file wasn't displayed in the workbook in fact a worksheet wasn't loaded I was under the impression that OpenText loads a worksheet as well Thanks

                       hercgui\_addr = GetProcAddress(hutil\_module,"hercgui\_proc");
                

                00000000013FD44B lea rdx,[string "hercgui_proc" (14D42B0h)]
                00000000013FD452 mov rcx,rax
                00000000013FD455 call qword ptr [__imp_GetProcAddress (14B7050h)]

                	   if (hercgui\_addr = NULL)
                		    errcd = GetLastError();
                
                L 1 Reply Last reply
                0
                • F ForNow

                  Richard look at what happens When I turn optimazation off and check for an error no code is generated for the if (hercgui_addr = NULL) one wierd complier On aonther issue my assignment at work I was able to resolve the 800A30EC I think thats it by Doing app.GetActiveWorkBook however txt file wasn't displayed in the workbook in fact a worksheet wasn't loaded I was under the impression that OpenText loads a worksheet as well Thanks

                         hercgui\_addr = GetProcAddress(hutil\_module,"hercgui\_proc");
                  

                  00000000013FD44B lea rdx,[string "hercgui_proc" (14D42B0h)]
                  00000000013FD452 mov rcx,rax
                  00000000013FD455 call qword ptr [__imp_GetProcAddress (14B7050h)]

                  	   if (hercgui\_addr = NULL)
                  		    errcd = GetLastError();
                  
                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  if (hercgui_addr = NULL)

                  This sets the value of hercgui_addr to NULL, so it is little wonder that the generated code does not look correct.

                  F 1 Reply Last reply
                  0
                  • L Lost User

                    if (hercgui_addr = NULL)

                    This sets the value of hercgui_addr to NULL, so it is little wonder that the generated code does not look correct.

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #9

                    Thanks once I referenced hercgui eith "==" the optimized version genereted the "mov hercgui,rax" Thanks again

                    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