title: c++ function hook(dll, asm)
body: <p>I program a dll. In this dll, I want to hook another dll's function loaded into memory. This is the result of many hours of work:</p>
  
  <pre><code>typedef int (__fastcall *def_cry)(int a,int b,int fromlen);
  def_cry Real_cry;
  int __fastcall custom_cry(int a,int b,int fromlen) {
      Log("cry ...");
      __asm nop;
      return Real_cry(a, b, fromlen);
  }
  DWORD imageBaseOtherDll = 0x39500000;
  DWORD functionOffset = 0x395742F8;
  DWORD imageBase = (DWORD)GetModuleHandle("otherDll.dll");
  DWORD functionOffset = imageBase + (functionOffset  - imageBaseOtherDll);
  Real_cry = (def_cry)DetourFunction((PBYTE)functionOffset,(PBYTE)&amp;custom_cry);
  </code></pre>
  
  <p>It seems, my hook doesn't work. I think i put some logical errors in the code but I'm a beginner and nned help!</p>