Re: C3395: __declspec(dllexport) and __clrcall incompatible
- From: "Marcus Heege" <NOSPAM@xxxxxxxxx>
- Date: Thu, 20 Oct 2005 00:01:20 +0200
Hi Jochen,
"Jochen Kalmbach [MVP]" <nospam-Jochen.Kalmbach@xxxxxxxxx> wrote in message
news:uHSH7cv0FHA.1032@xxxxxxxxxxxxxxxxxxxxxxx
> Hi bonk!
>> Hello, I created a MFC extension dll (using VS 2005 Beta 2) that is
>> supposed to export a class that uses .NET internally (See header below)
>> und later shall be used by a plain MFC Project (without the /CLR).
>>
>> As soon as I try to specify __declspec(dllexport) (AFX_EXT_CLASS) I get
>> the following compiler error:
>>
>> Error 2 error C3395: 'CWPFControlProxy::OnWPFButtonClick' :
>> __declspec(dllexport) cannot be applied to a function with the __clrcall
>> calling convention g:\robert_d\visual studio
>> 2005\projects\wpfcontrols\wpfcontrols\WPFControlProxy.h 28
>>
>> Could you explain what this error means and what I can do against it? I
>> don't see a __clrcall definition anywhere in my project ...
>
> If you compile with /clr, then all methods/functions are compiled into
> MSIL, therefor they will always use __clrcall as calling convention.
>
> If you want to have __stdcall or __cdecl then you need to compile into
> native code.
>
> So please add the
>
> #pragma unmanaged
>
> to the region of code, you want to export.
Sorry to correct you here, but your statement is wrong. Managed functions
can indeed have native calling conventions. In these cases special metadata
is generated that the CLR can use to generate unmanaged -> managed thunks.
The calling convention __clrcall exists only to avoid the generation of this
metadata and the managed -> unmanaged thunks in cases where they are not
necessary.
See [1] for the details.
Marcus Heege
[1]
http://www.heege.net/blog/PermaLink,guid,48daf2ff-41c8-4312-9d80-bdfa8c55058d.aspx
.
- Follow-Ups:
- Re: C3395: __declspec(dllexport) and __clrcall incompatible
- From: Jochen Kalmbach [MVP]
- Re: C3395: __declspec(dllexport) and __clrcall incompatible
- References:
- C3395: __declspec(dllexport) and __clrcall incompatible
- From: bonk
- Re: C3395: __declspec(dllexport) and __clrcall incompatible
- From: Jochen Kalmbach [MVP]
- C3395: __declspec(dllexport) and __clrcall incompatible
- Prev by Date: Re: writing to text file
- Next by Date: Re: C3395: __declspec(dllexport) and __clrcall incompatible
- Previous by thread: Re: C3395: __declspec(dllexport) and __clrcall incompatible
- Next by thread: Re: C3395: __declspec(dllexport) and __clrcall incompatible
- Index(es):
Relevant Pages
|