Documentation error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Can

    #1

    Documentation error

    From the MSN documentation;

    "By default, /CLRUNMANAGEDCOD ECHECK is in effect, which means
    SuppressUnmanag edCodeSecurityA ttribute is applied to linker-generated
    PInvoke calls. Specify /CLRUNMANAGEDCOD ECHECK:NO to not apply this
    attribute."

    But it seems it's just the opposite (which sounds more logical). By default
    no SuppressUnmanag edCodeSecurityA ttribute is applied to the C++ interop
    calls. And /CLRUNMANAGEDCOD ECHECK:NO must be specified to apply the
    attribute.

    There is also a "bug" in Visual Studio. If you specify
    AllowPartiallyT rustedCallers attribute, you must explicitly set the
    /CLRUNMANAGEDCOD ECHECK[:NO] switch, but there is no way to set it as
    /CLRUNMANAGEDCOD ECHECK:NO.

    Can


  • Jochen Kalmbach [MVP]

    #2
    Re: Documentation error

    Hi Can!
    "By default, /CLRUNMANAGEDCOD ECHECK is in effect, which means
    SuppressUnmanag edCodeSecurityA ttribute is applied to linker-generated
    PInvoke calls. Specify /CLRUNMANAGEDCOD ECHECK: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 SuppressUnmanag edCodeSecurityA ttribute 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(Meth odImplOptions.U nmanaged,
    MethodCodeType= MethodCodeType. Native),
    SuppressUnmanag edCodeSecurity,
    DllImport("", EntryPoint="",
    CallingConventi on=CallingConve ntion.StdCall,
    SetLastError=tr ue)]
    public static extern unsafe int modopt(CallConv Stdcall)
    GetUserNameW(ch ar*, uint modopt(IsLong)* );

    =SuppressUnmana gedCodeSecurity is applied!

    If I specify "/CLRUNMANAGEDCOD ECHECK", it will *not* apply the attribute:

    [MethodImpl(Meth odImplOptions.U nmanaged,
    MethodCodeType= MethodCodeType. Native),
    DllImport("", EntryPoint="", CallingConventi on=CallingConve ntion.StdCall,
    SetLastError=tr ue)]
    public static extern unsafe int modopt(CallConv Stdcall)
    GetUserNameW(ch ar*, uint modopt(IsLong)* );


    If I specify "/CLRUNMANAGEDCOD ECHECK:NO", it will *apply* the attribute:
    [MethodImpl(Meth odImplOptions.U nmanaged,
    MethodCodeType= MethodCodeType. Native),
    SuppressUnmanag edCodeSecurity,
    DllImport("", EntryPoint="",
    CallingConventi on=CallingConve ntion.StdCall,
    SetLastError=tr ue)]
    public static extern unsafe int modopt(CallConv Stdcall)
    GetUserNameW(ch ar*, uint modopt(IsLong)* );


    And /CLRUNMANAGEDCOD ECHECK:NO must be specified to apply the
    attribute.
    Or you do not apply this option at all.

    In short:

    No linker option: =SuppressUnmana gedCodeSecurity
    /CLRUNMANAGEDCOD ECHECK =*no* SuppressUnmanag edCodeSecurity
    /CLRUNMANAGEDCOD ECHECK:NO =SuppressUnmana gedCodeSecurity

    Tested with VS2005-SP1 and the following code:
    #include <windows.h>
    #pragma comment(lib, "Advapi32.l ib")

    namespace Foo
    {
    ref class Bar
    {
    void Test()
    {
    TCHAR szStr[100];
    DWORD dwSize = 100;
    BOOL bRet = GetUserName(szS tr, &dwSize);
    DWORD dw = GetLastError();
    }
    };
    }

    int main()
    {
    }

    Greetings
    Jochen

    Comment

    • Can

      #3
      Re: Documentation error

      Thank you for your reply.
      >I can't confirm that...
      >If I specify *nothing* in the linker options it will generate the
      >following PInvoke declaration:
      I guess I made a mistake by the "no switch" test. Sorry for that.
      >If I specify "/CLRUNMANAGEDCOD ECHECK:NO", it will *apply* the attribute:
      How do you specify "/CLRUNMANAGEDCOD ECHECK:NO" in Visual Studio? Because
      when I try to set it through the project properties dialog (by selecting
      "No" for the "CLR unmanaged code check" field) , VS just removes the switch
      from the command line instead of appending "/CLRUNMANAGEDCOD ECHECK:NO". If
      you do not use the AllowPartiallyT rustedCallers attribute, it does not
      matter, because the default is NO switch anyway. But otherwise the linker
      gives me a warning.

      Again from the MSDN doc;

      "Note that if you use AllowPartiallyT rustedCallersAt tribute in your code,
      you should explicitly set /CLRUNMANAGEDCOD ECHECK:NO. It is potential
      security vulnerability if an image contains both the
      SuppressUnmanag edCodeSecurity and AllowPartiallyT rustedCallers attributes."

      For now I manually append the switch.

      Regards;
      Can


      Comment

      • Jochen Kalmbach [MVP]

        #4
        Re: Documentation error

        Hi Can!
        How do you specify "/CLRUNMANAGEDCOD ECHECK:NO" in Visual Studio?
        I added it in
        "Linker|Com mand Line|Additonal Options"
        ;-)

        Greetings
        Jochen

        Comment

        • Can

          #5
          Re: Documentation error

          Oh I see :)

          Thank you very much...

          Regards
          Can

          "Jochen Kalmbach [MVP]" <nospam-Jochen.Kalmbach @holzma.dewrote in message
          news:OMW8zIRUHH A.1636@TK2MSFTN GP02.phx.gbl...
          Hi Can!
          >How do you specify "/CLRUNMANAGEDCOD ECHECK:NO" in Visual Studio?
          >
          I added it in
          "Linker|Com mand Line|Additonal Options"
          ;-)
          >
          Greetings
          Jochen

          Comment

          Working...