当前位置: 首页>>代码示例>>C#>>正文


C# IntPtr.Select方法代码示例

本文整理汇总了C#中System.IntPtr.Select方法的典型用法代码示例。如果您正苦于以下问题:C# IntPtr.Select方法的具体用法?C# IntPtr.Select怎么用?C# IntPtr.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IntPtr的用法示例。


在下文中一共展示了IntPtr.Select方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetJobObjectProcessIds

        static int[] GetJobObjectProcessIds(SafeJobObjectHandle handle)
        {
            const int JobCountIncrement = 5;

            int numberOfAssignedProcessesOffset = Marshal.OffsetOf(typeof(NativeMethods.JobObjectBasicProcessIdList), "NumberOfAssignedProcesses").ToInt32();
            int numberOfProcessIdsInListOffset = Marshal.OffsetOf(typeof(NativeMethods.JobObjectBasicProcessIdList), "NumberOfProcessIdsInList").ToInt32();
            int firstProcessIdOffset = Marshal.OffsetOf(typeof(NativeMethods.JobObjectBasicProcessIdList), "FirstProcessId").ToInt32();

            int numberOfProcessesInJob = JobCountIncrement;
            do
            {
                int infoSize = firstProcessIdOffset + (IntPtr.Size * numberOfProcessesInJob);
                IntPtr infoPtr = IntPtr.Zero;
                try
                {
                    infoPtr = Marshal.AllocHGlobal(infoSize);
                    NativeMethods.FillMemory(infoPtr, (IntPtr)infoSize, 0);

                    Marshal.WriteInt32(infoPtr, numberOfAssignedProcessesOffset, numberOfProcessesInJob);
                    Marshal.WriteInt32(infoPtr, numberOfProcessIdsInListOffset, 0);

                    if (!NativeMethods.QueryInformationJobObject(
                        handle,
                        NativeMethods.JobObjectInfoClass.JobObjectBasicProcessIdList,
                        infoPtr,
                        infoSize,
                        IntPtr.Zero))
                    {
                        var error = Marshal.GetLastWin32Error();
                        if (error == NativeMethods.Constants.ERROR_MORE_DATA)
                        {
                            numberOfProcessesInJob += JobCountIncrement;
                            continue;
                        }

                        throw new Win32Exception(error);
                    }

                    int count = Marshal.ReadInt32(infoPtr, numberOfProcessIdsInListOffset);
                    if (count == 0)
                        return new int[0];

                    IntPtr[] ids = new IntPtr[count];

                    Marshal.Copy(infoPtr + firstProcessIdOffset, ids, 0, count);

                    return ids.Select(id => id.ToInt32()).ToArray();
                }
                finally
                {
                    if (infoPtr != IntPtr.Zero)
                        Marshal.FreeHGlobal(infoPtr);
                }

            } while (true);
        }
开发者ID:stefanschneider,项目名称:IronFrame,代码行数:56,代码来源:JobObject.cs

示例2: Load


//.........这里部分代码省略.........
            var data = new byte[bitmap.Width * bitmap.Height * 4 * 2];
            var mipPointers = new IntPtr[GetMipCount(bitmap.Width, bitmap.Height)];

            fixed (byte* pData = data)
            {
                mipPointers[0] = (IntPtr)pData;

                var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                {
                    var dst = pData;
                    var src = (byte*)bitmapData.Scan0;

                    if (bgra)
                    {
                        for (int y = 0; y < bitmap.Height; y++)
                        {
                            for (int x = 0; x < bitmap.Width; x++)
                            {
                                dst[0] = src[0];
                                dst[1] = src[1];
                                dst[2] = src[2];
                                dst[3] = 255;

                                src += 3;
                                dst += 4;
                            }
                        }
                    }
                    else
                    {
                        for (int y = 0; y < bitmap.Height; y++)
                        {
                            for (int x = 0; x < bitmap.Width; x++)
                            {
                                dst[0] = src[2];
                                dst[1] = src[1];
                                dst[2] = src[0];
                                dst[3] = 255;

                                src += 3;
                                dst += 4;
                            }
                        }
                    }

                    int mipWidth = bitmap.Width;
                    int mipHeight = bitmap.Height;

                    for (int level = 1; level < mipPointers.Length; level++)
                    {
                        mipPointers[level] = (IntPtr)dst;
                        src = (byte*)mipPointers[level - 1];

                        int srcRowSpan = mipWidth * 4;

                        mipWidth = Math.Max(mipWidth / 2, 1);
                        mipHeight = Math.Max(mipHeight / 2, 1);

                        for (int y = 0; y < mipHeight; y++)
                        {
                            for (int x = 0; x < mipWidth; x++)
                            {
                                for (int i = 0; i < 3; i++)
                                {
                                    float tl = SrgbToLinear(src[i] / 255f);
                                    float tr = SrgbToLinear(src[i + 4] / 255f);
                                    float bl = SrgbToLinear(src[i + srcRowSpan] / 255f);
                                    float br = SrgbToLinear(src[i + 4 + srcRowSpan] / 255f);

                                    dst[i] = (byte)(LinearToSrgb((tl + tr + bl + br) / 4f) * 255.9999f);
                                }

                                dst[3] = 255;

                                src += 8;
                                dst += 4;
                            }

                            src += srcRowSpan;
                        }
                    }
                }
                bitmap.UnlockBits(bitmapData);

                var desc = new Texture2DDescription
                {
                    Width = bitmap.Width,
                    Height = bitmap.Height,
                    ArraySize = 1,
                    MipLevels = mipPointers.Length,
                    FormatID = formatId,
                    Sampling = Sampling.NoMultisampling,
                    BindFlags = BindFlags.ShaderResource,
                    Usage = Usage.Immutable
                };

                result = device.Create.Texture2D(desc, mipPointers.Select(x => new SubresourceData(x, 1)).ToArray());
            }
            return result;
        }
