如何在DLL文件中嵌入文件和exe [英] How to embed files and exe in a DLL file

查看:142
本文介绍了如何在DLL文件中嵌入文件和exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi codeproject成员



无论如何调用dll中的文件,例如第三方exe。



i主要想要它,所以我可以将我的所有文件存储在一个单独的位置,并且可以直接从dll自己调用文件。

这是可能的。



我尝试了什么:



i尝试了很多网站,但可以看到我正在寻找的选项。

hi codeproject members

is there anyway calling the files in a dll and such as a third party exe.

i mainly want it so i can store all my files in a separate location and be able to call the file direct from the dll it self.
is this possible .

What I have tried:

i tried many sites but can see the option am looking for.

推荐答案

是的,有可能:

Yes, it's possible:
string GetResourceFile(string assemblyPath, string nameSpace, string fileName)
    {
    Assembly assembly = Assembly.LoadFrom(assemblyPath);
    string resourceName = nameSpace + "." + fileName;
    string resource = null;
    using (Stream stream = assembly.GetManifestResourceStream(resourceName))
        {
        using (StreamReader reader = new StreamReader(stream))
            {
            resource = reader.ReadToEnd();
            }
        }
    return resource;
    }



例如,如果MyAssembly有一个文件夹Resources,其中包含一个文件夹TextFiles,其中包含一个嵌入式资源文本文件RevisionHistory.txt :


For example, if MyAssembly has a folder "Resources", containing a folder "TextFiles", containg an embedded resource text file "RevisionHistory.txt":

GetResourceFile(@"D:\Testing\MyAssembly.dll", "MyAssembly.Resources.TextFiles", "RevisionHistory.txt");


这篇关于如何在DLL文件中嵌入文件和exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