regCreateKey function

void regCreateKey(
  1. int hKey,
  2. String subKey
)

Creates a registry key.

Throws a WindowsException if the key cannot be created.

Implementation

void regCreateKey(
  int hKey,
  String subKey,
) {
  final pOpenKey = calloc<IntPtr>();
  final pSubKey = TEXT(subKey);
  try {
    final result = RegCreateKeyEx(
        hKey,
        pSubKey,
        0,
        nullptr,
        0,
        KEY_QUERY_VALUE,
        nullptr, // not inheritable
        pOpenKey,
        nullptr);

    if (result != ERROR_SUCCESS) {
      throw WindowsException(HRESULT_FROM_WIN32(result));
    }
    RegCloseKey(pOpenKey.value);
  } finally {
    calloc
      ..free(pOpenKey)
      ..free(pSubKey);
  }
}