c# - 将 uint 传递给 IntPtr 参数
问题描述
我正在尝试使用 RegCreateKeyExA 函数创建注册表项。我对 C# 很陌生,所以我可能错了,但我得出的结论是第一个参数是 IntPtr。问题是我不知道如何使用 IntPtr 数据类型,并且对我在该主题上找到的所有不同线程感到有点不知所措。我需要澄清我应该使用的数据类型以及如何处理它们。这是我的代码:
using System;
using System.Runtime.InteropServices;
namespace Win32Application
{
public class Win32
{
public static uint KEY_CREATE_SUB_KEY = 4;
public static uint HKEY_CURRENT_USER = 80000001;
public static uint REG_OPTION_NON_VOLATILE = 0;
[DllImport("Advapi32.dll", CharSet = CharSet.Ansi)]
public static extern int RegCreateKeyExA(IntPtr hKey, string lpSubKey, uint Reserved,
string lpClass, uint dwOptions, uint samDesired, ref SECURITY_ATTRIBUTES lpSecurityAttributes,
ref uint phkResult, ref uint lpdwDisposition);
public struct SECURITY_ATTRIBUTES
{
ulong nLenght;
IntPtr lpSecurityDescriptor;
bool bInheritHandle;
}
static void Main()
{
uint result = 0;
uint created_or_existing = 0;
string subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
SECURITY_ATTRIBUTES secAttrs = new SECURITY_ATTRIBUTES();
RegCreateKeyExA(ref HKEY_CURRENT_USER, subKey, 0, null, REG_OPTION_NON_VOLATILE,
KEY_CREATE_SUB_KEY, ref secAttrs, ref result, ref created_or_existing);
}
}
}
解决方案
推荐阅读
- scala.js - node.js 抛出“Buffer.alloc 不是函数”错误
- django - 如何向 Django DayArchiveView 添加上下文/附加字典
- javascript - 如何在函数 React 中从 onClick 返回 ID
- javascript - 在 Javasript 中创建模拟时钟时秒针停止移动
- python - Python 正则表达式将多个匹配项映射到一个
- anylogic - Anylogic:叉车在节点前卡住
- javascript - 如何克隆表单并将其输入的 id 更改 2,3 次?
- c# - EFCore 中的表关系不包含在查询中
- cqrs - CQRS 中的预防措施
- python - 如果我将图像粘贴到 pygame 的主窗口上,它不会按预期显示