# Wednesday, 17 January 2007

Try this. Open up Visual Studio and make yourself an MFC app. It doesn't really matter what kind of application it is - a dialog app is probably the quickest to create but you could use some more complex MFC app that you happened to have lying around if you preferred. Build the app and run it to prove to yourself that it's fine.

Now bring up the project properties, and under Configuration Properties, General set Common Language Runtime Support to Pure MSIL Common Language Runtime Support.

Click OK and build the application. Blam! Errors everywhere. My little nothing dialog application got 18 and they all look like this:

1>C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxv_w32.h(242) : error C3641: 'DrawState' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe

1>C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxv_w32.h(260) : error C3641: 'DrawStatusText' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe

1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winbase.h(1849) : error C3641: 'FreeResource' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe

What does this mean? Well, every function has a calling convention. These include __stdcall, __clrcall, __cdecl, and so on. Many of the functions in the MFC libraries (look at the include files for which these errors occur) are declared to be __stdcall, meaning that they are common-or-garden native C++ functions. But when you compile your application /clr:pure, you are saying "I don't have any common-or-garden native C++ functions in here. Everything is managed."

Since you can't change MFC, you have to change your compiler options. Change the CLR support to just "Common Language Runtime Support (/clr)" and build again. All the errors go away.

Kate

Wednesday, 17 January 2007 12:05:53 (Eastern Standard Time, UTC-05:00)  #