a stand alone exe as a child in an MDI container

  • Thread starter Thread starter Sajid Saeed
  • Start date Start date
S

Sajid Saeed

Hi All,

I want to know if there is any way a complied EXE created in C# [App_A], can
be called by another EXE [App_MDI].
The App_MDI, should be the container for the App_A.
(In short App_A should be a child form in the App_MDI parent application)

note: App_A will only contain one form.

Thanks in Advance.

Sajid Saeed
 
Sajid,

I don't think that there is. You could try and set the parent of the
window to be the MDI parent, but I have serious doubts as to whether or not
that will work. Also, calling the other EXE will cause it to be in another
process, it has its own message loop, etc, etc.

Hope this helps.
 
Hi,

Thanks for ur comments, so it looks like, stand alone exe's will not be part
of the MDI.
I was expecting this answer...

Now is there anyway, where an assembly can be shared between two seperate
exe's, so that lets say if the parent application is closed, it forces the
other exe to clase as well.

Thanks once again

Sajid Saeed..
 
Hi,

Could you actually show a code snippet on how this could actually be done.

Thanks

Sajid Saeed

Chris Capel said:
Actually, there is a way, I believe. You just can't reference the file at
compile time. You load it at runtime using Assembly.Load or LoadFrom, and
then you use reflection to get the type of the form, and
Activator.CreateInstance to create an instance of the type. Of course, the
form in your EXE has to be of the right type and everything. But that should
do the trick. I use this sort of tactic to run all of the applications in my
system from a stub, with the files downloaded off of an application server,
to simplify deployment. Since they're EXEs, they can be run standalone if
needed, but you can reference them (albeit awkwardly) as if they were
libraries. This will probably work for you.

Hope this helps.

Chris

Sajid Saeed said:
Hi All,

I want to know if there is any way a complied EXE created in C# [App_A], can
be called by another EXE [App_MDI].
The App_MDI, should be the container for the App_A.
(In short App_A should be a child form in the App_MDI parent application)

note: App_A will only contain one form.

Thanks in Advance.

Sajid Saeed
 
Ooof - now that I went and shot my mouth off, I've earned myself a
bunch of looking. Seems I am missing '99 where it counts. While I'm
doing that (it might take a while, I might just have to hack it again)
I've at least recalled the architecture.

A small C++ DLL was used to invoke IE as an active-x control, but did
so in an offscreen window. This was then wrapped by a java interface
lib built from the type library (i have that but fat lot of good it
does) and then our 3D browser used that to get images.

Hmmm, maybe I misspoke in the first place, I did just say IE active X
control, not .exe. Hmmm, my apologies.

So, a little research

1) ::CreateProcess doesn't seem on casual inspection to offer the
parameters you need to do this

2) Windows can't tell the difference between a memory dc and a real
screen window, but if it's a 3D view, glacially slow would be the
order of the day (no hardware accelleration). Actually, for that
matter, I think you loose all 2D hardware accelleration too.

The link http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20585994.html

might be of some use, it's a discussion by people trying to hook
CreateWindow and prevent the
javascript alert popup. (hmmm, do I smell an exploit ?). The PlanetCpp
post on that page gives code to show how to hook notepad, tho some
comments indicate it has a few problems.

My guess is that IFF you have sufficient permissions on the machine,
you _may_ be able to intercept the apps createwindow call. If so, you
need to create an offscreen window and give that to the app. Across
processes, this could be a serious pita, and you may need to research
it extensively. If it is possible, you'll also need to assume msft
may move to prevent it in the future. It has the potential to open a
nasty can of worms.

So, sorry for my poor recollection, I was actually thinking of running
activex components offscreen. Now if your target app happens to
provide an activex interface, then you should be all set

I'll keep rooting about off and on, it's an interesting question.

regards
mmm
 
HAHA, I did it. Here's the code you need: (be sure to set
IsMdiContainer to true on the parent)

