4

I am working on a project. The task is to create a DLL Project. In that project, I am having an existing DLL with set of methods. With the use of existing DLL I can call some methods and create some methods in the new DLL.

Is that Possible in C#? What are the possibilities and methods to create such a project?

E_net4
  • 27,810
  • 13
  • 101
  • 139
Ahamed Nafeel
  • 49
  • 3
  • 13
  • 1
    like a DLLception...? – Thomas Ayoub May 05 '15 at 09:27
  • 1
    Do you want to actually create methods at runtime, or just call methods on an existing DLL? You can certainly embed another DLL as a resource and extract and load it at runtime if that's what you need. As it stands though, this question is a little unclear. Be careful it doesn't end up too broad if you clarify anything though... – James Thorpe May 05 '15 at 09:28
  • It definitelly is possible. Please, provide more information - what IDE are you using? Do you want the `Existing DLL` to be "hidden" inside your resulting .dll, or are you fine with it being part of the project output? – jmodrak May 05 '15 at 09:28
  • Yes. You can use **ILMerge** tool to merge existing DLLs into one file. More info http://www.codeproject.com/Articles/9364/Merging-NET-assemblies-using-ILMerge. – Fka May 05 '15 at 09:29
  • The IDE is Visual studio 2008. The DLL Might be hidden inside our resulting dll. I am using C# code. – Ahamed Nafeel May 05 '15 at 09:30
  • James. My Question is simple. I need to create a DLL with an existing DLL. The Existing DLL functionalities might be used in the New DLL. The Existing DLL behind the Original One.. – Ahamed Nafeel May 05 '15 at 09:32
  • If the existing DLL is a thrid party one, be carefull about its licence. Not so much DLL creators like to see it hidden in others libraries. – IronSlug May 05 '15 at 09:37
  • IronSlug I have the license of that dude – Ahamed Nafeel May 05 '15 at 09:38

1 Answers1

6

If you want to hide that DLL in the contents of your own DLL, you can simply put it into resources. From the standpoint of resources, a DLL is just a file like any other and you can simply add it to program resources and simply drop the file where you need it.

However this will prohibit you from using implicit linking and you will have to link the DLL explicitly. MSDN already offers a quite reasonable tutorial already and here.

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);
    }
}

If you want to create your own DLL that just uses the old one you may just Add Reference. Then you can set up "Use Copy Local", but you will have to distribute two files:

Copy Local Visual Studio Screenshot


And if you want to make "static link" simply by compiler/linker (build in to visual studio) you need to use a statically linked library (LIB) and not a dynamically linkws library (DLL)...

Or you can try reading "How to link a .DLL statically?" which seems to provide some guidance (proprietary software) on how to do this.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Vyktor
  • 20,559
  • 6
  • 64
  • 96
  • Main Problem is I need to create a DLL Project with the Existing one. I want to use the existing one in my project by using reference. Can You tell me how to create a DLL With Migrating the Existing DLL in C#.?? – Ahamed Nafeel May 05 '15 at 10:17
  • Boss I dont have the "Old DLL project". I only Have a DLL. I am Creating a new DLL Project. To enhance something and Create a New DLL with existing features of the old DLL. – Ahamed Nafeel May 05 '15 at 10:26
  • thank u so much .... But I already refer the page. I done the following methods by creating a net module. But It shows some errors. That's Why I have the doubt about my path is correct or not. – Ahamed Nafeel May 05 '15 at 10:39