参考:To Retrieve All Metadata in a File
IWMHeaderInfo3::GetAttributeByIndexEx method
ID3 Tag Support
#include <stdio.h> //printf とかで必要
#include <wmsdk.h> //HRESULT とかで必要
using namespace System;//Console::ReadLine()で必要
#pragma comment(lib, "wmvcore.lib") //IWMMetadataEditor とかで必要
#ifndef GOTO_EXIT_IF_FAILED
#define GOTO_EXIT_IF_FAILED(hr) if(FAILED(hr)) goto Exit;
#endif
#ifndef SAFE_ARRAY_DELETE
#define SAFE_ARRAY_DELETE(x) \
if(x != NULL) \
{ \
delete[] x; \
x = NULL; \
}
#endif
void main(){
HRESULT hr = S_OK;
IWMMetadataEditor * pEditor = NULL;
IWMHeaderInfo3 * pHeaderInfo = NULL;
hr = WMCreateEditor(&pEditor);
hr = pEditor->Open(L"G:\\sampleMovie\\Amanda.wma");
hr = pEditor->QueryInterface(IID_IWMHeaderInfo, (void**) &pHeaderInfo);
WORD cAttributes = 0;
WCHAR* pwszName = NULL;
WORD cchName = 0;
BYTE* pbValue = NULL;
DWORD cbValue = 0;
WORD langIndex = 0;
WORD attIndex = 0;
WMT_ATTR_DATATYPE attType;
// Get the total number of attributes in the file.
//ファイルの属性の総数を取得します。
hr = pHeaderInfo->GetAttributeCountEx(0xFFFF, &cAttributes);
GOTO_EXIT_IF_FAILED(hr);
// Loop through all the attributes, retrieving and displaying each.
//すべての属性をループし取得表示
for(attIndex = 0; attIndex < cAttributes; attIndex++)
{
//printf("%d 回目\r\n ", attIndex);
// Get the required buffer lengths for the name and value.
//名前と値のために必要なバッファ長を取得します。
hr = pHeaderInfo->GetAttributeByIndexEx(0xFFFF,
attIndex,
NULL,
&cchName,
NULL,
NULL,
NULL,
&cbValue);
GOTO_EXIT_IF_FAILED(hr);
// Allocate the buffers.
//バッファを割り当てる。属性名
pwszName = new WCHAR[cchName];
//WCHAR *pbValue = (WCHAR *) new BYTE[ cbValue ];
//pwszName = (WCHAR *) new BYTE[ cchName ];
if(pwszName == NULL)
{
printf("割り当て失敗\r\n");
hr = E_OUTOFMEMORY;
goto Exit;
}
////属性の値
pbValue = new BYTE[cbValue];
if(pbValue == NULL)
{
printf("割り当て失敗\r\n");
hr = E_OUTOFMEMORY;
goto Exit;
}
////属性を取得します。
hr = pHeaderInfo->GetAttributeByIndexEx(0xFFFF,
attIndex,
pwszName,
&cchName,
&attType,
&langIndex,
pbValue,
&cbValue);
GOTO_EXIT_IF_FAILED(hr);
// Display the attribute global index and name.
//表示 属性のグローバルインデックスと名前
printf("%3d - %S (Language %d):\n\t ", attIndex, pwszName, langIndex);
// Display the attribute depending upon type.
// 属性のタイプ別に表示
switch(attType)
{
case WMT_TYPE_DWORD:
case WMT_TYPE_QWORD:
case WMT_TYPE_WORD:
printf("%d\n\n", (DWORD) *pbValue);
break;
case WMT_TYPE_STRING:
printf("%S\n\n", (WCHAR*) pbValue);
break;
case WMT_TYPE_BINARY:
printf("<binary value>\n\n");
break;
case WMT_TYPE_BOOL:
printf("%s\n\n", ((BOOL) *pbValue == TRUE) ? "True" : "False");
break;
case WMT_TYPE_GUID:
printf("<GUID value>\n\n", (DWORD) *pbValue);
break;
}
// Release allocated memory for the next pass.
//次のために、割り当てられたメモリを解放
SAFE_ARRAY_DELETE(pwszName);
SAFE_ARRAY_DELETE(pbValue);
cchName = 0;
cbValue = 0;
}// for ループ終了
Exit:
SAFE_ARRAY_DELETE(pwszName);
SAFE_ARRAY_DELETE(pbValue);
Console::ReadLine();//入力待-ウインドウ維持
return ;
}

0 件のコメント:
コメントを投稿