我正在做一个项目。任务是创建一个 DLL 项目。在该项目中,我有一个带有一组方法的现有 DLL。通过使用现有的 DLL,我可以调用一些方法并在新的 DLL 中创建一些方法。
这在 C# 中可能吗?创建这样一个项目的可能性和方法是什么?
如果你想将该DLL隐藏在你自己的DLL的内容中,你可以简单地将它放入资源中。从资源的角度来看,DLL 只是一个像任何其他文件一样的文件,您可以简单地将其添加到程序资源中,然后将文件拖放到您需要的位置。
然而,这将禁止您使用隐式链接,并且您必须显式链接 DLL。MSDN 已经在这里提供了一个相当合理的教程。
using System;
using System.Reflection;
public class Asmload0
{
public static void Main()
{
// Use the file name to load the assembly into the current
// application domain.
Assembly a = Assembly.Load("example");
// Get the type to use.
Type myType = a.GetType("Example");
// Get the method to call.
MethodInfo myMethod = myType.GetMethod("MethodA");
// Create an instance.
object obj = Activator.CreateInstance(myType);
// Execute the method.
myMethod.Invoke(obj, null);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您想创建自己的 DLL,只使用旧的 DLL,您只需添加引用即可。然后你可以设置“Use Copy Local”,但你必须分发两个文件:

如果您想简单地通过编译器/链接器(内置于 Visual Studio 中)创建“静态链接”,您需要使用静态链接库(LIB)而不是动态链接库(DLL)...
或者您可以尝试阅读“如何静态链接 .DLL? ”,这似乎提供了一些有关如何执行此操作的指导(专有软件)。
| 归档时间: |
|
| 查看次数: |
5201 次 |
| 最近记录: |