Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

We have an old C++ app creating an exe where our lab window can call this exe functions. This C++ app is so old, and we would like to rewrite again in C#. How can I create external functions in C# to substitute C++ functions so our main lab window application can call?

Thanks,

Trammy
Posted
Comments
[no name] 25-Apr-12 19:57pm    
It's not very clear what it is that you want to do. You have a C++ exe that you want to call functions in from C#?
If you have a C++ DLL you can p/invoke the functions in C#.
Member 3027075 25-Apr-12 20:16pm    
Wes,

We have an 15 years old C++ exe that our lab window application is calling. I would like to rewrite this C++ exe using C# that exposes the same function the C++ exe exposes.

I am familiar with DLL or OCX in C# but I don't think it can expose the same functions as C++ exe exposes.

-Trammy
[no name] 25-Apr-12 20:27pm    
Sure you can write a C# exe that performs the same functionality that your C++ app does. I am not sure what you mean by "external functions". C++ exe do not export functions to the outside world (to the best of my knowledge). That is what DLLs are for.

Edit... having a lightbulb moment. Do you mean that your C++ exe acts as a server or service and your lab application sends commands to it via TCP or named pipes or other type of interprocess communication? C# fully supports that type of communication.
Shahin Khorshidnia 25-Apr-12 21:00pm    
I think if you add up your 2 comments, you can post it as a solution.
Sorry that I can't vote here.
+5
[no name] 25-Apr-12 21:02pm    
Thanks.... I would but I am still not sure what it is that he wants to do.

It's not very clear what it is that you want to do. You have a C++ exe that you want to call functions in from C#? If you have a C++ DLL you can p/invoke the functions in C#.

Sure you can write a C# exe that performs the same functionality that your C++ app does. I am not sure what you mean by "external functions". C++ exe do not export functions to the outside world (to the best of my knowledge). That is what DLLs are for.

Edit... having a lightbulb moment. Do you mean that your C++ exe acts as a server or service and your lab application sends commands to it via TCP or named pipes or other type of interprocess communication? C# fully supports that type of communication.

After thinking about this I am fairly certain that what you are wanting to do is create a C# application that unitizes inter-process communication (IPC) to communicate with your lab application. This is fairly simple to do using the .NET TCP classes. I have no personal experience using the named pipes with .NET but I would imagine that they are probably pretty easy too. Certainly easier than the C++ counterparts.

This[^] would be a good place to start.
 
Share this answer
 
I think you might need to consider the example of C# Com interop [^]

Hope it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900