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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Calling a method in a library to an exe file using a delegate

Calling a method in a library to an exe file using a delegate

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    MAW30
    wrote on last edited by
    #1

    I am trying to call the following method from a library to an exe file using a delegate, can anyone help with the following: namespace xxx { public delegate void DelegateGetMethodA(Int32 b); class Library1 { MethodA() // How do I call MethodA here using delegates } } namespace xxx { static class Program { [STAThread] public static void Main() { ExecutionClass exe = new ExecutionClass(); DelegateGetMethodA GetMethodA = new DelegateGetMethodA(exe.MethodA); } } } namespace xxx { class ExecutionClass { void MethodA(Int32 b) { a = b + c; } } } Thanks in advance, Michael

    S 1 Reply Last reply
    0
    • M MAW30

      I am trying to call the following method from a library to an exe file using a delegate, can anyone help with the following: namespace xxx { public delegate void DelegateGetMethodA(Int32 b); class Library1 { MethodA() // How do I call MethodA here using delegates } } namespace xxx { static class Program { [STAThread] public static void Main() { ExecutionClass exe = new ExecutionClass(); DelegateGetMethodA GetMethodA = new DelegateGetMethodA(exe.MethodA); } } } namespace xxx { class ExecutionClass { void MethodA(Int32 b) { a = b + c; } } } Thanks in advance, Michael

      S Offline
      S Offline
      sudeesh
      wrote on last edited by
      #2

      create an instance of the delegate like DelegateGetMethodA _delegateGetMethodA = null; in the class where you want to invok the method. Then set the method to the delegate Library1 _library = new Library1(); _library.SetDelegate(exe.MethodA); In the SetDelegate methods assign the value to the _delegateGetMethodA Then you can call the delegate _delegateGetMethodA (parameters);

      Sudeesh

      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