📄 registry.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
// ************************************************************
// This file contains registry related helper routines for the
// Unimodem SPI.
// **********************************************************************
#include "windows.h"
#include "types.h"
#include "memory.h"
#include "mcx.h"
#include "tspi.h"
#include "linklist.h"
#include "tspip.h"
#include "tapicomn.h"
#ifdef DEBUG
#define REG_MSGS 0
#endif
// ***************************************************************************
//
// ***************************************************************************
DWORD
MdmRegGetValue(
PTLINEDEV ptLineDev, // Which line device
LPCWSTR szKeyName, // Which Unimodem key contains the value
LPCWSTR szValueName, // What value should we look up
DWORD dwType, // And what type should it be
LPBYTE lpData, // Where do we return the results
LPDWORD lpdwSize // How large is lpData
)
{
DWORD dwTmpType = dwType;
DWORD dwRetCode;
HKEY hKey;
// ----------------------------------------------------------------------
// ------- First, see if a device specific value exists -----------------
// ----------------------------------------------------------------------
// Open the device specific key if needed
if( NULL != szKeyName )
{
dwRetCode = RegOpenKeyEx(
ptLineDev->hSettingsKey,
szKeyName,
0,
KEY_READ,
&hKey);
DEBUGMSG(REG_MSGS & ZONE_MISC,
(TEXT("UNIMODEM:MdmRegGetValue RegOpenKeyEx(%s) failed %d\n"),
szKeyName, dwRetCode));
}
else
{
// No need to open anything, use base key.
hKey = ptLineDev->hSettingsKey;
dwRetCode = ERROR_SUCCESS;
}
if (ERROR_SUCCESS == dwRetCode)
{
dwRetCode = RegQueryValueEx(hKey,
szValueName,
NULL,
&dwTmpType,
(PUCHAR)lpData,
lpdwSize);
if ( dwRetCode != ERROR_SUCCESS)
{
DEBUGMSG(REG_MSGS & ZONE_MISC,
(TEXT("UNIMODEM:MdmRegGetValue RegQueryValueEx failed when reading %s (device specific).\r\n"), szValueName));
}
else
{
if (dwTmpType != dwType)
{
// Hmm, this shouldn't happen. I guess the best thing to
// do is to see if we can find a valid entry in the defaults
DEBUGMSG(REG_MSGS & ZONE_MISC,
(TEXT("UNIMODEM:MdmRegGetValue '%s' was type x%X, not x%X.\r\n"),
szValueName, dwTmpType, dwType));
dwRetCode = ERROR_NO_TOKEN; // cause us to read default below
}
}
// be sure to close the key if we opened it
if( szKeyName != NULL )
{
RegCloseKey( hKey );
}
}
else
{
// we couldn't open a device specific key, fall thru to default
DEBUGMSG(REG_MSGS & ZONE_MISC,
(TEXT("UNIMODEM:MdmRegGetValue Unable to open device specific key for %s. (ignoring)\r\n"), szKeyName));
}
// ----------------------------------------------------------------------
// ------- If needed, look for the default value ------------------------
// ----------------------------------------------------------------------
if( ERROR_SUCCESS != dwRetCode )
{
// Open the default key if needed
if( NULL != szKeyName )
{
dwRetCode = RegOpenKeyEx(
TspiGlobals.hDefaultsKey,
szKeyName,
0,
KEY_READ,
&hKey);
}
else
{
// No need to open anything, use base key.
hKey = TspiGlobals.hDefaultsKey;
dwRetCode = ERROR_SUCCESS;
}
if (ERROR_SUCCESS == dwRetCode)
{
// Open the specified default key
dwTmpType = dwType;
dwRetCode = RegQueryValueEx(hKey,
szValueName,
NULL,
&dwTmpType,
(PUCHAR)lpData,
lpdwSize);
if ( dwRetCode != ERROR_SUCCESS)
{
DEBUGMSG(REG_MSGS & ZONE_MISC,
(TEXT("UNIMODEM:MdmRegGetValue RegQueryValueEx failed when reading %s (default).\r\n"), szValueName));
}
else
{
if (dwTmpType != dwType)
{
// Hmm, this shouldn't happen. I guess the best thing to
// do is to see if we can find a valid entry in the defaults
DEBUGMSG(REG_MSGS & ZONE_MISC,
(TEXT("UNIMODEM:MdmRegGetValue '%s' was type x%X, not x%X.\r\n"),
szValueName, dwTmpType, dwType));
dwRetCode = ERROR_NO_TOKEN; // return an error
}
}
// be sure to close the key if we opened it
if( szKeyName != NULL )
{
RegCloseKey( hKey );
}
}
else
{
// we couldn't open a default key, return error
DEBUGMSG(REG_MSGS & ZONE_ERROR,
(TEXT("UNIMODEM:MdmRegGetValue Unable to open default key for %s rc=%d.\r\n"),
szKeyName, dwRetCode));
}
}
return dwRetCode;
} // MdmRegGetValue
void
MdmRegGetLineValues(
PTLINEDEV ptLineDev
)
{
static const WCHAR szPPPMTU[] = TEXT("PPPMTU");
static const WCHAR szMaxCmd[] = TEXT("MaxCmd");
static const WCHAR szCmdSendDelay[] = TEXT("CmdSendDelay");
static const WCHAR szMdmLogFile[] = TEXT("MdmLogFile");
DWORD dwSize, dwRetCode, dwTemp;
WCHAR szContinuation[16];
// Get the MTU for this device for PPP
dwSize = sizeof( DWORD );
dwRetCode = MdmRegGetValue(ptLineDev, NULL, szPPPMTU, REG_DWORD,
(LPBYTE)&dwTemp, &dwSize);
if( dwRetCode == ERROR_SUCCESS ) {
ptLineDev->dwPPPMTU = dwTemp;
} else {
ptLineDev->dwPPPMTU = 1500;
}
DEBUGMSG(ZONE_MISC|ZONE_INIT, (TEXT("UNIMODEM:MdmRegGetLineValues - PPP MTU %d.\r\n"), ptLineDev->dwPPPMTU));
// Get the maximum command length from registry
dwSize = sizeof( DWORD );
dwRetCode = MdmRegGetValue(ptLineDev, szSettings, szMaxCmd, REG_DWORD,
(LPBYTE)&dwTemp, &dwSize);
if( dwRetCode == ERROR_SUCCESS ) {
DEBUGMSG(ZONE_MISC|ZONE_INIT,
(TEXT("UNIMODEM:MdmRegGetLineValues - Max command length x%X.\r\n"), dwTemp));
ptLineDev->dwMaxCmd = (WORD)dwTemp;
} else {
DEBUGMSG(ZONE_MISC|ZONE_INIT,
(TEXT("UNIMODEM:MdmRegGetLineValues - Max command length defaulting to x%X.\r\n"), MAX_CMD_LENGTH));
ptLineDev->dwMaxCmd = MAX_CMD_LENGTH;
}
// Get the time in milliseconds to delay before sending Commands to modem
dwSize = sizeof( DWORD );
dwRetCode = MdmRegGetValue(ptLineDev, szSettings, szCmdSendDelay, REG_DWORD,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -