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 I can use a function from another application

How I can use a function from another application

Scheduled Pinned Locked Moved C#
csharp
4 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hai, I am having two C# applications.I need to use some functions of second application in First application. How I can do this.I need to know complete steps. I am sure somebody can show my way. Thank you, Rahul.

    D 1 Reply Last reply
    0
    • L Lost User

      Hai, I am having two C# applications.I need to use some functions of second application in First application. How I can do this.I need to know complete steps. I am sure somebody can show my way. Thank you, Rahul.

      D Offline
      D Offline
      Daniel Monzert
      wrote on last edited by
      #2

      One option is at design time: If the other application's EXE name is called 'app.exe', copy it to 'app.exe.dll' and add it as 'Reference' to your project. Right-click on "References" in the Visual Studio's Solution Explorer, choose "Add Reference..." and "Browse..." for the 'app.exe.dll' .NET tab of the dialog. If app.exe has a class "MyClass" in the namespace "MyApp.MyNamespace" you can use it in your application with "MyApp.MyNamespace.MyClass myClass = new MyApp.MyNamespace.MyClass()", for example. /EDIT: The reason for renaming the app.exe to app.exe.dll is, that Visual Studio allows only .DLL files as file references.

      D 1 Reply Last reply
      0
      • D Daniel Monzert

        One option is at design time: If the other application's EXE name is called 'app.exe', copy it to 'app.exe.dll' and add it as 'Reference' to your project. Right-click on "References" in the Visual Studio's Solution Explorer, choose "Add Reference..." and "Browse..." for the 'app.exe.dll' .NET tab of the dialog. If app.exe has a class "MyClass" in the namespace "MyApp.MyNamespace" you can use it in your application with "MyApp.MyNamespace.MyClass myClass = new MyApp.MyNamespace.MyClass()", for example. /EDIT: The reason for renaming the app.exe to app.exe.dll is, that Visual Studio allows only .DLL files as file references.

        D Offline
        D Offline
        Daniel Monzert
        wrote on last edited by
        #3

        Another option at runtime: You can load a .NET Assembly at runtime. Assembly assembly = Assembly.LoadFile("app.exe"); Type type = assembly.GetType("MyApp.MyNamespace.MyClass"); object obj = Activator.CreateInstance(type); "type" may be -null- if the given type name wasn't found in the assembly. You can create an object without loading the assembly through the "Activator.CreateInstanceFrom" method. Just search for some articles on how using Assemblies that are loaded at runtime and/or the Activator class. I prefer the implementation at design time though.

        L 1 Reply Last reply
        0
        • D Daniel Monzert

          Another option at runtime: You can load a .NET Assembly at runtime. Assembly assembly = Assembly.LoadFile("app.exe"); Type type = assembly.GetType("MyApp.MyNamespace.MyClass"); object obj = Activator.CreateInstance(type); "type" may be -null- if the given type name wasn't found in the assembly. You can create an object without loading the assembly through the "Activator.CreateInstanceFrom" method. Just search for some articles on how using Assemblies that are loaded at runtime and/or the Activator class. I prefer the implementation at design time though.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hai Zarrab, Thanks much for your incredible help and information.I will follow the way that you have specified . Thank you, Rahul.

          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