RukeとLuNaYuの日記
I know the truth.
I know whole.
And I...know you.
平凡な大学生活の日記です。時折まじめな長文を書く病気になります。興味がなければ読み飛ばしてください。
201706 << 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 >> 201708
スポンサーサイト (--/--/--(--) --:--:--)
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。
アイチューンズゾク (2006/06/01(木) 04:21:48)
整理していたらむしろ参考にしたサイトからのコピペに戻った。進展なし。とりあえずプリコンパイルヘッダを止めて一ファイルにしたので以下のC++ソースでATLが使える環境でコンパイルすればそれらしきものができるはず。

中途半端に動作するんだよな。
//Windowsのバージョン
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define _WIN32_WINDOWS 0x0410
#define _WIN32_IE 0x0600
//ATL
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 一部の CString コンストラクタは明示的です。
#include <atlbase.h>
#include <atlstr.h>
#include <atlcom.h>
CComModule _Module;
//その他
#define WIN32_LEAN_AND_MEAN // Windows ヘッダーから使用されていない部分を除外します。
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <conio.h>
// iTunes
#undef GetFreeSpace
#import "c:\program files\itunes\itunes.exe" named_guids

/*CComInitializer : COM初期化クラス*/
class CComInitializer {
bool initialized_;

public:
CComInitializer() : initialized_(false) { }
HRESULT init() {
HRESULT hr;
hr = ::CoInitialize(NULL);
if ( initialized_ = SUCCEEDED(hr) )
_Module.Init(NULL, ::GetModuleHandle(NULL));
return hr;
}

~CComInitializer() {
if ( initialized_ ) {
_Module.Term();
::CoUninitialize();
}
}
};
/*com_assert : エラーチェックと例外送出*/
void com_assert(HRESULT result, const std::string& msg) {
if ( FAILED(result) )
throw std::runtime_error(msg);
}

#define SINKID_iTunesEvents 0

/* iTunesEvents : シンク(イベント受付窓口)クラス */
class ATL_NO_VTABLE iTunesEvents :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispEventImpl<SINKID_iTunesEvents, iTunesEvents,
&iTunesLib::DIID__IiTunesEvents,&iTunesLib::LIBID_iTunesLib, 1, 7>
{
public:
iTunesEvents() {}
BEGIN_COM_MAP(iTunesEvents)
COM_INTERFACE_ENTRY_IID(iTunesLib::DIID__IiTunesEvents, iTunesEvents)
END_COM_MAP()

BEGIN_SINK_MAP(iTunesEvents)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventDatabaseChanged,&handle_OnDatabaseChangedEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventPlayerPlay,&handle_OnPlayerPlayEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventPlayerStop,&handle_OnPlayerStopEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventPlayerPlayingTrackChanged,&handle_OnPlayerPlayingTrackChangedEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventUserInterfaceEnabled,&handle_OnUserInterfaceEnabledEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventCOMCallsDisabled,&handle_OnCOMCallsDisabledEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventCOMCallsEnabled,&handle_OnCOMCallsEnabledEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventQuitting,&handle_OnQuittingEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventAboutToPromptUserToQuit,&handle_OnAboutToPromptUserToQuitEvent)
SINK_ENTRY_EX(SINKID_iTunesEvents, iTunesLib::DIID__IiTunesEvents,iTunesLib::ITEventSoundVolumeChanged,&handle_OnSoundVolumeChangedEvent)
END_SINK_MAP()

virtual void OnDatabaseChangedEvent(VARIANT deletedObjectIDs,VARIANT changedObjectIDs)=0;
HRESULT _stdcall handle_OnDatabaseChangedEvent(VARIANT deletedObjectIDs,VARIANT changedObjectIDs){OnDatabaseChangedEvent(deletedObjectIDs,changedObjectIDs);return S_OK;}

virtual void OnPlayerPlayEvent(VARIANT iTrack)=0;
HRESULT _stdcall handle_OnPlayerPlayEvent(VARIANT iTrack){OnPlayerPlayEvent(iTrack);return S_OK;}

