STATUS_STACK_BUFFER_OVERRUN encountered

hook_api("user32.dll", "ToUnicode", MyToUnicode, SysToUnicode);


int MyToUnicode(
    UINT       wVirtKey,
    UINT       wScanCode,
    const BYTE* lpKeyState,
    LPWSTR     pwszBuff,
    int        cchBuff,
    UINT       wFlags
)

{
    int r = SysToUnicode(wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff, wFlags);

//在此处程序报 STATUS_STACK_BUFFER_OVERRUN,程序退出
    return r;
}

排查发现,与原型不符合,须加WINAPI,原理是不同的函数声明,不同的压栈出栈规则,必须还原原型声明。

WINUSERAPI
int
WINAPI
ToUnicode(
    _In_ UINT wVirtKey,
    _In_ UINT wScanCode,
    _In_reads_bytes_opt_(256) CONST BYTE *lpKeyState,
    _Out_writes_(cchBuff) LPWSTR pwszBuff,
    _In_ int cchBuff,
    _In_ UINT wFlags);

 

 

你可能感兴趣的:(C++,C)