By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

Call unmanaged .exe from c#

P: 22
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.
Feb 19 '09 #1
Share this Question
Share on Google+
9 Replies

Expert 100+
P: 692

Please refer the following link :
Feb 19 '09 #2

P: 22
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.
Feb 19 '09 #3

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

Expand|Select|Wrap|Line Numbers
  1. 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?

Feb 20 '09 #4

P: 59

I think this code will solve your purpose:

Expand|Select|Wrap|Line Numbers
  1. Process process = new Process();
  2.     process.StartInfo.UseShellExecute = false;
  3.     process.StartInfo.RedirectStandardOutput = true;
  4.     process.StartInfo.RedirectStandardError = true;
  5.     process.StartInfo.CreateNoWindow = true;
  6.     process.StartInfo.FileName = FileName;
  7.     process.StartInfo.Arguments = Arguments;//here your aruguements will go
  8.     process.StartInfo.WorkingDirectory = WorkingDirectory;
  9.     process.Start();
I took the code from here.
You may visit this page for more information.

Feb 20 '09 #5

Expert 100+
P: 229
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".
Feb 20 '09 #6

P: 22
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?
Feb 20 '09 #7

Expert 100+
P: 229

P: 22
vekipeki thanks for the help. I will check it out. Regards.
Feb 20 '09 #9

P: 1

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
May 6 '19 #10

Post your reply

Sign in to post your reply or Sign up for a free account.