virtual void OnPlayerStopEvent(VARIANT iTrack)=0;
HRESULT _stdcall handle_OnPlayerStopEvent(VARIANT iTrack){OnPlayerStopEvent(iTrack);return S_OK;}

virtual void OnPlayerPlayingTrackChangedEvent (VARIANT iTrack)=0;
HRESULT _stdcall handle_OnPlayerPlayingTrackChangedEvent(VARIANT iTrack){OnPlayerPlayingTrackChangedEvent(iTrack);return S_OK;}

virtual void OnUserInterfaceEnabledEvent ()=0;
HRESULT _stdcall handle_OnUserInterfaceEnabledEvent(){OnUserInterfaceEnabledEvent();return S_OK;}

virtual void OnCOMCallsDisabledEvent (iTunesLib::ITCOMDisabledReason reason)=0;
HRESULT _stdcall handle_OnCOMCallsDisabledEvent (iTunesLib::ITCOMDisabledReason reason){OnCOMCallsDisabledEvent(reason);return S_OK;}

virtual void OnCOMCallsEnabledEvent()=0;
HRESULT _stdcall handle_OnCOMCallsEnabledEvent(){OnCOMCallsEnabledEvent();return S_OK;}

virtual void OnQuittingEvent()=0;
HRESULT _stdcall handle_OnQuittingEvent(){OnQuittingEvent();return S_OK;}

virtual void OnAboutToPromptUserToQuitEvent()=0;
HRESULT _stdcall handle_OnAboutToPromptUserToQuitEvent(){OnAboutToPromptUserToQuitEvent();return S_OK;}

virtual void OnSoundVolumeChangedEvent(long newVolume)=0;
HRESULT _stdcall handle_OnSoundVolumeChangedEvent(long newVolume){OnSoundVolumeChangedEvent(newVolume);return S_OK;}

};


/*myiTunesEvents : 実際のイベントハンドラ*/
class myiTunesEvents : public iTunesEvents {
void OnDatabaseChangedEvent(VARIANT deletedObjectIDs,VARIANT changedObjectIDs){
std::cout<<"DatabaseChanged is fired.\n";
std::cout.flush();
};
void OnPlayerPlayEvent(VARIANT iTrack) {
std::cout<<"PlayerPlay is fired.\n";
std::cout.flush();
}
void OnPlayerStopEvent(VARIANT iTrack) {
std::cout<<"PlayerStop is fired.\n";
std::cout.flush();
}
void OnPlayerPlayingTrackChangedEvent (VARIANT iTrack){
std::cout<<"PlayerPlayingTrackChange is fired.\n";
std::cout.flush();
};
void OnUserInterfaceEnabledEvent(){
std::cout<<"UserInterfaceEnabled is fired.\n";
std::cout.flush();
};
void OnCOMCallsDisabledEvent (iTunesLib::ITCOMDisabledReason reason){
std::cout<<"ComCallsDisabled is fired.\n";
std::cout.flush();
};
void OnCOMCallsEnabledEvent(){
std::cout<<"ComCallsEnabled is fired.\n";
std::cout.flush();
};
void OnQuittingEvent(){
std::cout<<"Quitting is fired.\n";
std::cout.flush();
};
void OnAboutToPromptUserToQuitEvent(){
std::cout<<"AboutToPromptUserToQuit is fired.\n";
std::cout.flush();
};
void OnSoundVolumeChangedEvent(long newVolume){
std::cout<<"SoundVolumeChanged is fired.\n";
std::cout.flush();
};
};

/* ecom_event_sink : シンクラッパー*/
template<class Event>
class com_event_sink {
typedef CComObject<Event> com_object_type;
com_object_type* sink_;
CComPtr<IUnknown> unk_;
public:
HRESULT create() {
HRESULT hr = com_object_type::CreateInstance(&sink_);
if ( SUCCEEDED(hr) )
sink_->QueryInterface(IID_IUnknown,(void**)&unk_);
return hr;
}
com_object_type* operator->() {
return sink_;
}
};