开发者ID:Zulkir,项目名称:Beholder,代码行数:101,代码来源:TextureLoader.cs

示例3: APidlToIdListArray

 public static IdList[] APidlToIdListArray(IntPtr apidl, int count)
 {
     var pidls = new IntPtr[count];
     Marshal.Copy(apidl, pidls, 0, count);
     return pidls.Select(PidlToIdlist).ToArray();
 }
开发者ID:JamesLinus,项目名称:sharpshell,代码行数:6,代码来源:PidlManager.cs

示例4: QueryFormats

 /// <summary> Query if 'wand' is magick wand. </summary>
 /// <param name="wand"> The wand. </param>
 /// <returns> true if magick wand, false if not. </returns>
 /*private static bool IsMagickWand(IntPtr wand)
 {
     return WandInterop.IsMagickWand(wand);
 }*/
 /// <summary> Command genesis. </summary>
 /// <param name="image_info"> Information describing the image. </param>
 /// <param name="command"> The command. </param>
 /// <param name="argc"> The argc. </param>
 /// <param name="argv"> The argv. </param>
 /// <param name="metadata"> The metadata. </param>
 /// <param name="exception"> The exception. </param>
 /// <returns> true if it succeeds, false if it fails. </returns>
 /*private static bool CommandGenesis(IntPtr image_info, MagickCommandType command, int argc, string[] argv, byte[] metadata, IntPtr exception)
 {
    return WandInterop.MagickCommandGenesis(image_info, command, argc, argv, metadata, ref exception);
     //return WandInterop.MagickCommandGenesis(image_info, command, argc, argv);
 }*/
 /// <summary> Queries the formats. </summary>
 /// <param name="pattern"> Specifies the pattern. </param>
 /// <returns> An array of string. </returns>
 internal static List<string> QueryFormats(string pattern)
 {
     EnsureInitialized();
     IntPtr number_formats = IntPtr.Zero;
     IntPtr format = WandInterop.MagickQueryFormats("*", ref number_formats);
     IntPtr[] rowArray = new IntPtr[(int)number_formats];
     Marshal.Copy(format, rowArray, 0, (int)number_formats);
     List<string> val = rowArray.Select(x => WandNativeString.Load(x)).ToList();
     if (pattern == "*")
         return val;
     return val.FindAll(x => x.Equals(pattern, StringComparison.InvariantCultureIgnoreCase));
 }
开发者ID:NazioByte,项目名称:ImageMagickSharp,代码行数:35,代码来源:Wand.cs

示例5: CredEnumerate

        internal static IEnumerable<CREDENTIAL> CredEnumerate()
        {
            int count;
            IntPtr pCredentials;
            var ret = CredEnumerate(null, 0, out count, out pCredentials);

            if (ret == false)
                throw new Exception("Failed to enumerate credentials");

            var credentials = new IntPtr[count];
            for (var n = 0; n < count; n++)
                credentials[n] = Marshal.ReadIntPtr(pCredentials,
                    n * Marshal.SizeOf(typeof(IntPtr)));

            return credentials.Select(ptr => (CREDENTIAL)Marshal.PtrToStructure(ptr, typeof(CREDENTIAL)));
        }
开发者ID:spolnik,项目名称:Simple.CredentialsManager,代码行数:16,代码来源:NativeMethods.cs


注:本文中的System.IntPtr.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。