Call unmanaged .exe from c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackirish
    New Member
    • Sep 2008
    • 22

    Call unmanaged .exe from c#

    Hi all,
    I want to load an unmanaged c++ exe file and then invoke methods inside it by using c#. I can load and invoke methods in .net exe files by using reflection but couldn't do that on unmanaged exe files.

    Is there a way to do that by using c#?

    Thanks in advance.
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Please refer the following link :

    Comment

    • blackirish
      New Member
      • Sep 2008
      • 22

      #3
      shweta123 thanks for the reply. Actually i just want to load .exe files by using c# not dll files. Because i don't want to write a wrapper class to handle unmanged dll files. What i need is accessing the methods in simple unmanaged c++ applications. I think just sending inputs to exe files and getting the outputs automatically would be enough to do what i want. Thanks for your helps.

      Comment

      • babai28
        New Member
        • Jul 2008
        • 59

        #4
        Check for the intricacies of the Diagnostic class.
        May be this is what you want:

        Code:
        System.Diagnostics.Process.Start("myexe.exe");
        Since you also want to pass arguements to the exe you will need to use a property of the Process class (Jus check in the Visual Studio, iI forgot the name) before you can acually call the method called "Start()". Does this solve your problem?

        Regards,
        Siddhartha

        Comment

        • babai28
          New Member
          • Jul 2008
          • 59

          #5
          Hey,

          I think this code will solve your purpose:

          Code:
          Process process = new Process();
              process.StartInfo.UseShellExecute = false;
              process.StartInfo.RedirectStandardOutput = true;
              process.StartInfo.RedirectStandardError = true;
              process.StartInfo.CreateNoWindow = true;
              process.StartInfo.FileName = FileName;
              process.StartInfo.Arguments = Arguments;//here your aruguements will go
              process.StartInfo.WorkingDirectory = WorkingDirectory;
              process.Start();
          I took the code from here.
          You may visit this page for more information.


          Regards,
          Siddhartha

          Comment

          • vekipeki
            Recognized Expert New Member
            • Nov 2007
            • 229

            #6
            P/Invoking should still be the preferred way to do it. Why do you want to avoid it?

            There is a tool from Microsoft which generates P/Invoke signatures for you (if you have a native header file, which I presume you do ), google for "P/Invoke Interop Assistant".

            Comment

            • blackirish
              New Member
              • Sep 2008
              • 22

              #7
              Thank u all for your helps. Actually first i thought using P/Invoke to invoke methods of the unmanaged program. But it will not have a dll file what i have is just an exe file and i need to write a wrapper class to handle an unmanaged dll file to be able to use it in c# program. I want to write a program that automatically invokes the called methods in the main method of the exe file. Is it possible to manage that?

              Comment

              • vekipeki
                Recognized Expert New Member
                • Nov 2007
                • 229

                #8
                Check this: http://www.pinvoke.net/default.aspx/...ocAddress.html

                Comment

                • blackirish
                  New Member
                  • Sep 2008
                  • 22

                  #9
                  vekipeki thanks for the help. I will check it out. Regards.

                  Comment

                  • nanaaka
                    New Member
                    • May 2019
                    • 1

                    #10
                    Originally posted by blackirish
                    vekipeki thanks for the help. I will check it out. Regards.
                    Hello,

                    I try to do the same thing, using an exe in C# inside another C# code, but i don't know how i can use method or class from the first exe, any help please

                    Comment

                    Working...