Member Avatar for lithium112

Ok, I am really hoping there is someone who has some experience with old Cobol forms(exe's) and loading them into an MDI Parent as an MDI child. At the moment, I am calling the exe file as a process, but from what I see at the moment, there is no way to load the process onto the MDI Parent. Would anybody know how to do this?

I have also tried with the Assembly.LoadFile and .LoadFrom methods but I keep getting a manifest error. Any insight would be greatly appreciated.

Member Avatar for lithium112

I should probably also mention that I have tried using the SetParent Windows API.

What code are you using to call the SetParent routine? What is it doing wrong or not doing right? If done correctly and the COBOL form will run correctly it should work.

Member Avatar for lithium112
[DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        Process process = Process.Start(filetoexecute, args);
                    process.StartInfo = si;
                    process.EnableRaisingEvents = true;
                    process.Exited += ProcessExited;
                    process.StartInfo.CreateNoWindow = true;
                     process.WaitForInputIdle();

                        SetParent(process.Handle, mainform.handle);

I have tried process.MainWindowHandle but it is always 0, even if I refresh it.

See if this works:

Process process = new Process();
process.StartInfo = si;
process.StartInfo.FileName = filetoexecute;
process.StartInfo.Arguments = args;
process.EnableRaisingEvents = true;
process.Exited += ProcessExited;
process.Start();
process.WaitForInputIdle();
SetParent(process.MainWindowHandle, this.handle);
Member Avatar for lithium112

Sorry it took so long to respond. I just tried it and it still didn't work. What's kind of wierd is that when the application opened, it pulled in a screen behind my application (my visual studio screen with code) and placed it on the form. I think we'll go ahead and leave as is for now without setting the MDI parent.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.