Using /clr and incompatibility troubleshooting in MFC applications

16 Apr

In some circumstances, to use C# Winform or other .Net objects in MFC applications, the “/clr” directive should be used in the MFC project settings. However, it is found not always possible to use “/clr” to avoid conflicts with other projects in the same solution.

The workaround is to apply “/clr” on a specific cpp file, rather than on the entire project!


However this will result in another conflict:


To troubleshoot this, change the setting for this specific cpp file, and change the /Yu to /Yc:


Rebuild ! Now it works!

You can enjoy the Winform and CLR features without changing the entire project with the “/clr” directive!

Leave a comment

Posted by on April 16, 2011 in Dotnet/C#, MFC



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: