Click here to Skip to main content
Licence CPOL
First Posted 7 Mar 2009
Views 14,148
Downloads 1,297
Bookmarked 23 times

CFileProperty - Class Used To Read File Properties, Such as ID3 Tag and so on

By | 7 Mar 2009 | Article
CFileProperty can be used in MFC or ATL projects, helps to read file properties

2.png

Introduction

CFileProperty exposes simple methods to read the file properties, i.e. MP3 ID3 tags and so on.

Using the Code

Copy FileProperty.h and FileProperty.cpp into your project.

You may need to append some includes in the stdafx.h:

#include <map>
#include <NTQuery.h>
#include <shlwapi.h>
#include <ShlGuid.h>
#include <shlobj.h>
#include <shobjidl.h>
#pragma comment( lib, "shlwapi.lib") 

The tiny class is very simple to use. Here is the sample code:

CFileProperty oFileProperty;
if( oFileProperty.LoadFromFile(_T("C:\\1.mp3") )
{                                                   
	// Get information for music file               
	tagFilePropMusicInfo stMusicInfo = {0};      
	oFileProperty.GetMusicInformation(stMusicInfo);
	                                                   
	// TO DO: read information stored in stMusicInfo
	// ......                                   

	// Retrieve a specific property
	LPCTSTR lpszTitle = oFileProperty.GetProperty
			( FMTID_SummaryInformation, PIDSI_TITLE);

	// The code below demonstrates how to enumerate all properties,
	// but you'd better get the property by give FMTID and PID 
	std::map<CString, std::map<DWORD, CString> >::iterator iter1;
	iter1 = oFileProperty.m_mpProperties.begin();    
	for( ; iter1 != oFileProperty.m_mpProperties.end(); iter1++)   
	{                                                        
		std::map<DWORD, CString> & mpProperty = iter1->second;
		std::map<DWORD, CString>::iterator iter2;
		iter2 = mpProperty.begin();   
		for( ; iter2 != mpProperty.end(); iter2++)   
		{
			m_strInfo.AppendFormat( _T("\r\n%s %08ld %s")
				, iter1->first
				, iter2->first
				, iter2->second.IsEmpty() ? 
						_T("<NULL>") : iter2->second
				);
		}
	}
} 

FMTID

A property set is identified with a format identifier (FMTID). Listed below are some FMTIDs for your reference.

FMTID Memo
FMTID_Storage Storage property set
FMTID_ImageProperties Image property set 
FMTID_CustomImageProperties Custom image property set
FMTID_Displaced Displaced property set
FMTID_Briefcase Briefcase property set 
FMTID_Misc Miscellaneous property set
FMTID_WebView Web property set 
FMTID_MUSIC Music property set 
FMTID_DRM Digital Rights Management property set
FMTID_Volume Volume property set 
FMTID_Query Query property set 
FMTID_SummaryInformation Summary information property set.
FMTID_DocSummaryInformation Summary information property set
FMTID_UserDefinedProperties User defined property set 
FMTID_DiscardableInformation
FMTID_ImageSummaryInformation Summary information property set
FMTID_AudioSummaryInformation Image summary information property set
FMTID_VideoSummaryInformation Video summary information property set
FMTID_MediaFileSummaryInformation Media file summary information property set
FMTID_FileAttributes 

History

  • 8th March, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jerry.Wang

Architect
Best Brain
China China

Member

Jerry is working for the Best Brain ChangSha Office, China. He has been being interested in computer programing from his childhood. Skilled in Windows/Linux C++, Mac OS Objective-C, .Net & C#, ASP.Net, AS3/JS/PHP etc.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionit only works on window based app Pinmemberdunniu15:54 2 May '12  
QuestionDoes not work!!!!!!!!!!!!!! Pinmembergpsm198922:44 21 Feb '12  
QuestionVisual Studio Conversion wizard error PinmemberAnandi.VC1:46 16 Sep '11  
AnswerOn Vista it hangs (Fix) Pinmemberrazvar1:03 11 Nov '09  
GeneralRe: On Vista it hangs (Fix) PinmemberJerry.Wang0:59 15 Nov '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 8 Mar 2009
Article Copyright 2009 by Jerry.Wang
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid