本文整理汇总了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);
}
示例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;
}
示例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();
}
示例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));
}
示例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)));
}