Host Windows Forms (C#) Inside MFC Application (VC++,VS6.0) - c#

After a bunch of reading this afternoon, and not getting any tangible results. Is it possible to host a windows forms dialog inside of a MFC application that is still being developed using VC6.
The issue arises is that we have a large application that has never been upgraded with the new Visual Studios because VC6 always worked. Now we need to add some of the C# functionality in it. I am unable to do the /clr option as our project consists entirely of unmanaged C++. I did a search for "CWinFormsControl" within all our libraries/headers and didn't come up with anything. I am unsure what to try next.
Also, forgive any ignorance as I am doing research and new to this depth of programming.
I have checked the following articles:
http://msdn.microsoft.com/en-us/library/676cbawx(v=vs.100).aspx
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/97fddc35-e94d-4587-8be0-0b573185eb63/
http://msdn.microsoft.com/en-us/library/ahdd1h97(v=vs.80).aspx
http://www.functionx.com/visualc/Lesson04.htm
http://social.msdn.microsoft.com/Forums/sk/vcgeneral/thread/c38db22e-cf61-4b47-bcc8-e6202c40d1b5

CWinFormsControl requires MFC 8.0.
You can make your managed assembly a COM server (e.g. ActiveX) and use it in MFC application like any other COM server.

I don't have VC6 laying around to try this out, but I think it should be mostly possible; at least for a simple modal ShowDialog() scenario.
You'll create a new assembly/DLL using C++/CLI, compiled with the /clr flag. This will expose an unmanaged API to your existing MFC code, using the usual __declspec(dllexport). The implementation will call into your C# code which lives it yet another assembly.

Related

WPF with C++, is it possible?

I have my main program in C++, but now I need to build a beautiful application and I know that WPF is easy and makes for beautiful apps. Can WPF work with C++ or C# and C++? (If yes, how?) Is WPF the best thing for me?
You can use WPF in a managed C++ project, but you're better off keeping your C++ in a separate assembly and referencing it from a C# or VB WPF project.
Yes, you can develop a GUI using WPF framework in Managed C+ or C++/CLI. But they're not Standard C++, hence not cross-platform.
If you just want a GUI for your application written in C++, then you may try Qt as well. The advantage in Qt is that its completely in C++. Not Microsoft Managed C++. The second advantage is that its cross-platform toolkit. That means, you can run your app in Windows, Linux, Mac, and on other machines as well.
Have a look at its documentation
Qt Reference Documentation
It has lots of tools for fast development such as Qt Creator, Qt Designer and others. You can see all of them by browsing the above link.
WPF is dead along with Silverlight, remember, MS says its HTML5 only from now on :)
Using WPF in your C++ app can be achieved using hwndSource, but its not the optimal solution, for that you will have to create C# or VB.NET GUI app, and use it to communicate with your C++ app via some form of IPC.
There are alternatives, probably the best one is to write your GUI using Qt, which is very well respected. You can get similar features to WPF by writing using QML alongside the old forms-based system (which means you get all the development speed of using the old, boring text boxes and the like, and the fancy GUI benefits of using the new declarative UI system, all in the same system. sweet).
Of course, a decent option is to make your app into a back-end server process and call it from a web-server based HTML5 UI. That's pretty future proof, easy to deploy to clients, and as modern as you're likely to get.

automating .NET applications

I'm trying to automate a hidden .NET application, with another .NET application (written in c#) using the easiest way possible. It's NOT for testing purposes, it's a way to fulfill the lack of scripting for this application.
I already tried white framework, but there is one major problems with it: the way it's working. It's slow and it's not working on hidden windows and controls (like the winAPI does). Whats more, when "clicking" white moves the mouse, brings it's targeted window to the front and so on.
I was also thinking about using a user32.dll wrapper, because the way it's handling it's target is what I need, but I've red it's not working with .NET applications. It also would be a problem working with it, because my targeted application got 5 button labeled "...", and would be really hard finding 2 of them I need. I also would like to use the controls .NET id (the name the developer gave to it's controls when designing the GUI).
BTW, my targeted application is MeGUI if that helps. We do a lot of video encoding and a tool like this would help us a lot. I need the MeGUI to be hidden, because I'm the only programmer, others using my tool shouldn't see what happens in the background, not to talk about the many windows popping all around.
You can add a reference to the exe from your project and then create an AppDomain to run its main method. From there, it should be possible to queue delegates to its main thread's loop. With a bit of reflection, you could have those delegates invoke the click events and whatnot directly.
I've never attempted this approach, but it should work.
You should try Stephens idea instead of scripting a hidden app. A .NET Windows Forms App (EXE) is still a .NET Assembly and that means you can use that the same way as a DLL, just add a reference and use the public classes.
If you still want to try some scripting, take a look on the "Microsoft UI Automation" API and the "System.Windows.Automation" namespace.
Nice article here: http://msdn.microsoft.com/en-us/magazine/cc163465.aspx
MSDN Doc: http://msdn.microsoft.com/en-us/library/system.windows.automation.aspx

Creating a Web Wrapper for COM and OCX

Today we have a windows application that, using an OCX, creates a web page (visible by a WebBrowser control in a small .NET WinForm application) and communicates through COM to the main application/client. (not relevant but this is Pascal)
I'm currently responsible to re create this application in a web environment so we can have the same functionality shared through Web as the user can see the same in a Web Browser.
The Windows application has almost 4 years on it and I need to re create everything from scratch, and all the bugs/features find in the future in the Windows Application I have to re create them again in the Web...
Ohh well, you can see where this will end.
I was thinking... is there any way I can create a Wrapper, even using 3rd party commercial objects, to:
Communicate with the COM Object
Can expose the content of the OCX
(this in my most confortable language, ASP.NET C#, but other are welcome)
I was thinking out loud, can this be accomplish with a Java Applet? Silverlight 4?
Any ideas or any point to the right road will be appreciated.
You may want to consider using Silverlight 4. Although it's not fully baked (Microsoft announced it as Release Candidate status yesterday or today) it has COM support but will run in a web enabled way.
The fact that your previous application is Windows/OCX tells me that the chief weakness of this approach, which would be platform neutrality, is less of an issue.

Integrating Qt GUI code into C#

I have to develop a plug-in for an external program using C#.
I am an experienced Qt/C++ programmer and the core of the plug-in is programmed in C++.
My first idea was to program GUI in C#, which write settings to a text file and then call the core C++ code, as an external process, with this textfile as an input.
However I also noticed that there is something called the QAxServer Module in Qt that should make it possible to run Qt/C++ GUI code from C# (trough ActiveX).
I experimented a bit with this and it seemed a bit "shaky".
Do you have any experiences with this you could share?
I would look at writing a C++/CLI (i.e. Managed C++) shim to launch your plug-in and be the bridge between it and the main application.
This will allow you to call into (or be called from) the C# application on one side and talk native C++ on the other.
http://techbase.kde.org/Development/Languages/Qyoto
Qyoto seems to be the most active Qt binding for .NET.
There is also the "QT for .NET" project.

What is the best way to use a Custom .net control from a legacy C++ app?

I maintain a legacy application (unmanaged C++) and I need a new control (Basic Form). I would like to build this control in C# for simplicity but use it from my legacy app. Any suggestions?
Well, you might want to make a COM control in C#, register it and use it from within your C++ application. I can't see any other way of using a .NET control in C++ - however, I haven't tried that.
Theoretically you could build the c++ into a dll and use it, but there is really not enough information here.

Categories