Hi Can!
"By default, /CLRUNMANAGEDCODECHECK is in effect, which means
SuppressUnmanagedCodeSecurityAttribute is applied to linker-generated
PInvoke calls. Specify /CLRUNMANAGEDCODECHECK:NO to not apply this
attribute."
Yes, this seems to be a docu bug...
But it seems it's just the opposite (which sounds more logical). By default
no SuppressUnmanagedCodeSecurityAttribute is applied to the C++ interop
calls.
I can't confirm that...
If I specify *nothing* in the linker options it will generate the
following PInvoke declaration:
[MethodImpl(MethodImplOptions.Unmanaged,
MethodCodeType=MethodCodeType.Native),
SuppressUnmanagedCodeSecurity,
DllImport("", EntryPoint="",
CallingConvention=CallingConvention.StdCall,
SetLastError=true)]
public static extern unsafe int modopt(CallConvStdcall)
GetUserNameW(char*, uint modopt(IsLong)*);
=SuppressUnmanagedCodeSecurity is applied!
If I specify "/CLRUNMANAGEDCODECHECK", it will *not* apply the attribute:
[MethodImpl(MethodImplOptions.Unmanaged,
MethodCodeType=MethodCodeType.Native),
DllImport("", EntryPoint="", CallingConvention=CallingConvention.StdCall,
SetLastError=true)]
public static extern unsafe int modopt(CallConvStdcall)
GetUserNameW(char*, uint modopt(IsLong)*);
If I specify "/CLRUNMANAGEDCODECHECK:NO", it will *apply* the attribute:
[MethodImpl(MethodImplOptions.Unmanaged,
MethodCodeType=MethodCodeType.Native),
SuppressUnmanagedCodeSecurity,
DllImport("", EntryPoint="",
CallingConvention=CallingConvention.StdCall,
SetLastError=true)]
public static extern unsafe int modopt(CallConvStdcall)
GetUserNameW(char*, uint modopt(IsLong)*);
And /CLRUNMANAGEDCODECHECK:NO must be specified to apply the
attribute.
Or you do not apply this option at all.
In short:
No linker option: =SuppressUnmanagedCodeSecurity
/CLRUNMANAGEDCODECHECK =*no* SuppressUnmanagedCodeSecurity
/CLRUNMANAGEDCODECHECK:NO =SuppressUnmanagedCodeSecurity
Tested with VS2005-SP1 and the following code:
#include <windows.h>
#pragma comment(lib, "Advapi32.lib")
namespace Foo
{
ref class Bar
{
void Test()
{
TCHAR szStr[100];
DWORD dwSize = 100;
BOOL bRet = GetUserName(szStr, &dwSize);
DWORD dw = GetLastError();
}
};
}
int main()
{
}
Greetings
Jochen