Re: Invoking Console Application's Program.Main from another project

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 20 Jul 2009 09:15:03 -0700, Shikari Shambu
<shikarishambu70@xxxxxxxxxxx> wrote:

Hi,
Is it possible to invoke the entry point of a console application project from another project. Or, do I have to invoke the associated exe as per the post below
http://blogs.msdn.com/csharpfaq/archive/2004/06/01/146375.aspx

You can try referencing the .exe as an assembly for your own application
(just as you would a managed .dll), and then calling the entry point
directly.

In unmanaged code, this would be an "iffy proposition", because doing so
might skip some important initialization. But I think there's a good
chance .NET would handle this correctly. I haven't done it myself, so I
don't know for sure, but if it's something you really want to do, you
might as well try.

If the other application isn't a managed application, you might be able to
still do it, by using the unmanaged LoadLibrary() and GetProcAddress().
But as I said, I would be less confident that could be done safely.
Simply loading the .exe as a library might cause the necessary
initialization to happen, but it might not; I don't recall the specifics.

Pete
.



Relevant Pages