| 
 | 
 | 
 
Home » Community » Newbie corner » U++ and Managed c++ /clr 
	
		
		
			| U++ and Managed c++ /clr [message #34241] | 
			Sat, 05 November 2011 19:50   | 
		 
		
			
				
				
				
					
						  
						conrad
						 Messages: 12 Registered: November 2011  Location: Norway
						
					 | 
					Promising Member  | 
					 | 
		 
		 
	 | 
 
	
		I'd like to give U++ a serious try but I need to integrate with a few .net libraries (On Windows). I am wondering if anyone has tried to combine /clr (managed c++) code with the U++ framework and TheIde? 
Regards, 
Conrad 
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
	| 
		
 |  
	
		
		
			| Re: U++ and Managed c++ /clr [message #34244 is a reply to message #34243] | 
			Sun, 06 November 2011 07:15    | 
		 
		
			
				
				
				
					
						  
						Sender Ghost
						 Messages: 301 Registered: November 2008 
						
					 | 
					Senior Member  | 
					 | 
		 
		 
	 | 
 
	
		Let's create simple "Core console project" application: 
#include <Core/Core.h>
using namespace Upp;
#using <mscorlib.dll>
using namespace System;
CONSOLE_APP_MAIN
{
	Cout() << "Hello, from U++!\n";
	Console::WriteLine("Hello, from managed C++!");
}
 
Open "Project -> Package organizer.." for main package and insert following compiler option: 
-clr
  
Open "Project -> Main package configuration.." menu and add following build flags: 
EVC .USEMALLOC
  
EVC - is build flag (used for another C++ compiler), which adds compiler options to turn off exception handling, because -clr is not compatible with -EHsc compiler option. 
USEMALLOC - disables U++ memory allocator to not conflict with .NET Framework memory allocation methods. 
 
Also check "Build -> Output mode.." menu for the "Use shared libs" link mode. 
 
Now, you can build combined U++ and Managed C++ package. 
 
To note: 
It also possible to extend C++ syntax higlighting for managed C++ extensions and add CLR specific compiler options, instead of EVC. 
Here, I just showed possible way to use TheIDE with Managed C++ extensions. I don't think, this is recommended way.
		
		
		[Updated on: Sun, 20 November 2011 21:08] Report message to a moderator  
 |  
	| 
		
	 | 
 
 
 |  
	| 
		
 |  
	| 
		
 |  
	
		
		
			| Re: U++ and Managed c++ /clr [message #34247 is a reply to message #34241] | 
			Sun, 06 November 2011 17:12    | 
		 
		
			
				
				
				
					
						  
						conrad
						 Messages: 12 Registered: November 2011  Location: Norway
						
					 | 
					Promising Member  | 
					 | 
		 
		 
	 | 
 
	
		Many thanks for all the answers here. 
I must say, I have rarely if ever experienced such support. 
I will give this a try this week. 
I have a fair amount of experience with mixed mode solutions running in VS 2009 and 2010. 
The system I need to make work is one I call for the "firewall" solution. Let me explain. 
I do not want the entire app to bee "seen" by the /clr compiler but only a wrapper "project" (a Package ?). The reason for this is that once the application grows, mixed mode compilation & linking becomes completely unmanageable. Footprint is 2.5 times fold and link times can be literally hours. 
For this to work, a few .h header files will have to be compatible for both c++ and /clr compilation. With VS 2010 doing the compilation, std::string and std::wstring is for example a workable candidate. In a VS solution, these wrapper classes live in a unique project and only this project has /clr turned on. /clr only, not /pure, not /safe - as these create far too many issues. But /clr works, and I know for a fact that given a few wrapper classes where essentially plain old data and strings are converted from the .net world to the c++ world, mixed mode can have much to offer. 
 
I will let you know how I am doing as soon as I know a bit more. 
Again, thanks for the support here without which I may not have had the courage to give it a try   
 
Conrad 
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
	
		
		
			| Re: U++ and Managed c++ /clr [message #34249 is a reply to message #34247] | 
			Sun, 06 November 2011 20:26    | 
		 
		
			
				
				
				
					
						  
						conrad
						 Messages: 12 Registered: November 2011  Location: Norway
						
					 | 
					Promising Member  | 
					 | 
		 
		 
	 | 
 
	
		| conrad wrote on Sun, 06 November 2011 17:12 |  
  
I will let you know how I am doing as soon as I know a bit more. 
Conrad 
  |  
  
 
I understand the concept of Packages a bit better now. 
I made a "DotNetWrapper" package with -clr. 
It looks like I need a way to pass on more compiler options to VS. 
In particular the /MDd option must override the /MTd option. 
(Adding -EHa seems to work, but adding -MDd doesn't) 
 
I am using the HelloWorld example. 
I don't think I need to change the default setting of the application. Only the wrapper package must be build with correct options. 
 
I have read Miroslav's http://www.ultimatepp.org/redmine/issues/156 and looked at the diffs but that is going a bit too fast for me   Besides, looks like I would have to recompile theIde first after pull in those changes.  
 
Regards, 
Conrad
		
		
		[Updated on: Sun, 06 November 2011 20:39] Report message to a moderator  
 |  
	| 
		
	 | 
 
 
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |   
Goto Forum:
 
 Current Time: Tue Nov 04 06:47:25 CET 2025 
 Total time taken to generate the page: 0.05715 seconds 
 |   
 |  
  |