![]() |
CXTPPropExchange faq |
Post Reply ![]() |
Author | |
jimmy ![]() Senior Member ![]() Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
![]() ![]() ![]() ![]() ![]() Posted: 27 February 2008 at 7:03am |
Hello,
i use CXTPPropExchange function to save & store some data. static void PropLOS2Data(CXTPPropExchange* pPX, SLOS2Data& ld) { CXTPPropExchangeSection secLD(pPX->GetSection("LOS2Data")); PX_ULong(&secLD, _T("CRC"), ld.dwCRC, 0); PX_ULong(&secLD, _T("LenData"), ld.dwLenData, 0); // ??? PX_CharBuffer(&secLD, _T("PasswordOnline"), ld.szPasswordOnline, ""); } With this function i save/load some data from a struct. DWORD, int values are no problem. #define MAX_PASSWORD 19 struct SLOS2Data { ULONG dwCRC; ULONG dwLenData; char szPassword[MAX_PASSWORD + 1]; } But how can i save/load szPassword ? The szPassword is always \0 terminated. I have wrote this template, but how can i save/load it ? Or is there a other nice solution ? template<class TYPE> BOOL PX_CharBuffer(CXTPPropExchange* pPX, LPCTSTR pszPropName, TYPE& szBuf, LPCTSTR lpDefault) { int iBufSize = sizeof(szBuf); // DWORD nBytes = iBufSize; // return PX_Blob(pPX, pszPropName, szBuf, nBytes); } Jimmy |
|
![]() |
|
jimmy ![]() Senior Member ![]() Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
![]() ![]() ![]() ![]() ![]() |
Is this a correct way ?
template<class TYPE> void CharBufCpy(TYPE& szBuf, const CString& lpText) { int iSize = sizeof(szBuf) - 1; memset(szBuf, 0, iSize + 1); int iLenText = lpText.GetLength(); if (iLenText > iSize) iLenText = iSize; strncpy(szBuf, lpText, iLenText); } template<class TYPE> BOOL PX_CharBuffer(CXTPPropExchange* pPX, LPCTSTR pszPropName, TYPE& szBuf, LPCTSTR lpDefault) { if (pPX->IsStoring()) { CString strVal(szBuf); return PX_String(pPX, pszPropName, strVal); } else { CString strVal; BOOL bOk = PX_String(pPX, pszPropName, strVal, lpDefault); if (bOk) CharBufCpy(szBuf, strVal); return bOk; } } Jimmy |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hi,
Maybe easy to change "char szPassword" to "CString strPassword" in struct ?
:)
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
jimmy ![]() Senior Member ![]() Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
![]() ![]() ![]() ![]() ![]() |
No, because the struct is a binary mapping of a file.
Jimmy |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |