+ Reply to Thread
Results 1 to 2 of 2

Thread: Reading and Writing user object in INI file.

  1. #1

    Reading and Writing user object in INI file.

    Reading and Writing user object in INI file.

  2. #2
    This can be done using
    a. WritePrivateProfileString and
    b. WritePrivateProfileStruct APIs

    Example:

    Code:
    struct CStudent
    {
    	int		m_nRoleID ;
    	char	m_szName[100] ;
    } ;
    
    CStudent objStudent ;
    
    objStudent.m_nRoleID = 1 ;
    strcpy(objStudent.m_szName, "Max") ;
    
    CString strLength ;
    strLength.Format(_T("%d"), sizeof(objStudent)) ;
    
    BOOL bReturn = WritePrivateProfileString("Student", "Length", strLength, "C:\\Student.ini") ;
    if(bReturn)
    {
    	//write bookmark....
    	bReturn = WritePrivateProfileStruct("Student", "Value", &objStudent, sizeof(objStudent), "C:\\Student.ini") ;
    }
    
    
    TCHAR szLength[10] = { 0 } ;
    TCHAR *pBookmarkXml = NULL ;
    
    //find the length of the book mark which is stored last time...
    BOOL bResult = GetPrivateProfileString("Student", "Length",  _T("0"), szLength, 10, "C:\\Student.ini") ;
    if(bResult)
    {
    	int nLength = _ttoi(szLength) ;
    	if(nLength)
    	{
    		CStudent objStudent1 ;
    		//find the actual bookmark XML string....
    		bResult = GetPrivateProfileStruct("Student", "Value", &objStudent1, nLength, "C:\\Student.ini") ;
    	}
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts