首页 > 解决方案 > C++ ASM 发布模式下推送偏移字符串问题

问题描述

我要调用的函数是一个类的函数:

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

当我用 asm 块调用它时它可以工作,但是当我在发布模式下构建它时出现错误,然后当我从内存中检查它时,我意识到我需要将字符串偏移量移动 4 个字节并且当我尝试它时它工作.

我的问题是我为什么要这样做?这是什么原因?

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
    }
}

标签: c++assemblyvisual-c++x86inline-assembly

解决方案


推荐阅读