📄 appcore.cpp
字号:
return strValue.Todouble();
}
/*
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section containing the entry.
// lpszEntry Points to a null-terminated string that contains the
// entry whose value is to be retrieved.
// pbyData Pointer to the buffer that receives the data associated with section and key names.
//
// wDataLen Specifies the size, in bytes, of the buffer pointed to by the pbyData parameter.
// Return Value:
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
// Remarks:
// Call this member function to retrieve the data associated with the specified key
// in the given section of the application's .INI file.
BOOL CRTApp::GetProfileStruct(LPCSTR lpszSection, LPCSTR lpszEntry,
BYTE *pbyData, WORD wDataLen)
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);
ASSERT(pbyData != NULL);
CProfileEntry *pEntry = FindProfileEntry(lpszSection, lpszEntry);
if (pEntry && pEntry->wDataLen > 0)
{
memcpy(pbyData, pEntry->pbyData, wDataLen);
return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section containing the entry.
// lpszEntry Points to a null-terminated string that contains the
// entry whose value is to be retrieved.
// pbyData Pointer to the buffer that receives the data associated with section and key names.
//
// wDataLen Specifies the size, in bytes, of the buffer pointed to by the pbyData parameter.
// Return Value:
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
// Remarks:
// Call this member function to copies data into the specified key
// in the given section of the application's .INI file.
BOOL CRTApp::WriteProfileStruct(LPCSTR lpszSection, LPCSTR lpszEntry,
BYTE *pbyData, WORD wDataLen)
{
ASSERT(lpszSection != NULL && *lpszSection != '\0');
ASSERT(lpszEntry != NULL && *lpszEntry != '\0');
if (pbyData == NULL)
return DeleteProfileEntry(lpszSection, lpszEntry);
CProfileSection *pSection = FindProfileSection(lpszSection);
if (pSection == NULL)
{// create new section
pSection = new CProfileSection();
ASSERT(pSection);
pSection->strSection = lpszSection;
// Add to header
pSection->pNext = m_pSectionHeader;
m_pSectionHeader = pSection;
}
CProfileEntry *pEntry = FindProfileEntry(pSection, lpszEntry);
if (pEntry == NULL)
{// create new entry
pEntry = new CProfileEntry();
ASSERT(pEntry);
pEntry->strEntry = lpszEntry;
pEntry->bStructData = TRUE; // This entry hold struct data
// Add to header
pEntry->pNext = pSection->pEntryHeader;
pSection->pEntryHeader = pEntry;
}
// Free previously allocated memory
if (pEntry->pbyData != NULL)
{
delete [] pEntry->pbyData;
pEntry->pbyData = NULL;
}
// New data
pEntry->wDataLen = wDataLen;
pEntry->pbyData = new BYTE[wDataLen + 1];
ASSERT(pEntry->pbyData);
memcpy(pEntry->pbyData, pbyData, wDataLen);
return TRUE;
}
*/
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section containing the entry. If the section does not
// exist, it is created. The name of the section is case
// sensitive; the string may be any combination of
// uppercase and lowercase letters.
// lpszEntry Points to a null-terminated string that contains the
// entry into which the value is to be written. If the
// entry does not exist in the specified section, it is
// created.
// dbValue Contains the value to be written.
// Return Value:
// TRUE if successful; otherwise FALSE.
// Remarks:
// Call this member function to write the specified float number value into
// the specified section of the application's .INI file.
BOOL CRTApp::WriteProfileFloat(LPCSTR lpszSection, LPCSTR lpszEntry, double dbValue)
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);
CString strValue;
strValue.Format("%f", dbValue);
return WriteProfileString(lpszSection, lpszEntry, strValue);
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section containing the entry. If the section does not
// exist, it is created. The name of the section is case
// sensitive; the string may be any combination of
// uppercase and lowercase letters.
// lpszEntry Points to a null-terminated string that contains the
// entry into which the value is to be written. If the
// entry does not exist in the specified section, it is
// created.
// pData Points to the data to be written.
// nBytes Contains the number of bytes to be written.
// Return Value:
// TRUE if successful; otherwise FALSE.
// Remarks:
// Call this member function to write binary data into the specified
// section of the application's .INI file.
BOOL CRTApp::WriteProfileBinary(LPCSTR lpszSection, LPCSTR lpszEntry,
BYTE *pData, UINT nBytes, BYTE uMode)
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);
ASSERT(pData != NULL);
UINT i;
CString strByte, strValue;
switch (uMode)
{
case PROFILE_BINARY_MODE_MAC:
for (i = 0; i < nBytes; i++)
{
strByte.Format("%02X-", *pData++);
strValue += strByte;
}
strValue.TrimRight('-');
break;
case PROFILE_BINARY_MODE_IP:
for (i = 0; i < nBytes; i++)
{
strByte.Format("%d.", *pData++);
strValue += strByte;
}
strValue.TrimRight('.');
break;
case PROFILE_BINARY_MODE_NORMAL:
default:
for (i = 0; i < nBytes; i++)
{
strByte.Format("%02X ", *pData++);
strValue += strByte;
}
strValue.TrimRight();
break;
}
return WriteProfileString(lpszSection, lpszEntry, strValue);
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section containing the entry. The name of the section
// is case sensitive; the string may be any combination
// of uppercase and lowercase letters.
// lpszEntry Points to a null-terminated string that contains the
// entry whose value is to be retrieved.
// pData Points to the buffer to retrieve the data.
// nBytes Contains the number of bytes to retrieve at most.
// Return Value:
// TRUE if successful; otherwise FALSE.
// Remarks:
// Call this member function to retrieve binary data from an entry within
// a specified section of the application's .INI file.
BOOL CRTApp::GetProfileBinary(LPCSTR lpszSection, LPCSTR lpszEntry,
BYTE *pData, UINT nBytes) const
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);
CString strValue = GetProfileString(lpszSection, lpszEntry, NULL);
if (strValue.IsEmpty())
return FALSE;
UINT i;
if (strValue.Find('.') > 0)
{// PROFILE_BINARY_MODE_IP
for (i = 0; i < nBytes; i++)
{
*pData++ = (BYTE)strValue.Toint();
strValue = strValue.Mid(".", NULL);
}
}
else if (strValue.Find('-') > 0)
{// PROFILE_BINARY_MODE_MAC
for (i = 0; i < nBytes; i++)
{
*pData++ = (BYTE)strValue.Tohex();
strValue = strValue.Mid("-", NULL);
}
}
else
{// PROFILE_BINARY_MODE_NORMAL
for (i = 0; i < nBytes; i++)
{
*pData++ = (BYTE)strValue.Tohex();
strValue = strValue.Mid(" ", NULL);
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section. If this parameter is NULL, the whole section
// link table was deleted.
// Return Value:
// TRUE if successful, FALSE if the specified section was not found.
// Remarks:
// Deletes a section from the section link table or the whole link table.
BOOL CRTApp::DeleteProfileSection(LPCSTR lpszSection)
{
if (lpszSection == NULL)
{
if (m_pSectionHeader != NULL)
{// delete the whole profile link table.
delete m_pSectionHeader;
m_pSectionHeader = NULL;
}
return TRUE;
}
CProfileSection *pSection = NULL;
CProfileSection *pNextSec = m_pSectionHeader;
while (pNextSec != NULL)
{
if (pNextSec->strSection == lpszSection)
{
if (pSection != NULL)
{
pSection->pNext = pNextSec->pNext;
}
else
{// it's the section header
m_pSectionHeader = pNextSec->pNext;
}
pNextSec->pNext = NULL; // cut off from the link table
delete pNextSec;
return TRUE;
}
pSection = pNextSec;
pNextSec = pNextSec->pNext;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section.
// lpszEntry Points to a null-terminated string that contains the
// entry.
// Return Value:
// TRUE if successful, FALSE if the specified entry was not found.
// Remarks:
// Deletes an entry from the section-entry link table.
BOOL CRTApp::DeleteProfileEntry(LPCSTR lpszSection, LPCSTR lpszEntry)
{
ASSERT(lpszSection);
ASSERT(lpszEntry);
CProfileSection *pSection = FindProfileSection(lpszSection);
if (pSection != NULL)
{// section found
CProfileEntry *pEntry = NULL;
CProfileEntry *pNextEntry = pSection->pEntryHeader;
while (pNextEntry != NULL)
{
if (pNextEntry->strEntry == lpszEntry)
{
if (pEntry != NULL)
{
pEntry->pNext = pNextEntry->pNext;
}
else
{// it's the entry header
pSection->pEntryHeader = pNextEntry->pNext;
}
pNextEntry->pNext = NULL; // cut off from the link table
delete pNextEntry;
return TRUE;
}
}
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection Points to a null-terminated string that specifies the
// section.
// lpszEntry Points to a null-terminated string that contains the
// entry. If lpszEntry is NULL, then the section rights
// is set.
// nReadRights Access rights for reading it. The value is same as the
// system user's access rights defined in EFCCONTS.H
// nWriteRights Access rights for writing it.
// Return Value:
// TRUE if profile rights was set successful, FALSE if the entry or section
// was not found.
// Remarks:
// Sets the read/write rights of the specified profile entry of section.
BOOL CRTApp::SetProfileRights(LPCSTR lpszSection, LPCSTR lpszEntry,
int nReadRights, int nWriteRights)
{
ASSERT(lpszSection);
CProfileSection *pSection = FindProfileSection(lpszSection);
if (pSection == NULL)
return FALSE; // section does not exist.
if (lpszEntry == NULL)
{// sets the section rights
pSection->nReadRights = nReadRights;
pSection->nWriteRights = nWriteRights;
return TRUE;
}
CProfileEntry *pEntry = FindProfileEntry(pSection, lpszEntry);
if (pEntry != NULL)
{
pEntry->nReadRights = nReadRights;
pEntry->nWriteRights = nWriteRights;
return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// lpszSection The string of the profile section to search for.
// Return Value:
// The pointer of the profile section if found, otherwise NULL.
// Remarks:
// Searches the whole profile link table for the match of a section
CProfileSection *CRTApp::FindProfileSection(LPCSTR lpszSection) const
{
ASSERT(lpszSection);
CProfileSection *pSection = m_pSectionHeader;
while (pSection != NULL)
{
if (pSection->strSection == lpszSection)
break;
pSection = pSection->pNext;
}
return pSection;
}
///////////////////////////////////////////////////////////////////////////////
// Parameters:
// pSection A pointer of the specified profile section.
// lpszEntry The name of the profile entry to search for.
// Return Value:
// The pointer of the profile entry if found, otherwise NULL.
// Remarks:
// Searches the specified profile section for the match of an profile entry.
CProfileEntry *CRTApp::FindProfileEntry(const CProfileSection *pSection,
LPCSTR lpszEntry) const
{
ASSERT(lpszEntry);
if (pSection == NULL)
return NULL;
CProfileEntry *pEntry = pSection->pEntryHeader;
while (pEntry != NULL)
{
if (pEntry->strEntry == lpszEntry)
break;
pEntry = pEntry->pNext;
}
return pEntry;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -