# 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)  #    Comments [6]
Friday, 02 February 2007 12:08:13 (Eastern Standard Time, UTC-05:00)
Doesn't make much sense to have a /clr:pure compiled mixed-mode assembly anyway :-)
Sunday, 13 May 2007 00:31:57 (Eastern Daylight Time, UTC-04:00)
If MFC will not call these functions, you may be able to make these function __clrcall instead and get rid of the errors, but if MFC will call these functions, you have no choice but to compile with /clr instead.
Yuhong Bao
Sunday, 13 May 2007 00:34:57 (Eastern Daylight Time, UTC-04:00)
Also these error should only occur if these functions came from your application. If these function came from MFC, these errors should not occur.
Yuhong Bao
Monday, 28 May 2007 16:53:15 (Eastern Daylight Time, UTC-04:00)
Thanks man,

Saved me a lot of time.

Regards.
Yahel
Tuesday, 24 November 2009 15:23:10 (Eastern Standard Time, UTC-05:00)
Many, many, many thanks!
Jim
Saturday, 23 January 2010 11:06:04 (Eastern Standard Time, UTC-05:00)
Ahhhhhhh. Thanks
Bonko
Comments are closed.