コード例 #1
0
        public static int SetContextAttributes(SSPIInterface SecModule, SafeDeleteContext securityContext, ContextAttribute contextAttribute, object value)
        {
            GlobalLog.Enter("SetContextAttributes", contextAttribute.ToString());

            byte[] nativeBuffer;

            switch (contextAttribute)
            {
            case ContextAttribute.UiInfo:
                Debug.Assert(value is IntPtr, "Type Mismatch");
                IntPtr hwnd = (IntPtr)value; // A window handle
                nativeBuffer = new byte[IntPtr.Size];
                if (IntPtr.Size == 4)        // 32bit
                {
                    int ptr = hwnd.ToInt32();
                    nativeBuffer[0] = (byte)(ptr);
                    nativeBuffer[1] = (byte)(ptr >> 8);
                    nativeBuffer[2] = (byte)(ptr >> 16);
                    nativeBuffer[3] = (byte)(ptr >> 24);
                }
                else     // 64bit
                {
                    long ptr = hwnd.ToInt64();
                    nativeBuffer[0] = (byte)(ptr);
                    nativeBuffer[1] = (byte)(ptr >> 8);
                    nativeBuffer[2] = (byte)(ptr >> 16);
                    nativeBuffer[3] = (byte)(ptr >> 24);
                    nativeBuffer[4] = (byte)(ptr >> 32);
                    nativeBuffer[5] = (byte)(ptr >> 40);
                    nativeBuffer[6] = (byte)(ptr >> 48);
                    nativeBuffer[7] = (byte)(ptr >> 56);
                }
                break;

            default:
                throw new ArgumentException(SR.GetString(SR.net_invalid_enum, "ContextAttribute"), "contextAttribute");
            }

            return(SecModule.SetContextAttributes(securityContext, contextAttribute, nativeBuffer));
        }