/*++ Copyright (c) 1995-1996 Microsoft Corporation Module Name: catentry Abstract: Read & write the relevant registry entries. Author: Steve Firebaugh (stevefir) 14-Jan-1995 Revision History: --*/ #include #include #include #include #include #include "ws2spi.h" #include "sporder.h" #include "globals.h" #define MAX_ENTRIES 1000 // hack, make dynamic WSAPROTOCOL_INFOW ProtoInfo[MAX_ENTRIES]; // // keep track of the total number of entries in the list box; // int gNumRows = 0; int CatReadRegistry (HWND hwnd) /*++ Called once when the dialog first comes up. Read the registry and fill the listbox with all of the entries. --*/ { TCHAR szOutput[MAX_STR]; TCHAR szInput[MAX_STR]; TCHAR szBuffer[MAX_STR]; LONG r; INT iIndex; DWORD dwSize; // // set a tab stop far off of the screen, so that we can store the original // index there, and it will stay glued to the string even as the user // reorders them (unless we are building a debug). // #ifndef DEBUG { int iTab; iTab = 300; SendMessage (HWNDLISTCTL, LB_SETTABSTOPS, 1, (LPARAM) &iTab); } #endif dwSize = sizeof (ProtoInfo); gNumRows = WSCEnumProtocols (NULL, ProtoInfo, &dwSize, &r); if (gNumRows==SOCKET_ERROR) { CatCheckRegErrCode (hwnd, r, TEXT("WSCEnumProtocols")); return FALSE; } for (iIndex = 0; iIndex= gNumRows) iSelection = gNumRows-1 ; // // Re-insert the string and restore the selection // SendMessage (HWNDLISTCTL, LB_INSERTSTRING, iSelection, (LPARAM)szBuffer); SendMessage (HWNDLISTCTL, LB_SETCURSEL, iSelection, 0); } return TRUE; } BOOL CatGetIndex (LPTSTR szBuffer, LPINT lpIndex, LPINT lpCatID) /*++ The original index is stored after a tab stop, hidden from view far off screen to the right. Parse the string for the tab stop, and read the next value. The catalog ID is stored to the right of the index. --*/ { int r; TCHAR *p; // // To get the index, start at the begining of the string, parse // it for tokens based on tab as a separator, and take the // second one. // #ifdef UNICODE p = wcstok (szBuffer, TEXT("\t")); p = wcstok (NULL, TEXT("\t")); r = swscanf (p, TEXT("%d"), lpIndex); ASSERT((r == 1), TEXT("#1 ASSERT r == 1")) p = wcstok (NULL, TEXT("\t")); r = swscanf (p, TEXT("%d"), lpCatID); ASSERT((r == 1), TEXT("#2 ASSERT r == 1")) #else p = strtok (szBuffer, TEXT("\t")); p = strtok (NULL, TEXT("\t")); r = sscanf (p, TEXT("%d"), lpIndex); ASSERT((r == 1), TEXT("#1 ASSERT r == 1")) p = strtok (NULL, TEXT("\t")); r = sscanf (p, TEXT("%d"), lpCatID); ASSERT((r == 1), TEXT("#2 ASSERT r == 1")) #endif return TRUE; }