Form child=new Form();
Assembly asm=Assembly.LoadFile(***path to executable/dll***;
Type type=asm.GetType(***name of child form***,true,true);

object childform=Activator.CreateInstance(type);
child=(Form)childform;
child.MdiParent=this;
child.Show();

Austin Ehlers
 
Hi,
Thanks, i will have a go at it

Sajid
Chris Capel said:
Type childFormType =
Assembly.LoadFrom(fullExePath).GetType(nameOfChildFormType);

Form childForm = Activator.CreateInstance(childFormType);

This will give you an instance of your child form. Then just add it like you
would a From from in the same assembly.

Chris

Sajid Saeed said:
Hi,

Could you actually show a code snippet on how this could actually be done.

Thanks

Sajid Saeed

Chris Capel said:
Actually, there is a way, I believe. You just can't reference the file at
compile time. You load it at runtime using Assembly.Load or LoadFrom, and
then you use reflection to get the type of the form, and
Activator.CreateInstance to create an instance of the type. Of course, the
form in your EXE has to be of the right type and everything. But that should
do the trick. I use this sort of tactic to run all of the applications
in
my
system from a stub, with the files downloaded off of an application server,
to simplify deployment. Since they're EXEs, they can be run standalone if
needed, but you can reference them (albeit awkwardly) as if they were
libraries. This will probably work for you.

Hope this helps.

Chris

Hi All,

I want to know if there is any way a complied EXE created in C# [App_A],
can
be called by another EXE [App_MDI].
The App_MDI, should be the container for the App_A.
(In short App_A should be a child form in the App_MDI parent application)

note: App_A will only contain one form.

Thanks in Advance.

Sajid Saeed
 
Hi All,

I have written the code which is shown below, well actually copied yours...
Type childFormType =
Assembly.LoadFrom("c:\\WindowsApplication1").GetType("WindowsForm",true,true
);

Form childForm = (Form)Activator.CreateInstance(childFormType);

childForm.MdiParent=this;

childForm.Show();

I get the following error during runtime, on the first line of code itself

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in
mscorlib.dll

Additional information: File or assembly name WindowsApplication1, or one of
its dependencies, was not found.



you know what exactly am i doing wrong...

Sajid Saeed
 
I have written the code as per ur code.... shown below

Form child=new Form();

Assembly asm=Assembly.LoadFile("c:\\windowsapplication1.exe");

Type type=asm.GetType("WindowsForm",true,true);

object childform=Activator.CreateInstance(type);

child=(Form)childform;

child.MdiParent=this;

child.Show();


and i get the following runtime error

An unhandled exception of type 'System.TypeLoadException' occurred in
WindowsApplication2.exe

Additional information: Could not load type WindowsForm from assembly
WindowsApplication1, Version=1.0.1300.21115, Culture=neutral,
PublicKeyToken=null.

Anything that i am missing....

Sajid Saeed
Austin Ehlers said:
HAHA, I did it. Here's the code you need: (be sure to set
IsMdiContainer to true on the parent)

Form child=new Form();
Assembly asm=Assembly.LoadFile(***path to executable/dll***;
Type type=asm.GetType(***name of child form***,true,true);

object childform=Activator.CreateInstance(type);
child=(Form)childform;
child.MdiParent=this;
child.Show();

Austin Ehlers

Hi All,

I want to know if there is any way a complied EXE created in C# [App_A], can
be called by another EXE [App_MDI].
The App_MDI, should be the container for the App_A.
(In short App_A should be a child form in the App_MDI parent application)

note: App_A will only contain one form.

Thanks in Advance.

Sajid Saeed
 
Yes. The argument to LoadFrom has to be the complete filename. Include the
EXE extension.

Chris
 
Thanks.... It works.... don't know what i would have done without you
guys...

Thanks once again

Sajid Saeed
Austin Ehlers said:
Comments inline.

I have written the code as per ur code.... shown below

Form child=new Form();

Assembly asm=Assembly.LoadFile("c:\\windowsapplication1.exe");

Type type=asm.GetType("WindowsForm",true,true);

That should be
Type type=asm.GetType("name of form in other app",true,true);
Don't forget the namespace on it if you have one.
object childform=Activator.CreateInstance(type);

child=(Form)childform;

child.MdiParent=this;

child.Show();


and i get the following runtime error

An unhandled exception of type 'System.TypeLoadException' occurred in
WindowsApplication2.exe

Additional information: Could not load type WindowsForm from assembly
WindowsApplication1, Version=1.0.1300.21115, Culture=neutral,
PublicKeyToken=null.

Anything that i am missing....

Sajid Saeed
Austin Ehlers said:
HAHA, I did it. Here's the code you need: (be sure to set
IsMdiContainer to true on the parent)

Form child=new Form();
Assembly asm=Assembly.LoadFile(***path to executable/dll***;
Type type=asm.GetType(***name of child form***,true,true);

object childform=Activator.CreateInstance(type);
child=(Form)childform;
child.MdiParent=this;
child.Show();

Austin Ehlers

On Mon, 21 Jul 2003 11:29:18 +0300, "Sajid Saeed"

Hi All,

I want to know if there is any way a complied EXE created in C#
[App_A],
can
be called by another EXE [App_MDI].
The App_MDI, should be the container for the App_A.
(In short App_A should be a child form in the App_MDI parent application)

note: App_A will only contain one form.

Thanks in Advance.

Sajid Saeed
 
Thanks.... It works.... don't know what i would have done without you
guys...

Thanks once again

Sajid Saeed
 
System.TypeLoadException: Could not load type 'PEPAR02' from assembly 'PEPAR02, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
 
System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at MENU.Form1.Menu_Click(Object sender, EventArgs e) in
 
Last edited:
Back
Top