Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:50:39+00:00 2026-06-14T12:50:39+00:00

This codes purpose is to add or edit the value of KeyboardDelay REG_SZ. What

  • 0

This codes purpose is to add or edit the value of KeyboardDelay REG_SZ. What I can do is make its value 0 but when I try making it 31, it fails and a weird “box” comes as KeyboardDelays data value instead of the number 31. What am I doing wrong with this since it wont add 31 but it will do 0?

HKEY key;
if (RegOpenKey(HKEY_CURRENT_USER, TEXT("Control Panel\\Keyboard"), &key) != ERROR_SUCCESS)
{
cout << "Unable to open registry key";
}

if (RegSetValueEx(key, TEXT("KeyboardDelay"), 0, REG_SZ, (LPBYTE)"31", strlen("31")*sizeof(char)) != ERROR_SUCCESS)
{
RegCloseKey(key);
cout <<"Unable to set registry value value_name";
}
else
{
   cout << "KeyboardDelay was set" << endl;
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:50:40+00:00Added an answer on June 14, 2026 at 12:50 pm

    RegSetValueEx is defined in winreg.h as follows:

    #ifdef UNICODE
    #define RegSetValueEx  RegSetValueExW
    #else
    #define RegSetValueEx  RegSetValueExA
    #endif // !UNICODE
    

    this means that when UNICODE is defined then RegSetValueExW will be used. The last letter ‘W’ means that it accepts wide character strings (wchar_t*), ‘A’ means it accept multibyte character strings. So if you know you are compiling with UNICODE enabled (project properties -> Configuration -> Character Set -> Use Unicode Character Set), you should provide wide character string literals. The easiest way under windows is to use macros:

    TEXT("31")
    

    or my favorite:

    _T("31")
    

    those two macros will result into “31” under non UNICODE compilation, and into L”31″ under UNICODE compilation.

    also you should use proper string functions, to get length use wcslen for UNICODE and strlen for multibyte character set. You can use _t* macros that check character set for you and use _tcslen() to get length.

    Actually you should always use UNICODE when creating new projects.

    to fix your code use :

    if (RegSetValueEx(key, TEXT("KeyboardDelay"), 0, REG_SZ, (LPBYTE)TEXT("31"),_tcslen(TEXT("31"))*sizeof(TCHAR)) != ERROR_SUCCESS)
    

    sizeof(TCHAR) is used here because when UNICODE is defined then single character is two bytes length, and RegSetValueEx requires number of bytes and not number of characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use inline edit in my application. For this purpose I am
The purpose of this code is to pull upgrade.zip from a central server, extract
What is the purpose of these java.lang.annotation imports in this code? Why are they
Quick question, What have I done wrong here. The purpose of this code is
This Codes give me error: Msg 156, Level 15, State 1, Procedure DefaultActivity, Line
This below codes give me error below: How to generate this codes help me
Look please below this codes throw me : FormatException was unhandled by user code
I'm using this codes for listing custom field values into drop-down list element on
This may be waaay to specific for SO, but there seems to be a
Using javascript, how can I add to an array an element which contains fields

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.