none
Can a dll call methods in the calling class? RRS feed

  • Question

  • I am creating a pretty complex app that controls a high end radio.  In addition to my app I want to integrate an open source program that does the following:

    It creates a tcp server and listens for clients that send commands.  These clients are other third party products that want certain information from the radio and also provide certain information to the radio.  The open source software basically has a thread dealing with the tcpip server part and there is several methods that process the received information, finally telling the radio what information it wants or what the radio has to do.

    This app, contains several classes and a lot of code.  I would like to put this in a dll instead of having it as part of my code.  This should be straight forward, and I could execute the code in the dll when I initialize it.

    My question is, this dll would need access to two methods in my calling program.  It would call these methods at any time.  I would have a separate thread to deal with this

    So my question is can the dll call methods in the calling exe?  How could I do this?


    Thanks for any help!

    Saturday, April 13, 2013 5:09 AM

Answers

  • Supply a callback delegate to the dll or subscribe to an event in the dll.

    • Marked as answer by tomb1818 Monday, April 15, 2013 3:03 PM
    Saturday, April 13, 2013 1:00 PM

All replies

  • Definitely but not directly. You can use reflection to call a method (in calling exe) in  the dll.

    Some example are here,

    http://www.csharp-examples.net/reflection-examples/

    http://www.csharp-examples.net/reflection-examples/

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Saturday, April 13, 2013 11:04 AM
  • Supply a callback delegate to the dll or subscribe to an event in the dll.

    • Marked as answer by tomb1818 Monday, April 15, 2013 3:03 PM
    Saturday, April 13, 2013 1:00 PM
  • Just create delegate in a third component that will used to make the communication possible. Here is what you need to do

    1) Create a helper DLL project that will have one delegate. This delegate will take one method name and required number of arguments

    2) refer this DLL in your EXE and main DLL project, so that you get definition of this delegate in both places.

    3) from your EXE when you call the method in your main DLL, pass the delegate (and name of method that you want to call back).

    4) now from your main DLL, whenever you want to call the method in EXE, just invoke delegate reference (you will have to save this delegate reference in you class of main DLL.


    Pravin Chandankhede

    Sunday, April 14, 2013 8:55 AM
  • Thanks, this is the first time I used this forum.  Good answers.  Should be good to get me going!
    Monday, April 15, 2013 3:03 PM