Click here to Skip to main content
15,920,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello CodeProject,
I want to embed a game(like : GTA etc.) inside my Forms Application, I know how you do it with simple Windows Forms Applications using the following Code ::
C#
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
//<JUMPING TO BUTTON_1 CLICK>
/////////////////////////////////.........................................................\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 private void button1_Click(object sender, EventArgs e)
        {
            try
            {
            Process p = Process.Start(textBox1.Text,textBox1.Text);
            p.WaitForInputIdle(); // Allow the process to open it's window
            SetParent(p.MainWindowHandle, panel1.Handle); //Set the Windows Parent as Panel1
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR DUDE!!!!!\n" + ex.Message);
            }
        }
        //Import a DLL called User32.dll for catching the Form
        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

It works for Normal Applications like Notepad,QEMU etc.
But for complex applications like Games,Browsers,etc. I get the following problems
1) For mostly Games, They are Not able to load resources properly, for instance take IGI,
when I start igi2.exe from my application I get a error message saying
"COULD NOT LOAD FILE : LOCAL:weapons.res"

Same goes for Games that require resources to be loaded from HDD.
2)When I start chrome,iexplore,explorer.exe or any such complex application my Form is unable to catch it. Also My error handler show the following message(sometimes) :
"ERROR DUDE!!!!!!!!!!!!!!!!!
Process has exited"


Any Solution/Suggestion to this?
Any help would be appreciated

~Sids123
Posted
Updated 10-Aug-13 23:27pm
v4
Comments
Maciej Los 11-Aug-13 7:26am    
Most of games (like GTA) does not use single executable file... There are several files installed with them (dll's, meta files, media files, etc.). It wouldn't work...

1 solution

I think you can try with something like..
Embedding-an-external-executable-inside-a-c-sharp-program[^]
Or,
can embed an executable as resource inside a project like..
http://www.cs.nyu.edu/~vs667/articles/embed_executable_tutorial/[^]
 
Share this answer
 
v3
Comments
Maciej Los 11-Aug-13 7:28am    
Shuvro, please, see my comment to the question. Your solution is good to add executable file as a resocurce file, but...
ridoy 11-Aug-13 7:39am    
Yes Maciej you said rightly,and i also agree it.But those solutions seems to me a possible way for the games which contains single executable files.But it is right,most complex games won't work in this way as they have a number of files.
Maciej Los 11-Aug-13 7:42am    
Your answer all together with comment deserves for 5!
ridoy 11-Aug-13 7:45am    
Thanks Maciej,:)
sid2x 11-Aug-13 9:18am    
So any 3rd Party Library that does that job for me???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900