void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { switch (id) { case IDCANCEL: EndDialog(hWnd, id); break; case IDC_INJECT: DWORD dwProcessId = GetDlgItemInt(hWnd, IDC_PROCESSID, NULL, FALSE); if (dwProcessId == 0) { // A process ID of 0 causes everything to take place in the // local process; this makes things easier for debugging. dwProcessId = GetCurrentProcessId(); } TCHAR szLibFile[MAX_PATH]; GetModuleFileName(NULL, szLibFile, _countof(szLibFile)); PTSTR pFilename = _tcsrchr(szLibFile, TEXT('\\')) + 1; _tcscpy_s(pFilename, _countof(szLibFile) - (pFilename - szLibFile), TEXT("22-ImgWalk.DLL")); if (InjectLib(dwProcessId, szLibFile)) { chVERIFY(EjectLib(dwProcessId, szLibFile)); chMB("DLL Injection/Ejection successful."); } else { chMB("DLL Injection/Ejection failed."); } break; } }
// MBCS version of EjectLib void Injector::EjectLib(DWORD ProcID, const std::string& Path) { // Convert path to unicode std::wstring UnicodePath(Path.begin(),Path.end()); // Call the Unicode version of the function to actually do the work. EjectLib(ProcID, UnicodePath); }