How to call and control a windows app (.exe) from a class library (.dll) in .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • minermadison
    New Member
    • Feb 2008
    • 4

    How to call and control a windows app (.exe) from a class library (.dll) in .net

    Hello,

    I need to have a .dll start up and pass some information to an .exe, then receive some information back.

    The only way I can think of doing this currently is to use Process.Start and/or ProcessStartInf o to start the .exe, then have the .exe and the .dll communicate through text files. I know this could work but it would be really messy and I'm hoping for a cleaner solution.

    Is there anyway to import and use the classes in an assembly (.exe) like you can import and use the classes in a library (.dll?). I tried adding my .exe as a reference for the .dll and using something like the following in my .dll :
    _______________ _____________
    WinUI.MyWinForm myWinForm = new WinUI.MyWinForm ();
    myWinForm.Show( );
    _______________ _____________
    (WinUI is my application namespace/project and MyWinForm is the name a the form...)

    But as soon as the the function containing the above code (in the .dll) was called I got the following error :

    System.IO.FileN otFoundExceptio n "Could not load file or assembly 'WinUI"

    What I'm trying to accomplish is have a .net 2.0 class in a library (.dll) start up a .net 2.0 application (.exe) open up a windows form that lives in the .exe (the form can be the .exe's start up object), pass some data to the aplcation, call a couple functions and then close it (or leaving it open would be ok too)....

    And help or code samples very much appreciated.

    P.S.
    Unfortunately I can not work the other way around (of course), the application can not be started first and simply reference the class library, that would be way too easy :) This whole process must start with and be controlled by the library. Also, the form in question must live in the .exe, trust me (long story).

    Thanks in advance!

    and sorry if I'm doing something wrong here; this is my first post :)
  • SharpDeveloper
    New Member
    • Feb 2008
    • 12

    #2
    Hello
    I hope your exe program should be in the same directory as the .DLL.
    You can copy the .EXE to the .DLL project directory and try once.

    Happy Programming

    Originally posted by minermadison
    Hello,

    I need to have a .dll start up and pass some information to an .exe, then receive some information back.

    The only way I can think of doing this currently is to use Process.Start and/or ProcessStartInf o to start the .exe, then have the .exe and the .dll communicate through text files. I know this could work but it would be really messy and I'm hoping for a cleaner solution.

    Is there anyway to import and use the classes in an assembly (.exe) like you can import and use the classes in a library (.dll?). I tried adding my .exe as a reference for the .dll and using something like the following in my .dll :
    _______________ _____________
    WinUI.MyWinForm myWinForm = new WinUI.MyWinForm ();
    myWinForm.Show( );
    _______________ _____________
    (WinUI is my application namespace/project and MyWinForm is the name a the form...)

    But as soon as the the function containing the above code (in the .dll) was called I got the following error :

    System.IO.FileN otFoundExceptio n "Could not load file or assembly 'WinUI"

    What I'm trying to accomplish is have a .net 2.0 class in a library (.dll) start up a .net 2.0 application (.exe) open up a windows form that lives in the .exe (the form can be the .exe's start up object), pass some data to the aplcation, call a couple functions and then close it (or leaving it open would be ok too)....

    And help or code samples very much appreciated.

    P.S.
    Unfortunately I can not work the other way around (of course), the application can not be started first and simply reference the class library, that would be way too easy :) This whole process must start with and be controlled by the library. Also, the form in question must live in the .exe, trust me (long story).

    Thanks in advance!

    and sorry if I'm doing something wrong here; this is my first post :)

    Comment

    • minermadison
      New Member
      • Feb 2008
      • 4

      #3
      Thank you for the suggestion.. But the .exe is in the same directory...


      Originally posted by SharpDeveloper
      Hello
      I hope your exe program should be in the same directory as the .DLL.
      You can copy the .EXE to the .DLL project directory and try once.

      Happy Programming

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You should be able to (theoretically) use Windows Messages to talk back and forth between applications.
        You could also use a socket.
        Depending on what type of program the .exe is (a console app would be best) you can redirect the standard stream objects to your dll.

        How are you calling the DLL? Usually you have a .exe call functions from withen a .DLL

        Comment

        • minermadison
          New Member
          • Feb 2008
          • 4

          #5
          Thank you for the reply... The .dll is actually loaded from a web application (asp.net), and then the .dll must do some processesing, but unfortunalty part of the .dll's job includes some rendering, and the way we have that set up right now the rendering can only be done in a windows forms application.

          maybe I should look in to Sockets and Windows Messages, those are two technologies that I'm not very familair with... I was hoping that there was a simple .net solution (remoting?).

          Thanks again.

          Originally posted by Plater
          You should be able to (theoretically) use Windows Messages to talk back and forth between applications.
          You could also use a socket.
          Depending on what type of program the .exe is (a console app would be best) you can redirect the standard stream objects to your dll.

          How are you calling the DLL? Usually you have a .exe call functions from withen a .DLL

          Comment

          Working...