Хорошо, спасибо за ваши предложения, я нашел рабочий путь!
DWORD targetProcessId;
int APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (_stricmp(entry.szExeFile, "target.exe") == 0)
{
targetProcessId = entry.th32ProcessID;
}
}
}
CloseHandle(snapshot);
if (reason == DLL_PROCESS_ATTACH)
{
if (GetCurrentProcessId() == targetProcessId)
{
//MY Code
}
}
return true;
}