Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LPWSTR utf8ToWideChar(std::string utf8) {
return result;
}

Napi::Object CreateEntry(Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data, DWORD dataLengthBytes)
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data, DWORD dataLengthBytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add const to the type parameter so we can avoid the const_cast uses?

Suggested change
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data, DWORD dataLengthBytes)
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, const LPWSTR type, LPWSTR data, DWORD dataLengthBytes)

Copy link
Contributor Author

@kmashint kmashint Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I adjusted. This isn't yet updating node-gyp in package.json, but needs at least node-gyp@9 to recognize MS VisualStudio 2022, e.g. [email protected] , or the latest now is 11.2.0.

{
// NB: We must verify the data, since there's no guarantee that REG_SZ are stored with null terminators.

Expand All @@ -64,7 +64,7 @@ Napi::Object CreateEntry(Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data,
return obj;
}

Napi::Object CreateEntry(Napi::Env& env, LPWSTR name, LPWSTR type, DWORD data)
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, LPWSTR type, DWORD data)
{
auto obj = Napi::Object::New(env);
obj.Set(Napi::String::New(env, "name"), Napi::String::New(env, (char16_t*)name));
Expand All @@ -73,7 +73,7 @@ Napi::Object CreateEntry(Napi::Env& env, LPWSTR name, LPWSTR type, DWORD data)
return obj;
}

Napi::Array EnumerateValues(Napi::Env& env, HKEY hCurrentKey) {
Napi::Array EnumerateValues(const Napi::Env& env, HKEY hCurrentKey) {
DWORD cValues, cchMaxValue, cbMaxValueData;

auto retCode = RegQueryInfoKey(
Expand Down Expand Up @@ -125,19 +125,19 @@ Napi::Array EnumerateValues(Napi::Env& env, HKEY hCurrentKey) {
if (lpType == REG_SZ)
{
auto text = reinterpret_cast<LPWSTR>(buffer.get());
auto obj = CreateEntry(env, achValue, L"REG_SZ", text, cbData);
auto obj = CreateEntry(env, achValue, const_cast<LPWSTR>(L"REG_SZ"), text, cbData);
results.Set(i, obj);
}
else if (lpType == REG_EXPAND_SZ)
{
auto text = reinterpret_cast<LPWSTR>(buffer.get());
auto obj = CreateEntry(env, achValue, L"REG_EXPAND_SZ", text, cbData);
auto obj = CreateEntry(env, achValue, const_cast<LPWSTR>(L"REG_EXPAND_SZ"), text, cbData);
results.Set(i, obj);
}
else if (lpType == REG_DWORD)
{
assert(cbData == sizeof(DWORD));
results.Set(i, CreateEntry(env, achValue, L"REG_DWORD", *reinterpret_cast<DWORD*>(buffer.get())));
results.Set(i, CreateEntry(env, achValue, const_cast<LPWSTR>(L"REG_DWORD"), *reinterpret_cast<DWORD*>(buffer.get())));
}
}
else if (retCode == ERROR_NO_MORE_ITEMS)
Expand All @@ -159,7 +159,7 @@ Napi::Array EnumerateValues(Napi::Env& env, HKEY hCurrentKey) {

Napi::Value ReadValues(const Napi::CallbackInfo& info)
{
Napi::Env& env = info.Env();
const Napi::Env& env = info.Env();

if (info.Length() < 2)
{
Expand Down Expand Up @@ -219,8 +219,8 @@ Napi::Value ReadValues(const Napi::CallbackInfo& info)
}

Napi::Value EnumKeys(const Napi::CallbackInfo& info) {
Napi::Env& env = info.Env();
const Napi::Env& env = info.Env();

auto argCount = info.Length();
if (argCount != 1 && argCount != 2)
{
Expand Down Expand Up @@ -285,8 +285,8 @@ Napi::Value EnumKeys(const Napi::CallbackInfo& info) {

Napi::Value CreateKey(const Napi::CallbackInfo& info)
{
Napi::Env& env = info.Env();
const Napi::Env& env = info.Env();

auto argCount = info.Length();
if (argCount != 2)
{
Expand Down Expand Up @@ -343,7 +343,7 @@ Napi::Value CreateKey(const Napi::CallbackInfo& info)

Napi::Value SetValue(const Napi::CallbackInfo& info)
{
Napi::Env& env = info.Env();
const Napi::Env& env = info.Env();

auto argCount = info.Length();
if (argCount != 5)
Expand Down Expand Up @@ -446,7 +446,7 @@ Napi::Value SetValue(const Napi::CallbackInfo& info)
datalength);
}
else if (wcscmp(valueType, L"REG_DWORD") == 0)
{
{
uint32_t dwordData = info[4].ToNumber().Uint32Value();
DWORD valueData = static_cast<DWORD>(dwordData);

Expand Down