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


C# IntPtr.Read方法代码示例

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


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

示例1: SetValueEx

 /// <summary>
 /// This method will insert a value into the VREG.
 /// </summary>
 /// <param name="hKey">A handle to an open registry key.</param>
 /// <param name="lpValueName">
 /// The name of the value to be set. If a value with this name is not already present in the key,
 /// the function adds it to the key.
 /// If lpValueName is NULL or an empty string, "", the function sets the type and data for
 /// the key's unnamed or default value.
 /// </param>
 /// <param name="reserved">This parameter is reserved and must be zero.</param>
 /// <param name="dwType">The type of data pointed to by the <paramref name="lpData"/> parameter.</param>
 /// <param name="lpData">The data to be stored.</param>
 /// <param name="cbData">The size of the information pointed to by the lpData parameter, in bytes.</param>
 /// <returns>A WinError code.</returns>
 public NativeResultCode SetValueEx(UIntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpValueName,
                                       uint reserved, ValueType dwType, IntPtr lpData, uint cbData)
 {
   uint handle;
   if (!TryParse(hKey, out handle))
     return NativeResultCode.InvalidHandle;
   using (EngineCore.Engine.GetEngineProcessingSpace())
   {
     var data = lpData.Read<byte[]>(cbData);
     var registryValue = new VirtualRegistryValue(lpValueName, data, dwType);
     var resultCode = _registry.SetValue(handle, registryValue);
     EngineCore.Log.Debug("SetValue(HKey={0} Name={1} Type={2}) => {3}",
                         handle, lpValueName, dwType, resultCode);
     return resultCode;
   }
 }
开发者ID:rnpowerconsulting,项目名称:appstract,代码行数:31,代码来源:RegistryHookHandler.cs

示例2: 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;
   }
 }
开发者ID:rnpowerconsulting,项目名称:appstract,代码行数:58,代码来源:RegistryHookHandler.cs


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