Я пытаюсь подключить функцию SetRect с помощью Detours, но моя программа рушится сразу после подключения. Я попытался подключить другие функции, такие как DrawText, и все прошло отлично, и теперь я не уверен, есть ли проблема с моим кодом или что-то о SetRect (и других подобных функциях), о которых я не знаю, что вызвало крах.Сбой при сбоях приложения Detours 3.0 SetRect
Для тестирования я использую при условии Detours работать с программой длл:
withdll.exe -d:mydll.exe simpleprogram.exe
Где simpleprogram.exe является простой одна кнопка C# приложение. Пробовал тестирование также на блокноте, calc, firefox, но все они тоже разбились.
Мой крючок DLL
#include <Windows.h>
#include <detours.h>
#include<string>
#include<fstream>
#include<iostream>
using namespace std;
wofstream out;
BOOL(__stdcall * T14)
(
_Out_ LPRECT lprc,
_In_ int xLeft,
_In_ int yTop,
_In_ int xRight,
_In_ int yBottom
) = SetRect;
__declspec(dllexport) BOOL M14
(
_Out_ LPRECT lprc,
_In_ int L,
_In_ int T,
_In_ int R,
_In_ int B
){
out << "SetRect: " << L << " " << T << " " << R << " " << B << endl;
return T14(lprc, L, T, R, B);
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
out.open("out.txt");
out << "Attached" << endl;
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)T14, M14);
DetourTransactionCommit();
}
else if (dwReason == DLL_PROCESS_DETACH)
{
out << "detached" << endl;
out.close();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)T14, M14);
DetourTransactionCommit();
}
return TRUE;
}
Выход я получаю:
Прикрепленный
SetRect: 138 161 323 161
Так что программа рушится после того, как вызывается первая функция SetRect, любые идеи, почему это происходит?
Делает ли 'DetourTransactionCommit() == NO_ERROR'? – dxiv