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. dll function

dll function

Scheduled Pinned Locked Moved C#
question
9 Posts 5 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.
  • U Offline
    U Offline
    User 589870
    wrote on last edited by
    #1

    hi, i want to add a method to dll which could return a value.hw can i do that?

    C T 2 Replies Last reply
    0
    • U User 589870

      hi, i want to add a method to dll which could return a value.hw can i do that?

      C Offline
      C Offline
      Calla
      wrote on last edited by
      #2

      Do you have the source code to the dll? Is it a .NET assembly? I think we all need more info from your side to be able to help.. :confused:

      U 1 Reply Last reply
      0
      • C Calla

        Do you have the source code to the dll? Is it a .NET assembly? I think we all need more info from your side to be able to help.. :confused:

        U Offline
        U Offline
        User 589870
        wrote on last edited by
        #3

        yes i have the source code nw i want to add a function which should return a string.Also i want to call the function outside dll.hw to do that?

        P 1 Reply Last reply
        0
        • U User 589870

          hi, i want to add a method to dll which could return a value.hw can i do that?

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          Member 590310 wrote:

          i want to add a method to dll which could return a value.hw can i do that?

          In DLL:-

          namespace my
          {

          class ABC
          {
          private int _intValue=10;
          public int ReturnValue()
          {
          return _intValue;
          }
          }

          In your Executable:- First add reference of DLL , then following code will suffix

          my.ABC oABC = new my.ABC();
          Console.WriteLine(oABC.ReturnValue());

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
          Never mind - my own stupidity is the source of every "problem" - Mixture

          cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

          U 1 Reply Last reply
          0
          • T ThatsAlok

            Member 590310 wrote:

            i want to add a method to dll which could return a value.hw can i do that?

            In DLL:-

            namespace my
            {

            class ABC
            {
            private int _intValue=10;
            public int ReturnValue()
            {
            return _intValue;
            }
            }

            In your Executable:- First add reference of DLL , then following code will suffix

            my.ABC oABC = new my.ABC();
            Console.WriteLine(oABC.ReturnValue());

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

            U Offline
            U Offline
            User 589870
            wrote on last edited by
            #5

            0k thats fine but i dnt want to add dll reference instead i want to load it on runtime like that. Assembly a = Assembly.LoadFrom(Application.StartupPath + @"\"+strLangName+".dll"); then hw to call its function?

            C A 2 Replies Last reply
            0
            • U User 589870

              yes i have the source code nw i want to add a function which should return a string.Also i want to call the function outside dll.hw to do that?

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              If you have the source code, you edit one of the classes (or add a new one) and create a method that does this. This is pretty basic stuff.

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              1 Reply Last reply
              0
              • U User 589870

                0k thats fine but i dnt want to add dll reference instead i want to load it on runtime like that. Assembly a = Assembly.LoadFrom(Application.StartupPath + @"\"+strLangName+".dll"); then hw to call its function?

                C Offline
                C Offline
                Calla
                wrote on last edited by
                #7

                Maybe this can help?

                1 Reply Last reply
                0
                • U User 589870

                  0k thats fine but i dnt want to add dll reference instead i want to load it on runtime like that. Assembly a = Assembly.LoadFrom(Application.StartupPath + @"\"+strLangName+".dll"); then hw to call its function?

                  A Offline
                  A Offline
                  Abdul Rahman Hamidy
                  wrote on last edited by
                  #8

                  as calla suggested, bellow is the simple way to do it.

                  string asseblyId = @"NewAssembly,Version=1.0.0.0,Culture=neutral,PublicKeyToken=531174506d670b8c";
                  ObjectHandle Handle=Activator.CreateInstance(asseblyId, "NewAssembly.ClassName");
                  object obj = Handle.Unwrap();
                  object[] parm = new object[] { 2, 4 };
                  object[] parm1 = new object[] { "Hello" };
                  Type t = obj.GetType();
                  //Invoketion of the Method...........
                  t.InvokeMember("DoIt", BindingFlags.Public | BindingFlags.NonPublic|BindingFlags.InvokeMethod|BindingFlags.Instance ,null , obj ,null);
                  int i=(int)t.InvokeMember("Add", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj,parm);
                  Console.WriteLine(i);
                  //Set And Get the property
                  t.InvokeMember("Name", BindingFlags.Public | BindingFlags.SetProperty|BindingFlags.Instance , null, obj, parm1);
                  string strname=(string)t.InvokeMember("Name", BindingFlags.Public|BindingFlags.GetProperty| BindingFlags.Instance, null, obj, null);
                  Console.WriteLine(strname);

                  and bellow is the methods for class in dll

                  public class Employee
                  {
                  public string _name;
                  public int _age;
                  public string _address;
                  public string _id;
                  public Employee()
                  {
                  }
                  public string Name
                  {
                  get
                  {
                  return this._name;
                  }
                  set
                  {
                  this._name = value;
                  }
                  }
                  public int Age
                  {
                  get
                  {
                  return this._age;
                  }
                  set
                  {
                  this._age = value;
                  }
                  }
                  public string ID
                  {
                  get
                  {
                  return this._id;
                  }
                  set {
                  this._id = value;
                  }
                  }
                  public int Add(int i, int j)
                  {
                  return i + j;
                  }
                  public void DoIt()
                  {
                  Console.WriteLine("Welcome from DO it");
                  }
                  public override string ToString()
                  {
                  return String.Format("ID :{0} Name:={1} Age{2}", this._id, this._name, this._age);
                  }
                  }

                  hope this helps!

                  Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

                  T 1 Reply Last reply
                  0
                  • A Abdul Rahman Hamidy

                    as calla suggested, bellow is the simple way to do it.

                    string asseblyId = @"NewAssembly,Version=1.0.0.0,Culture=neutral,PublicKeyToken=531174506d670b8c";
                    ObjectHandle Handle=Activator.CreateInstance(asseblyId, "NewAssembly.ClassName");
                    object obj = Handle.Unwrap();
                    object[] parm = new object[] { 2, 4 };
                    object[] parm1 = new object[] { "Hello" };
                    Type t = obj.GetType();
                    //Invoketion of the Method...........
                    t.InvokeMember("DoIt", BindingFlags.Public | BindingFlags.NonPublic|BindingFlags.InvokeMethod|BindingFlags.Instance ,null , obj ,null);
                    int i=(int)t.InvokeMember("Add", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj,parm);
                    Console.WriteLine(i);
                    //Set And Get the property
                    t.InvokeMember("Name", BindingFlags.Public | BindingFlags.SetProperty|BindingFlags.Instance , null, obj, parm1);
                    string strname=(string)t.InvokeMember("Name", BindingFlags.Public|BindingFlags.GetProperty| BindingFlags.Instance, null, obj, null);
                    Console.WriteLine(strname);

                    and bellow is the methods for class in dll

                    public class Employee
                    {
                    public string _name;
                    public int _age;
                    public string _address;
                    public string _id;
                    public Employee()
                    {
                    }
                    public string Name
                    {
                    get
                    {
                    return this._name;
                    }
                    set
                    {
                    this._name = value;
                    }
                    }
                    public int Age
                    {
                    get
                    {
                    return this._age;
                    }
                    set
                    {
                    this._age = value;
                    }
                    }
                    public string ID
                    {
                    get
                    {
                    return this._id;
                    }
                    set {
                    this._id = value;
                    }
                    }
                    public int Add(int i, int j)
                    {
                    return i + j;
                    }
                    public void DoIt()
                    {
                    Console.WriteLine("Welcome from DO it");
                    }
                    public override string ToString()
                    {
                    return String.Format("ID :{0} Name:={1} Age{2}", this._id, this._name, this._age);
                    }
                    }

                    hope this helps!

                    Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    Good to see developer from Afghanistan... welcome brother!

                    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