How to convert CString to decimal value

mousumi majumder 20 Reputation points

I want to convert Cstring to decimal value in mfc application.

This is my code looks like

CString keyvalue = _T("SHIFT");

for (int i = 0 ; i < keyvalue.Getlength(); i++)


int decvalue = keyvalue[i];


so now I got decvalue is 83 which is for S It is giving me decimal value for single character but not the entire string so I need entire string value like for shift decimal value is 16 so I want to get 16

someone please look into that

I have tried that above scenario but not able to get the decimal of whole string

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,117 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,327 questions
{count} votes

Accepted answer
  1. Minxin Yu 8,271 Reputation points Microsoft Vendor


    I found a similar thread: How to convert vk_shift value to decimal value?

    Please check the document: Virtual-Key Codes

    The value of the virtual key is defined by macro. You can use map to bind relationship between CString and decimal value.

    #define VK_SHIFT 0x10

    	std::map<CString, int > vk_key = {
    			{  (CString)"SHIFT",VK_SHIFT}
    	CString keyvalue = _T("SHIFT");
    	int vaule = vk_key[keyvalue];

    Best regards,

    Minxin Yu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. RLWA32 37,131 Reputation points

    As far as I know there is no Windows API function that accepts the name of a key and returns the virtual-key code.

    However, the GetKeyNameTextW function will return the name of a key associated with a scan code and the MapVirtualKeyExW function can return the scan code for a virtual-key code.

    0 comments No comments