![]() |
| | #1 |
| Registered User Join Date: May 2006
Posts: 35
| When creating a GUI to interface with my C/C++ code in the past I have used MFC. Now I have switched to strictly using C# for creating GUI's. The issue is that I need to create a GUI for a C++ app and I do not want to go back to MFC to create it. Could someone point me in the proper direction to understand how I can add my C# designed interface into my MSVS solution and have it call functions from my C++ project. For instance, my C# dialog handlers need to be able to access function in other C++ projects. These projects will have be included in the solution and are compiled into static libraries. So presumably I would be able to call these function simply by making them dependencies of my C# project. I have heard of issues with managed and umanaged code, and I am not sure whether they will apply to my situation or if it is a non issue and I should ignore it. any ideas ? |
| gotclout is offline | |
| | #2 |
| Anti-Poster Join Date: Feb 2002
Posts: 1,241
| The company I worked for tried to do exactly this. It doesn't work very well. Unfortunately, I can't remember exactly what issues we ran into; I can only remember in broad terms. From what I remember, there's a compiler bug preventing you from putting managed and unmanaged code in the same assembly (except in the most trivial cases). There's another issue with passing memory either from an assembly of managed code into a library of unmanaged code or vice versa. I'd love to be more specific, but it's been two years since we tried that. We spent four months just trying to get the C#-C++ interface to work. It took us about another four months to just rewrite all of our C++ code in C#, and we haven't looked back since. If you get it to work, more power to you.
__________________ Rule #1: Every rule has exceptions |
| pianorain is offline | |
| | #3 |
| the hat of redundancy hat Join Date: Aug 2001 Location: Hannover, Germany
Posts: 2,769
| AFAIK there is no way to have C++ and C# code in the same assembly. You need a well defined interface to seperate you presentation layer ( GUI ) from your logic ( algorithms, database access, etc ). You have two choices: Create normal C++ dlls. You can call them from C# rather easy if you have simple types ( primitives and fixed length structures ). OR Create a wrapper dll in Managed C++ ( now C++/CLI ). You can include both managed and unmanaged code here, so you can have your C++ classes AND your managed interface. Beware, Managed C++ is a pain in the behind, but wrapping complex classes is well worth it.
__________________ hth -nv She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate." When in doubt, read the FAQ. Then ask a smart question. |
| nvoigt is offline | |
| | #4 |
| Registered User Join Date: May 2006
Posts: 35
| c++ dll's So for my purpose if I recompile my static libs into C++ dll's how do I access them from my C# code? What headers, includes etc... will I need to pull them in and what will I need to change in my C# project settings? Once this is complete what will I have access to within the dll's? |
| gotclout is offline | |
| | #5 |
| and the Hat of Clumsiness Join Date: Oct 2002
Posts: 1,101
| Add the reference to the c++ dll in your project ( using visual studio ). Use the keyword "using namespace" to include that namespace ( the namespace defined in the c++ dll ). Once this is done, you can access everything from the dll. |
| GanglyLamb is offline | |
| | #6 |
| Registered User Join Date: May 2006
Posts: 35
| I was working in .NET 2003 but I didn't specify anywhere to use managed C++ code so I assume it's unmanaged. Ergo it would be too much overhead to make these compatible so I scraped the C# GUI and rebuilt it in MFC ![]() thanks for the replies |
| gotclout is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|