views:

469

answers:

2

I have an existing project created using C/C++ under a development environment. Currently we want to facelift the existing form using a Window Forms application but the problem is the existing project is using Common Runtime Library = No /CLR and Runtime Library = /MTd.

But the a Windows Forms application is using Common Runtime Library = /CLR and Runtime Library = /MDd. Please advise if it possible to use a Windows Forms application to create a form in the existing project?
Is there any tutorial regarding this?

The comment from MSDN was:-

Caution Do not mix static and dynamic versions of the run-time libraries. Having more than one copy of the run-time libraries in a process can cause problems, because static data in one copy is not shared with the other copy. The linker prevents you from linking with both static and dynamic versions within one .exe file, but you can still end up with two (or more) copies of the run-time libraries. For example, a dynamic-link library linked with the static (non-DLL) versions of the run-time libraries can cause problems when used with an .exe file that was linked with the dynamic (DLL) version of the run-time libraries. (You should also avoid mixing the debug and non-debug versions of the libraries in one process.)
http://msdn.microsoft.com/en-us/library/2kzt1wy3%28VS.71%29.aspx..

+1  A: 

The simple answer is no. A more accurate answer is kind of, but you probably wouldn't want to.

It is possible to use Windows Forms (i.e. managed code) for your user interface and something else (e.g. non .NET/unmanaged code) for your domain logic. However I'd guess that if you're asking this question then that is going to be a bit much for you to do at the moment.

I suggest that you create a user interface with Windows Forms and then have that user interface call a native C/C++ DLL. Google for PInvoke on how to call an unmanaged dll (C/C++) from managed (.NET) code.

If you did that then you would be much better positioned to answer this question.

dan gibson
The problem now is i could not mix static and dynamic versions of the run-time libraries. Is there any suggestion how could i mix the run-time libraries?
Jenuel
Why do you want to mix them? I don't think you do. I think you may be getting confused between the c/c++ run-time libraries and the .Net run-time. They are completely separate things. The "Common Runtime Library" is .Net which is a different thing to the other runtime library specified with /MDd or /MTd.
dan gibson
A: 

My company software often has to have modules which mix managed and unmanaged code and user interfaces. What we do is to separate the modules into their own executables and expose the functionality as COM localserver objects. This way, the unmanaged code can have a user interface written in managed code.

However, you need to do alot of plumbing to get it to work. We do it this way because our applications have been deployed in the field for years and it will take years to give the entire program a makeover into .NET

Andrew Keith
It look interesting. Where could I find tutorial regarding using COM? Is COM can link static and dynamic versions of the run-time libraries?
Jenuel
There are alot of tutorials on COM which you can get from google. Its a fairly large topic, so you might want to look for COM LocalServer tutorials. It will most probably be covered as DCOM. If you use LocalServer, each module can be its own EXE, so you can mix and match as much as you like. COM is mostly deprecated in favour of WCF. I use COM because i have alot of legacy C++ code which cannot be converted to .NET without incuring a large cost.
Andrew Keith