Hello.. I'm writing a Euchre program because I'm bored >.< and I let the player name the teams which exist so its easier to display the scores. So when the program starts, the user inputs two team names and they're stored in the registry. Everything up to here works fine. If the user has already set team names, I want to read them in from the registry and display them on the controls. I have no idea why, but this part isn't work. I tried having two separate values Team1 and Team2 and tried condensing them into one value called Teams. As two separate values, Team2 is read in and displayed, but Team1 is null. As one value, nothing is read in. Here's the code I'm using..

Each team with a separate value:
Code:
void set_names(HWND hwnd)
{
     HINSTANCE hInst = GetModuleHandle(NULL);
     int i = 0;
     char *buf;
     int len = GetWindowTextLength(GetDlgItem(hwnd, ID_STAT_PLAYER3)), teams = 0;
     char pname[256] = {0}, t1name[256] = {0}, t2name[256] = {0};
     LONG lRet, lRetStatus, lRetTeam;
     HKEY hKey;
     DWORD dwLength = 100, dwType = REG_SZ, dwSize = 255;
     
     lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\ShibbyInc", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
     
     lRetStatus = RegQueryValueEx(hKey, "Name", NULL, &dwType, (LPBYTE)&pname, &dwSize);
     if (lRetStatus == ERROR_SUCCESS)
     {
         SetDlgItemText(hwnd, ID_STAT_PLAYER3, pname);
     }
     else
     {    
         RegCloseKey(hKey);
         DialogBox(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    }
    
    lRetTeam = RegQueryValueEx(hKey, "Team1", NULL, &dwType, (LPBYTE)&t1name, &dwSize);
    ErrorFunc("RegQueryValueEx for Team 1");
    if (lRetTeam == ERROR_SUCCESS)
    {
        MessageBox(0, t1name, "Team 1", MB_OK);
        for (i = ID_STAT1_TEAM1; i <= ID_STAT3_TEAM1; i++)
        {
            if (SetDlgItemText(g_hwnd, i, t1name) == 0)
		       ErrorFunc("SetDlgItemText");
        }
    }
    else
    {
        ErrorFunc("RegQueryValueEx");
        MessageBox(0, t1name, "Team 1", MB_OK);
        teams = 1;
    }
    
    lRetTeam = RegQueryValueEx(hKey, "Team2", NULL, &dwType, (LPBYTE)&t2name, &dwSize);
    if (lRetTeam == ERROR_SUCCESS)
    {
        for (i = ID_STAT1_TEAM2; i <= ID_STAT3_TEAM2; i++)
        {
            if (SetDlgItemText(g_hwnd, i, t2name) == 0)
		       ErrorFunc("SetDlgItemText");
        }
    }
    else
        teams = 1;
        
    if (teams == 1)
    {
        RegCloseKey(hKey);
        DialogBox(hInst, MAKEINTRESOURCE(IDD_TNAME), NULL, TDlgProc);
    }
}
Both team names in one value:
Code:
void set_names(HWND hwnd)
{
     HINSTANCE hInst = GetModuleHandle(NULL);
     int i = 0, x = 0;
     char *buf;
     int len = GetWindowTextLength(GetDlgItem(hwnd, ID_STAT_PLAYER3));
     char pname[256] = {0}, teams[256] = {0}, t1name[128] = {0}, t2name[128] = {0};
     LONG lRet, lRetStatus, lRetTeam;
     HKEY hKey;
     DWORD dwLength = 100, dwType = REG_SZ, dwSize = 255;
     
     lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\ShibbyInc", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
     
     lRetStatus = RegQueryValueEx(hKey, "Name", NULL, &dwType, (LPBYTE)&pname, &dwSize);
     if (lRetStatus == ERROR_SUCCESS)
     {
         SetDlgItemText(hwnd, ID_STAT_PLAYER3, pname);
     }
     else
     {    
         RegCloseKey(hKey);
         DialogBox(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    }
    RegCloseKey(hKey);
    lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\ShibbyInc", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
/* I added this code to close and reopen the key thinking that may be a problem
 * but it wasn't and it still doesn't work :[
 */
     
    lRetTeam = RegQueryValueEx(hKey, "Teams", NULL, &dwType, (LPBYTE)&teams, &dwSize);
    MessageBox(0, teams, "Teams", MB_OK);
    if (lRetTeam == ERROR_SUCCESS)
    {
        while (teams[i] != ' ')
        {
            t1name[x] = teams[i];
            ++i;
            ++x;
        }
        ++i;
        x = 0;
        while (teams[i] != '\0')
        {
            t2name[x] = teams[i];
            ++i;
            ++x;
        }
        for (i = ID_STAT1_TEAM1; i <= ID_STAT3_TEAM1; i++)
        {
            if (SetDlgItemText(g_hwnd, i, t1name) == 0)
		       ErrorFunc("SetDlgItemText");
        }
        for (i = ID_STAT1_TEAM2; i <= ID_STAT3_TEAM2; i++)
        {
            if (SetDlgItemText(g_hwnd, i, t2name) == 0)
		       ErrorFunc("SetDlgItemText");
        }
    }
    else
    {
        RegCloseKey(hKey);
        DialogBox(hInst, MAKEINTRESOURCE(IDD_TNAME), NULL, TDlgProc);
    }
}
(this also shows the code I'm using for the players name which works fine every time)

any ideas about what's going wrong? I'd greatly appreciate any help :] thanks