以下の Winapi EndPaint() 関数をフックし、その内部で wm_copydata を送信していますが、その間、「wm_copydata、変数 endpaint_text の周りのスタックが破損しています...」というメッセージが表示され、フックされたアプリがクラッシュします。
BOOL WINAPI Mine_EndPaint(HWND hWnd, const PAINTSTRUCT *lpPaint) {
BOOL result = fpEndPaint(hWnd, lpPaint);
if (hWnd == g_win)
{
if (lpPaint->rcPaint.left == g_12x && lpPaint->rcPaint.top == g_12y)
{
painting = 0;
wchar_t endpaint_text[MAX_PATH] = L"deleting_a";
COPYDATASTRUCT cds;
::ZeroMemory(&cds, sizeof(COPYDATASTRUCT));
cds.cbData = sizeof(paint_dc);
cds.lpData = endpaint_text;
::SendMessageTimeoutW(g_main, WM_COPYDATA, (WPARAM)::GetDesktopWindow(), (LPARAM)&cds, SMTO_ABORTIFHUNG, 1000, 0);
}
else if (lpPaint->rcPaint.left == g_list12x && lpPaint->rcPaint.top == 137)
{
big_painting = 0;
wchar_t endpaint_text[MAX_PATH] = L"deleting_b";
COPYDATASTRUCT cds;
::ZeroMemory(&cds, sizeof(COPYDATASTRUCT));
cds.cbData = sizeof(paint_dc);
cds.lpData = endpaint_text;
::SendMessageTimeoutW(g_main, WM_COPYDATA, (WPARAM)::GetDesktopWindow(), (LPARAM)&cds, SMTO_ABORTIFHUNG, 1000, 0);
}
}
else if (check_d)
{
re_window = NULL;
GetWindowText(hWnd, window_text, MAX_PATH);
if (!wcscmp(window_text, L"Text"))
{
check_d = false;
re_window = hWnd;
wchar_t re_info[MAX_PATH] = L"";
//wcscat(re_info, text);
COPYDATASTRUCT cds;
::ZeroMemory(&cds, sizeof(COPYDATASTRUCT));
cds.dwData = 931;
cds.cbData = sizeof(re_info);
cds.lpData = re_info;
wsprintf(re_info, L"Text='%s', HWND='%X'", d_text, re_window);
::SendMessageTimeoutW(g_main, WM_COPYDATA, (WPARAM)::GetDesktopWindow(), (LPARAM)&cds, SMTO_ABORTIFHUNG, 1000, 0);
}
}
return result;
}