int main() {
try {
HRESULT hr;
CComInitializer com;
hr = com.init();
com_assert(hr, "CoInitialize failed");
// iTunesオブジェクトの生成
CComPtr<iTunesLib::IiTunes> iTunes;
hr = iTunes.CoCreateInstance(iTunesLib::CLSID_iTunesApp);
com_assert(hr, "Creation of iTunesAppClass failed");
// イベントハンドラの生成
com_event_sink<myiTunesEvents> sink;
hr = sink.create();
com_assert(hr,"CCI Event sink failed");
// 接続
hr = sink->DispEventAdvise(iTunes);
com_assert(hr, "DispEventAdvise failed");
while(1){
//入力を待って各種処理
std::cout << "x:quit current iTunes, q:exit this program, spacebar: play/pause, b:back track, n:next track, m:toggle visibility of browser window.\n";
char inputchar=_getch();
if(inputchar=='x'){
iTunes->Quit();
}else if(inputchar=='q'){
break;
}else if(inputchar==' '){
iTunes->PlayPause();
}else if(inputchar=='b'){
iTunes->BackTrack();
}else if(inputchar=='n'){
iTunes->NextTrack();
}else if(inputchar=='m'){
if(iTunes->BrowserWindow->Minimized==VARIANT_TRUE){
iTunes->BrowserWindow->Minimized=VARIANT_FALSE;
}else{
iTunes->BrowserWindow->Minimized=VARIANT_TRUE;
}
}
}
// 解放
hr = sink->DispEventUnadvise(iTunes);
com_assert(hr, "DispEventUnadvise failed");
} catch ( std::exception& ex ) {
std::cout << ex.what() << std::endl;
return -1;
}
return 0;
}
スポンサーサイト
コメント
この記事へのコメント
管理人のみ閲覧できます
2008/05/30(金) 20:05:08 || | #[ 編集]
このコメントは管理人のみ閲覧できます
Lorinda Marks
2008/06/02(月) 12:23:25 |Lupe Hancock|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.themystic.org/ >The Mystic</a>
http://www.middleburgonline.com/maidstone/maidstone.html

Maurice Silva
2008/06/03(火) 14:52:23 |Emil Haynes|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.nepalmountain.com/ >Nepal Mountain Trekking & Expedition</a>
http://www.avonlakeschools.com/

Sue Nieves
2008/06/04(水) 03:49:15 |Liz Bauer|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.odysseypavilion.com/ >Odyssey Pavilion</a>
http://www.pitchforkmedia.com/article/record_review/18739

Deloris Hendrix
2008/06/08(日) 07:40:44 |Sterling Wynn|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://en.wikipedia.org/wiki/Amish_school_shooting >Wikipedia: Amish School Shooting</a>
http://www.hermitagemuseum.org/html_En/03/hm3_6.html

Babette Bridges
2008/06/12(木) 02:28:35 |Linwood Head|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.elmbridge-online.co.uk/ >Elmbridge Online</a>
http://www.intellyweb.com/

Howard Clayton
2008/06/12(木) 17:30:20 |Jeanette Rojas|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://anewyou.net >A New You Plastic Surgery and Laser Center</a>
http://www.callsymon.com

Benny Salas
2008/06/16(月) 05:54:44 |Scott Richmond|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.originalstyle.co.uk/ >Original Style</a>
http://www.fugatefordmotors.com

Sabrina Navarro
2008/06/19(木) 22:07:42 |Zachary Lang|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.geocities.com/sandgroper_chimbu/ >Sandgroper's Avatar MUD Page</a>
http://www.angelfire.com/or2/ashlysworldofwonders/medicallinks.html

Rodrigo Davidson
2008/06/22(日) 06:39:13 |Baron Howe|URL | #-[ 編集]
becomingness subhedral corrector intrabred quatertenses uranin dihalo methought
<a href= http://www.tndirectory.com/foutch/ >Foutch Distributing Company</a>
http://cnn.com/2002/TECH/science/05/21/new.iceberg.ap/index.html

コメントを投稿する

管理者にだけ表示を許可する
トラックバック
この記事のトラックバックURL
この記事へのトラックバック
(C)Copyright 2003-2007 by Ruke All rights reserved. Powered By FC2. VALID HTML? VALID CSS?
上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。