zoukankan      html  css  js  c++  java
  • Winform 程序中dll程序集嵌入exe可执行文件

    关于这方面,Google一下有很多方法,参考:

    http://blog.csdn.net/astonqa/article/details/7300856

    但按照以上的方法我并没有成功,于是继续找到了一篇更详细的步骤说明:

    http://adamthetech.com/2011/06/embed-dll-files-within-an-exe-c-sharp-winforms/

    按照以上链接的步骤去做,代码也不用修改,直接粘贴到构造函数中即可。

    再次附上相应的代码:

    C#版:

    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
    {
        string resourceName = new AssemblyName(args.Name).Name + ".dll";
        string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));
     
        using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
        {
            Byte[] assemblyData = new Byte[stream.Length];
            stream.Read(assemblyData, 0, assemblyData.Length);
            return Assembly.Load(assemblyData);
        }
    };

    VB.NET版:

    AddHandler AppDomain.CurrentDomain.AssemblyResolve,
        Function(sender, args)
            Dim resourceName As String = New AssemblyName(args.Name).Name + ".dll"
            Dim resource As String = Array.Find(Me.[GetType]().Assembly.GetManifestResourceNames(), Function(element) element.EndsWith(resourceName))
     
            Using stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource)
                Dim assemblyData As [Byte]() = New [Byte](stream.Length - 1) {}
                stream.Read(assemblyData, 0, assemblyData.Length)
                Return Assembly.Load(assemblyData)
            End Using
        End Function
  • 相关阅读:
    第一周作业
    C语言I博客作业08
    十四周助教总结
    十三周助教总结
    C语言I博客作业07
    C语言II博客作业01
    学期总结
    C语言I博客作业08(未完成)
    C语言I博客作业07
    C语言I博客作业06
  • 原文地址:https://www.cnblogs.com/jmpep/p/4486099.html
Copyright © 2011-2022 走看看