Make your own free website on
FAQ : CRegistry+CRegistrySerialize:

Home| Main Subjects| Documentation| Downloads| Misscelaneous| FAQ| Search
Email me
Amir Israeli October 2000  FAQ : CRegistry+CRegistrySerialize:

This page will contain questions (and answers) that were mailed to me
If you have any question Amir Israeli

Q: How to write a value of CTime ?
How to write a value of any type that is not directly supported?
A: It depends which class you use for saving/loading your data , if you use CRegistry you have pair of functions
BOOL GetValueSized( LPCTSTR lpszRegPath, LPCTSTR lpszValueName,LPVOID pData,size_t size);
BOOL SetValue( LPCTSTR lpszRegPath, LPCTSTR lpszValueName,LPVOID pData ,size_t size = 0,DWORD dwType=REG_BINARY);
The first function gets a value named "lpszValueName" from path "lpszRegPath" you set the pointer of target in LPVOID and the size of target in size.
examples : saving a double (only float supported)

double d;
LPCTSTR lpszValue = _T("MyData"); //getting some data
if (GetValueSized( lpszPath, lpszValue, &d, sizeof(double))) {
	//value was got into variable 'd'
	//do something ...
else { //some error

The same is with using CTime (based on time_t)
//getting from same path on another key ...

CTime t = CTime::GetCurrentTime()
if (GetValueSized( lpszPath, _T("SomeTimeValue"), &t, sizeof(CTime))) {
	//value was got into variable 't'
	//do something ...
NOTICE !! you must NOT use this method with any class that contains pointers , such as CString (instead use LPCTSTR) , because this function simply copies the memory representation of an object . and you there's a pointer only its' address will be copied and not the contents where it points (You will have to serialize the pointer with the same
GetValueSized( ... ,sizeof(the data that the pointer holds) )
(uses CopyMemory) CopyMemory is good as long as you know what you placed in that value : for example : in Win32 both int and DWORD takes 4 bytes , saving an intof value -1000 , and acquire a DWORD from that value will return a very big number (almost MAXDWORD)
you use the 'REGTIME' const and you use time_t variable to get the value (you also can load CTime as plain binary (if you look into the source files of MFC you see that CTime is just time_t variable wrapped in a class, with some data access and manipulation functions. (COleDateTime implements a wider range of times you use it as a binary data type : it include a float value type 'DATE' , and some status stuctures.)
Creating the map :
BOOL InsertPath( _T("path to that item"),TRUE);
BOOL InsertValue( NULL, _T("MyTimeValue"), //NULL=use current path
Persisting the data:
CTime  myTime = CTime::GetCurrentTime();
BOOL Path(_T("path to that item"));
BOOL Value( _T("MyTimeValue"), &myTime, TRUE); //or FALSE for saving
Ok because CTime==time_t!
More explicit way :
time_t tmpTime_t = myTime.GetTime();
BOOL Path(_T("path to that item"));
BOOL Value( _T("MyTimeValue"), &tmpTime_t, TRUE); //or FALSE for saving

Q: CRegistry::IsExistValue BUG
Corrected in Last update August 25. (using Query...)

Home  |  Links  |  About