本文整理汇总了C#中System.IntPtr.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IntPtr.Write方法的具体用法?C# IntPtr.Write怎么用?C# IntPtr.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IntPtr
的用法示例。
在下文中一共展示了IntPtr.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryValue
/// <summary>
/// Queries a key from the VREG, or if not exists from the RREG.
/// </summary>
/// <remarks>
/// Documentation from MSDN:
/// If the function succeeds, the return value is ERROR_SUCCESS.
/// If the lpData buffer is too small to receive the data, the function returns ERROR_MORE_DATA.
/// If the lpValueName registry value does not exist, the function returns ERROR_FILE_NOT_FOUND.
/// </remarks>
/// <param name="hKey"></param>
/// <param name="lpValueName">The name of the registry value.</param>
/// <param name="lpReserved">This parameter is reserved and must be NULL.</param>
/// <param name="lpType">
/// A pointer to a variable that receives a code indicating the type of data
/// stored in the specified value. For a list of the possible type codes, see Registry Value Types.
/// The lpType parameter can be NULL if the type code is not required.
/// </param>
/// <param name="lpData">
/// A pointer to a buffer that receives the value's data.
/// This parameter can be NULL if the data is not required.
/// </param>
/// <param name="lpcbData">
/// A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter,
/// in bytes. When the function returns, this variable contains the size of the data copied to lpData.
/// The lpcbData parameter can be NULL only if lpData is NULL.
/// </param>
/// <returns></returns>
public NativeResultCode QueryValue(UIntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpValueName,
IntPtr lpReserved, IntPtr lpType, IntPtr lpData, IntPtr lpcbData)
{
// BUG: If lpValueName is NULL or an empty string, the function retrieves the type and data for the key's unnamed or default value, if any.
if (string.IsNullOrEmpty(lpValueName))
return NativeResultCode.FileNotFound;
uint handle;
if (!TryParse(hKey, out handle))
return NativeResultCode.InvalidHandle;
using (EngineCore.Engine.GetEngineProcessingSpace())
{
VirtualRegistryValue virtualRegistryValue;
var resultCode = _registry.QueryValue(handle, lpValueName, out virtualRegistryValue);
EngineCore.Log.Debug("QueryValue(HKey={0} ValueName={1}) => {2}",
handle, lpValueName, resultCode);
if (resultCode != NativeResultCode.Success)
return resultCode;
// Marshal all data to the specified pointers.
if (lpType != IntPtr.Zero)
lpType.Write(virtualRegistryValue.Type);
if (lpcbData != IntPtr.Zero)
{
if (virtualRegistryValue.Data.Length > lpcbData.Read<uint>())
return NativeResultCode.MoreData;
if (lpData != IntPtr.Zero) // Guest might only need length
lpData.Write(virtualRegistryValue.Data);
lpcbData.Write(virtualRegistryValue.Data.Length);
}
return NativeResultCode.Success;
}
}