本文整理匯總了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;
}
}