Warning with RegOpenExKey and RegSetValueEx

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Wanderer82
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 675
Joined: Tue Jul 26, 2016 2:00 pm

Warning with RegOpenExKey and RegSetValueEx

Post by Wanderer82 »

My compiler gives the warning

passing NULL to non-pointer argument 3 of 'LONG RegOpenKeyExW(HKEY, LPCWSTR, DWORD, REGSAM, PHKEY)' [-Wconversion-null]|

for these statements:

RegOpenKeyEx(HKEY_CURRENT_USER, sKeyPath, NULL, KEY_ALL_ACCESS, &hKey);
RegSetValueEx(hKey, L"LegacyDefaultPrinterMode", NULL, REG_DWORD, (const BYTE*)&value, sizeof(value));

This is the complete code:

Code: Select all

HKEY hKey;
    LPCWSTR sKeyPath;
    sKeyPath = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\";
    RegOpenKeyEx(HKEY_CURRENT_USER, sKeyPath, NULL, KEY_ALL_ACCESS, &hKey);
    DWORD value = 0x00000001;
    RegSetValueEx(hKey, L"LegacyDefaultPrinterMode", NULL, REG_DWORD, (const BYTE*)&value, sizeof(value));
    RegCloseKey(hKey);
   
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Warning with RegOpenExKey and RegSetValueEx

Post by doublemax »

Try "0" or "0L" instead of NULL.

You do know that wxWidgets has functions to access the Windows registry?
https://docs.wxwidgets.org/trunk/classwx_reg_key.html
Use the source, Luke!
Post Reply