So i'm writing a DLL injector using a DLL injection library I found. It works well except for this:
Heres all of the injection code:
When I run my program, and I click the button that activates this code, it crashes and I get an unhandled exception (IndexOutOfRangeException) for this line:
I cant seem to get around this! What is causing it?
The process IS running.
Heres all of the injection code:
//inject dll here var injector = InjectionMethod.Create(InjectionMethodType.ManualMap); var processId = Process.GetProcessesByName(proc)[0].Id; if (processId == 0) { info.Text = "Failed to find game. Closing."; Thread.Sleep(2000); this.Close(); } var hModule = IntPtr.Zero; using (var img = new PortableExecutable(loc)) hModule = injector.Inject(img, processId); Thread.Sleep(1000); countdown.Enabled = true;
When I run my program, and I click the button that activates this code, it crashes and I get an unhandled exception (IndexOutOfRangeException) for this line:
Process.GetProcessesByName(proc)[0].Id;
I cant seem to get around this! What is causing it?
The process IS running.