从资源运行可执行文件

时间:2013-12-28 10:14:23

标签: c# resources

我已经使用C ++制作了控制台应用程序。现在我想将我的应用程序添加到我的Visual Studio C#资源中,使其每次从启动时运行。我使用过GetManifestResourceStream,但对我不起作用。我还在构建操作属性中设置了嵌入式资源。

Assembly asm = null;
using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApplication1.Resources.MyApplication.exe"))
{
    if (manifestResourceStream != null)
    {
        try
        {
            byte[] numArray = new byte[manifestResourceStream.Length];
            manifestResourceStream.Read(numArray, 0, numArray.Length);
            MessageBox.Show("Going to run!");
            asm = Assembly.Load(numArray);
        }
        catch
        {
            MessageBox.Show("I'm failed!");
        }
    }
    MessageBox.Show("I'm failed! from first if");
}

if (asm != null)
{
    MessageBox.Show("ASM not null");
    var entryPoint = asm.EntryPoint;
    var commandArgs = new string[1];
    var returnValue = entryPoint.Invoke(null, commandArgs);
}  

从我在这里看到的,我把这四个消息框放在不同的范围内让我轻松调试。但是,我不知道为什么会弹出前三个messagebox(Accept not null)。

我的目标:我想在运行另一个可执行文件的同时运行可执行文件。我不想使用ProcessStart,因为它分隔两个文件。

0 个答案:

没有答案
相关问题