2013年6月26日水曜日

システムプロファイルの言語を取得:IWMProfileManagerLanguage::GetUserLanguageID

To Load a System Profile

/*
空の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;

 IWMProfileManagerLanguage* pProfileMgrLang = NULL;

 // Create a profile manager object.
 // プロファイルマネージャオブジェクトを作成します。
 hr = WMCreateProfileManager(&pProfileMgr);
 if(FAILED(hr))
 {
  printf("Could not create a profile manager object.");
  return 0;
 }

 // Get the profile manager language interface.
 // 言語インターフェイスプロファイルマネージャーの取得
 pProfileMgr->QueryInterface(IID_IWMProfileManagerLanguage, (void**)&pProfileMgrLang);

 if(FAILED(hr))
 {
  printf("Couldn't get IWMProfileManagerLanguage.\n");
  SAFE_RELEASE(pProfileMgrLang);
  return hr;
 }

 // Retrieve the current language (as a LANGID value)
 // 現在の言語を取得
 WORD wLangID = 0;
 hr = pProfileMgrLang->GetUserLanguageID(&wLangID);
 if(FAILED(hr))
 {
  printf("Could not get the current language.\n");
  SAFE_RELEASE(pProfileMgrLang);
  return hr;
 }

 printf("The current language ID is 0x%X\n", wLangID);//English – United States (0x0409)


 SAFE_RELEASE(pProfileMgrLang);

 printf("-------------プログラム終了----------------");

 Console::ReadLine();//入力待-ウインドウ維持
}


0 件のコメント:

コメントを投稿