⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listmetadata.cpp

📁 这是一个控制台程序
💻 CPP
字号:
// ListMetadata.cpp : Defines the entry point for the console application.
//
/**
 ** Copyright (C) 2005 EnjoyView Inc., all rights reserved.
 **           Your View, Our Passion. Just Enjoy It!
 **
 **            http://spaces.msn.com/members/jemylu
 **
 **/

/*************************************************************************/

#include "stdafx.h"
#include "wmsdk.h"

//////////////////////////////////////////////////////////////////////////////
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
   if (x != NULL)       \
   {                    \
      x->Release();     \
      x = NULL;         \
   }
#endif

#ifndef SAFE_ARRAY_DELETE
#define SAFE_ARRAY_DELETE(x) \
   if (x != NULL)            \
   {                         \
      delete[] x;            \
      x = NULL;              \
   }
#endif
//////////////////////////////////////////////////////////////////////////////

void Usage()
{
    printf("Usage: ListMetadata\t <filename>\n");
}

void ShowAllAttributes(IWMHeaderInfo3* pHeaderInfo)
{    
	WORD    count       = 0;
	WCHAR*  pwszName    = NULL;
	WORD    length      = 0;
	BYTE*   pbValue     = NULL;
	DWORD   cbValue     = 0;
	WORD    langIndex   = 0; 
	WMT_ATTR_DATATYPE attType;

	HRESULT hr = pHeaderInfo->GetAttributeCountEx(0xFFFF, &count);
	printf("Total Count: \t%d\n", count);
	for (WORD index = 0; index < count; index++)
	{
		// First call, to retrieve the buffer length
		hr = pHeaderInfo->GetAttributeByIndexEx(0xFFFF,
												index,
												NULL,
												&length,
												NULL,
												NULL,
												NULL,
												&cbValue);     
		pwszName = new WCHAR[length];
		pbValue  = new BYTE[cbValue];
		if (pwszName == NULL || pbValue == NULL)
		{
			break;
		}

		// Second call, to retrieve the name string and value
		hr = pHeaderInfo->GetAttributeByIndexEx(0xFFFF,
												index,
												pwszName,
												&length,
												&attType,
												&langIndex,
												pbValue,
												&cbValue);		
		printf("%2d - %S (Language %d):\t ", index, pwszName, langIndex);

		// Display the attribute depending upon type
		switch (attType)
		{
		case WMT_TYPE_DWORD:
			printf("%d\n", *((DWORD*) pbValue));
			break;
		case WMT_TYPE_QWORD:
			printf("%I64u\n", *((QWORD*) pbValue));
			break;
		case WMT_TYPE_WORD:
			printf("%d\n", *((WORD*) pbValue));
			break;
		case WMT_TYPE_STRING:
			printf("%S\n", (WCHAR*) pbValue);
			break;
		case WMT_TYPE_BINARY:
			{
				printf("<binary value>0x");
				for (DWORD i = 0; i < cbValue; i++)
				{
					printf("%x", pbValue[i]);
				}
				printf("\n");
				break;
			}
		case WMT_TYPE_BOOL:
			printf("%s\n", (*((BOOL*)pbValue) == TRUE) ? "True" : "False");
			break;
		case WMT_TYPE_GUID:
			{
				WCHAR szGuid[100];
				if (StringFromGUID2(*(GUID *)pbValue, szGuid, 100))
				{
					printf("<GUID value> %S\n", szGuid);
				}
				else
				{
					printf("<GUID value> ERROR\n");
				}	
				break;
			}
		}

		SAFE_ARRAY_DELETE(pwszName);
		SAFE_ARRAY_DELETE(pbValue);
		length  = 0;
		cbValue = 0;
	}

	SAFE_ARRAY_DELETE(pwszName);
	SAFE_ARRAY_DELETE(pbValue);
}

int main(int argc, char* argv[])
{
	HRESULT hr = S_OK;
	IWMMetadataEditor * pEditor   = NULL; 
	IWMHeaderInfo3 * pHeaderInfo3 = NULL;

	if (argc < 2)
    {
        Usage();
        goto Exit;
    }

	CoInitialize(NULL);
	
	hr = WMCreateEditor(&pEditor);
	if (SUCCEEDED(hr))
	{
		// Open the specified asf file
		WCHAR wszFile[MAX_PATH];
		MultiByteToWideChar(CP_ACP, 0, argv[1], -1, wszFile, MAX_PATH);
		hr = pEditor->Open(wszFile);
		if (FAILED(hr))
		{
			printf("Could not open the file %s ( hr=0x%08x ).\n", argv[1], hr);
			SAFE_RELEASE(pEditor);
			return 0;
		}
		
		// Get IWMHeaderInfo3 interface from the metadata editor
		hr = pEditor->QueryInterface(IID_IWMHeaderInfo3, (void **)&pHeaderInfo3);
		if (SUCCEEDED(hr))
		{
			ShowAllAttributes(pHeaderInfo3);
		}
	}

	SAFE_RELEASE(pEditor);
	SAFE_RELEASE(pHeaderInfo3);
	CoUninitialize();

Exit:
	MessageBox(NULL, "Running ternimated.", "ListMetadata", MB_OK);

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -