0

The function I want to call is a function of a class:

void D3DBase::SetTexture(const std::string& path);

When i call it with asm block it works, but It was giving an error when I built it in release mode, then when I checked it from memory I realized that I needed to shift the string offset by 4 bytes and when I tried it worked.

My question is Why should I do that? What is the reason of this?

std::string __tmpString = "";

void SetTexture(DWORD table, const std::string& str)
{
    __tmpString = str;
    __asm {
#ifdef NDEBUG
        push offset __tmpString - 0x4
#else
        push offset __tmpString
#endif
        mov ecx, table
        mov eax, 0x401FC0
        call eax
    }
}
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 1
    I guess your library's string implementation is different in debug and release versions, and the string pointer ends up being stored in different places. Perhaps one implementation allows for extra exception handling while another is faster. It depends on your library. – Anonymous1847 Oct 26 '20 at 02:06
  • `__tmpString` is a global? This whole thing looks like a bad idea for inefficiency and brittleness. I wouldn't be surprised if you could write `push offset __tmpString.something` to push the address of some member of the struct, wherever it was in debug vs. release builds. – Peter Cordes Oct 26 '20 at 04:22
  • don't use names such as `__tmpString` for your variables. Those names are reserved. [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/q/228783/995714) – phuclv Oct 26 '20 at 04:50
  • In this case It is not the problem __ names are reserved. I realized that sizeof(string) is 28 in debug but 24 in release. May be the library I called built in debug mode and when i build the dll in release mode it takes the wrong address – seukaiwokeo Oct 26 '20 at 11:10

0 Answers0