Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

IndexOutOfRangeException Problem!

$
0
0
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:
//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.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>