Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to use the a interface declared in a dll

how to use the a interface declared in a dll

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goldli
    wrote on last edited by
    #1

    there are interfaces declared in a dll below -------------------- Encrypt.dll ------------------------- interface IDESCoder { string CreateCode(string IVString,string KeyString,string StringToEncode); string GetCode(string IVString, string KeyString, string StringToDecode); } interface IMD5Encoder { string CreateCode(string StringToEncode); } public class ClsDES : IDESCoder { public string CreateCode(string IVString, string KeyString, string StringToEncode) { } public string GetCode(string IVString, string KeyString, string StringToDecode) { } private Boolean CheckIVKey(string IVString, string KeyString, string StringToEncode) { } } public class CldMD5 : IMD5Encoder { public string CreateCode(string StringToEncode) { } } ----------------------------------------------------------------------- and there is a Host -------------------- test.exe ---------------------------------------- string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllType = myDllAssembly.GetType("IDESCoder"); if (dllType!=null) { ......?????? } ------------------------------------------------------------------------- then,what should i do next with Reflection if i want to use Interface declared in the dll??

    W 1 Reply Last reply
    0
    • G goldli

      there are interfaces declared in a dll below -------------------- Encrypt.dll ------------------------- interface IDESCoder { string CreateCode(string IVString,string KeyString,string StringToEncode); string GetCode(string IVString, string KeyString, string StringToDecode); } interface IMD5Encoder { string CreateCode(string StringToEncode); } public class ClsDES : IDESCoder { public string CreateCode(string IVString, string KeyString, string StringToEncode) { } public string GetCode(string IVString, string KeyString, string StringToDecode) { } private Boolean CheckIVKey(string IVString, string KeyString, string StringToEncode) { } } public class CldMD5 : IMD5Encoder { public string CreateCode(string StringToEncode) { } } ----------------------------------------------------------------------- and there is a Host -------------------- test.exe ---------------------------------------- string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllType = myDllAssembly.GetType("IDESCoder"); if (dllType!=null) { ......?????? } ------------------------------------------------------------------------- then,what should i do next with Reflection if i want to use Interface declared in the dll??

      W Offline
      W Offline
      wulixu
      wrote on last edited by
      #2

      string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllTypeInterface = myDllAssembly.GetType("IDESCoder");//this statement may have some question Type dllTypeClass = myDllAssembly.GetType("ClsDES");//this statement may have some question if (dllType!=null) { //TODO---you can use Factory pattern to improve it dllTypeInterface interf=Activator.CreateInstance(dllTypeClass ); } and you can choose another simpler way to resolve the problem. first of all,You should Add references into your application in VS.NET. then you can use it like using some interface or class in mscorlib.dll. for example. using System.Int32;

      It is very useful for everyone to show your own ideas to others.---Discussion is the power of improvement.

      G 1 Reply Last reply
      0
      • W wulixu

        string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllTypeInterface = myDllAssembly.GetType("IDESCoder");//this statement may have some question Type dllTypeClass = myDllAssembly.GetType("ClsDES");//this statement may have some question if (dllType!=null) { //TODO---you can use Factory pattern to improve it dllTypeInterface interf=Activator.CreateInstance(dllTypeClass ); } and you can choose another simpler way to resolve the problem. first of all,You should Add references into your application in VS.NET. then you can use it like using some interface or class in mscorlib.dll. for example. using System.Int32;

        It is very useful for everyone to show your own ideas to others.---Discussion is the power of improvement.

        G Offline
        G Offline
        goldli
        wrote on last edited by
        #3

        i know the way you said, and, you see , if i just know the interface'name ,can i have the dllTypeInterface object?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups