/*========================================================================== * * Copyright (C) 1995 - 2000 Microsoft Corporation. All Rights Reserved. * * File: registry.c * * History: * Date By Reason * ==== == ====== * ??? * 12/28/99 aarono added query for required key for Win95 rsip support * 04/19/01 vanceo added nathelp DLL retrieval and copied to dplaysvr * ***************************************************************************/ #include "dpsp.h" #define REGISTRY_NAMELEN 512 // space (in bytes) for a human readable (unicode) guid + some extra #define GUID_STRING_SIZE 80 #define SZ_SP_KEY "Software\\Microsoft\\DirectPlay\\Service Providers" #define SZ_GUID "Guid" #define SZ_FLAGS "dwFlags" #define SZ_GATEWAY "Gateway" #define SZ_NATHELP "NATHelp" #undef DPF_MODNAME #define DPF_MODNAME "FindApplicationInRegistry" // convert a hex char to an int - used by str to guid conversion // we wrote our own, since the ole one is slow, and requires ole32.dll // we use ansi strings here, since guids won't get internationalized int GetDigit(LPSTR lpstr) { char ch = *lpstr; if (ch >= '0' && ch <= '9') return(ch - '0'); if (ch >= 'a' && ch <= 'f') return(ch - 'a' + 10); if (ch >= 'A' && ch <= 'F') return(ch - 'A' + 10); return(0); } // walk the string, writing pairs of bytes into the byte stream (guid) // we need to write the bytes into the byte stream from right to left // or left to right as indicated by fRightToLeft void ConvertField(LPBYTE lpByte,LPSTR * ppStr,int iFieldSize,BOOL fRightToLeft) { int i; for (i=0;i cbszGateway){ DPF_ERR("Not enough room for gateway address"); goto CLEANUP_EXIT; } memcpy(lpszGateway, lpValue, dwSize); // fall through CLEANUP_EXIT: if (lpszSPName) SP_MemFree(lpszSPName); if (lpValue) SP_MemFree(lpValue); // Close the Apps key if(hkeySP) RegCloseKey(hkeySP); return hr; } // GetGatewayFromRegistry #elif USE_NATHELP // ! USE_RSIP #undef DPF_MODNAME #define DPF_MODNAME "GetNATHelpDLLFromRegistry" HRESULT GetNATHelpDLLFromRegistry(LPGUID lpguidSP, LPBYTE lpszNATHelpDLL, DWORD cbszNATHelpDLL) { LPSTR lpszSPName=NULL; HKEY hkeySP = NULL; LPBYTE lpValue=NULL; DWORD dwSize = 0; HRESULT hr = DP_OK; DPF(7, "Entering GetNATHelpDLLFromRegistry"); DPF(8, "Parameters: 0x%08x, 0x%08x %d", lpguidSP, lpszNATHelpDLL, cbszNATHelpDLL); ENTER_DPSP(); // Allocate memory for the SP Name lpszSPName = SP_MemAlloc(REGISTRY_NAMELEN); LEAVE_DPSP(); if(!lpszSPName) { DPF_ERR("Unable to allocate memory for sp name!"); return E_OUTOFMEMORY; } // Open the registry key for the SP if(!FindSPInRegistry(lpguidSP, lpszSPName,REGISTRY_NAMELEN, &hkeySP)) { DPF_ERR("Unable to find sp in registry!"); hr = E_FAIL; goto CLEANUP_EXIT; } // Get the gateway value. if(!GetKeyValue(hkeySP, SZ_NATHELP, REG_SZ, &lpValue)) { DPF(1, "Unable to get NATHelp key value from registry."); hr = E_FAIL; goto CLEANUP_EXIT; } dwSize = strlen(lpValue)+1; if(dwSize > cbszNATHelpDLL){ DPF_ERR("Not enough room for NATHelp DLL path"); goto CLEANUP_EXIT; } memcpy(lpszNATHelpDLL, lpValue, dwSize); // fall through CLEANUP_EXIT: if (lpszSPName) SP_MemFree(lpszSPName); if (lpValue) SP_MemFree(lpValue); // Close the Apps key if(hkeySP) RegCloseKey(hkeySP); return hr; } // GetNATHelpDLLFromRegistry #endif // USE_NATHELP