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 8175445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:47:13+00:00 2026-06-06T22:47:13+00:00

Here is my code: #include <stdio.h> #include <string.h> #include <windows.h> #include <tchar.h> #define MAX_KEY_LENGTH

  • 0

Here is my code:

#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <tchar.h>

#define MAX_KEY_LENGTH 6

void CheckForUIMatch(TCHAR *ui, TCHAR *UIToFind, TCHAR *UIFound);

int _tmain(int argc, LPTSTR argv[])
{
    TCHAR UIToFind[24] = _T("hi***;en-US; ");
    TCHAR UIFound[24] = _T("");

    LPCTSTR placeToLook = _T("SYSTEM\\CurrentControlSet\\Control\\MUI\\UILanguages");

    HKEY UIKey;
    DWORD subkeyCounter = 0;
    TCHAR subkeyName[MAX_KEY_LENGTH];
    DWORD subkeyLength;
    DWORD subkeyAmount = 0;

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, placeToLook , 0, KEY_READ, &UIKey) == ERROR_SUCCESS) {

            RegQueryInfoKey(UIKey, NULL, NULL, NULL, &subkeyAmount, NULL, NULL, NULL, NULL, NULL, NULL, NULL); // Get the length of the longest subkey. 

            for (subkeyCounter = 0; subkeyCounter < subkeyAmount; subkeyCounter++) {
                subkeyLength = MAX_KEY_LENGTH;
                RegEnumKeyEx(UIKey,
                        subkeyCounter,
                        subkeyName,
                        &subkeyLength,
                        NULL,
                        NULL,
                        NULL,
                        NULL);
                CheckForUIMatch(subkeyName, UIToFind, UIFound);

            }
    } else {
        _tprintf(L"Faild to open the registry key!");
    }


    _tprintf(_T("Match: %s"), UIFound);

    return 0;
}

void CheckForUIMatch(TCHAR *ui, TCHAR *UIToFind, TCHAR *UIFound)
{
    int charToMatch;
    TCHAR* token = _tcstok(UIToFind, L";");
    while(token != NULL) {
        /* Check for exact match or general match */
        if ((token[_tcslen(token)-2] == '*') && (token[_tcslen(token)-1] == '*')) { // make general lang match
            charToMatch = 2;    
        } else {
            charToMatch = 5; // make exact lang match
        }

        _tprintf(L"\ntoken: %s, to match %d.\n", token, charToMatch); //Debug
        if(!_tcsncmp(token, ui, charToMatch)) {
            _tcsncat(UIFound, ui, charToMatch);
            _tcscat(UIFound, _T(";"));
        }
        token = _tcstok(NULL, L";");

    }
}

The problem:

It seems that the while loop at the CheckForUIMatch is doing its work only once, but at the second time the loop is run (e.g. when there is more than one UI that is found in the registry), it loop only on one of the tokens (e.g. hi***) and not at the second, once it end the loop and needs to get the second token i can see in the debugger that it get BatPointer instead of the second token.

If i put the UIToFind TCHAR directly inside the CheckForUIMatch function, everything is working fine, i am don’t know why? is anybody knows ?

  • 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-06T22:47:14+00:00Added an answer on June 6, 2026 at 10:47 pm

    strtok modifies the search string in-place to delimit the substrings. Your search string evolves thus as you call strtok:

    "hi***;en-US; "
    "hi***\0en-US; "
    "hi***\0en-US\0 "
    

    When you try to reuse this string in a second round of calls to strtok, the function sees "hi***" because the first '\0' terminates the string.

    Instead of splitting the string each time, split it once or declare it as an array, e.g.:

    LPCTSTR UiToFind[] = {_T("hi***"), _T("en-US") };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: #include <stdio.h> #include <string.h> #include <errno.h> int cmp(const void *a,
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
Here is my code #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
So I have the following test code: #include <string.h> #include <stdio.h> int main(int argc,
I am going to paste here my code and errors: #include stdio.h #include winsock2.h
Here is my code which checks if the file exists : #include<stdio.h> #include<zlib.h> #include<unistd.h>
Here is my code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; int
Here is my code #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h>

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.