2013年6月26日水曜日

システムプロファイルの数を取得:IWMProfileManager::GetSystemProfileCount


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
空のCLRプロジェクト
*/
 
#include <stdio.h>  //printf とかで必要
#include <wmsdk.h>  //HRESULT とかで必要
 
#pragma comment(lib, "wmvcore.lib")   //IWMMetadataEditor とかで必要
#pragma comment ( lib, "ole32.lib" )//CoInitialize で必要
 
using namespace System;//Console::ReadLine()で必要
 
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
 if(x != NULL)        \
{                    \
 x->Release();     \
 x = NULL;         \
}
#endif
 
int main(void)
{
 
 HRESULT hr = S_OK;
 
 IWMProfileManager*  pProfileMgr  = NULL;
 IWMProfileManager2* pProfileMgr2 = NULL;
 
 WMT_VERSION         profileVersion;
 
 
 // Create a profile manager object.
 // プロファイルマネージャオブジェクトを作成します。
 hr = WMCreateProfileManager(&pProfileMgr);
 if(FAILED(hr))
 {
  printf("Could not create a profile manager object.");
  return 0;
 }
 
 // Get the IWMProfileManager2 interface.
 // IWMProfileManager2インタフェースを取得します。
 hr = pProfileMgr->QueryInterface(IID_IWMProfileManager2,
  (void**) &pProfileMgr2);
 if(FAILED(hr))
 {
  printf("Could not get the IWMProfileManager2 interface.");
  SAFE_RELEASE(pProfileMgr);
  return 0;
 }
 
 // Release the old interface.
 // 古いインターフェースを解放します。
 SAFE_RELEASE(pProfileMgr);
 
 
 // Set the system profile version to 8.
 // システムプロファイルをバージョン8に設定
 profileVersion = WMT_VER_8_0;
 
 hr = pProfileMgr2->SetSystemProfileVersion(profileVersion);
 if(FAILED(hr))
 {
  printf("Could not change profile version.");
  printf("\nError code: 0x%X\n", hr);
  SAFE_RELEASE(pProfileMgr2);
  return 0;
 }
 
 //------------------------------------------------------------------------------
 DWORD profileCount = 0;
 DWORD length = 0;
// char szName[256];
// char szDesc[256];
 // システムプロファイルの数を取得
 hr = pProfileMgr2->GetSystemProfileCount(&profileCount);
 printf("*** Total Count: %d ***\n", profileCount);
 
 for (int i = 0; i < (int)profileCount; ++i)
 {
  printf(" --------- No: %d -----------------\r\n", i);
  IWMProfile * pProfile = NULL;
  hr = pProfileMgr2->LoadSystemProfile(i, &pProfile);
  if (FAILED(hr))
  {
   printf("%2d: Failed to Load System Profile!hr=0x%x\n", i, hr);
   return FALSE;
  }
  hr = pProfile->GetName(NULL, &length);
  WCHAR *wszName = new WCHAR[length + 1];
  hr = pProfile->GetName(wszName, &length);
  //WideCharToMultiByte(CP_ACP, 0, wszName, -1, szName,256, NULL, NULL);
  printf("neme:%S\r\n", wszName);
 
  // Profile
  hr = pProfile->GetDescription(NULL, &length);
  WCHAR *wszDesc = new WCHAR[length + 1];
  hr = pProfile->GetDescription(wszDesc, &length);
  printf("Profile:%S\r\n", wszDesc);
  //WideCharToMultiByte(CP_ACP, 0, wszDesc, -1, szDesc, 256,NULL, NULL);
 
 }
 
 printf("-------------プログラム終了----------------");
 
 
 Console::ReadLine();//入力待-ウインドウ維持
}


0 件のコメント:

コメントを投稿