我有这个 P/Invoke RegSetValueExW 将值设置为注册表项。在 C# 中
[DllImport("coredll.dll", EntryPoint = "RegSetValueExW")]
public static extern int RegSetValueExW(uint hKey, string lpValueName,
uint lpReserved,
uint lpType,
byte[] lpData,
uint lpcbData);
我的第 4 个参数 byte[] lpdata 有问题。我需要传递一个值为 5 (int) 的 DWORD。如果我传递一个字符串 (REG_SZ),一切正常,只需要使用 GetBytes 函数进行转换。
如果我调用 GetBytes("5") 它将其转换为 53 的 ascii 值,因此它将 53 写入注册表值而不是 5