トップ回答者
レイトハンディングでのイベント取得について

質問
-
つい先日こちら
http://social.msdn.microsoft.com/Forums/ja-JP/vcgeneralja/thread/c0e17eb7-a22b-4da5-a737-deb7db214e89
でPowerPointでのイベント取得について教えて頂いたのですが。
また詰まってしまったのでアドバイスして頂きたいです。
上記のリンク先で教えて頂いたbutton2_ClickではOffice2003の場合エラーで終了してしまったので
button3_Clickのようにレイトハンディングというのを見よう見真似で書いてみました。
無事Office2007と2003でpowerpointが起動するようになったのですがbutton2のようにイベントを登録する方法で詰まっています。
なにかわかれば教えて頂きたいです。private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { if(System::IO::File::Exists(textBox2->Text->ToString())){ ppt = gcnew Microsoft::Office::Interop::PowerPoint::Application(); ppt->Visible = Microsoft::Office::Core::MsoTriState::msoTrue; //PowerPointイベント:slideshowstart ppt->SlideShowBegin += gcnew Microsoft::Office::Interop::PowerPoint::EApplication_SlideShowBeginEventHandler(this, &Form1::SlideShowBegin); //PowerPointイベント:slideshowend ppt->SlideShowEnd += gcnew Microsoft::Office::Interop::PowerPoint::EApplication_SlideShowEndEventHandler(this, &Form1::SlideShowEnd); //PowerPointイベント:slideshownextslide ppt->SlideShowNextSlide += gcnew Microsoft::Office::Interop::PowerPoint::EApplication_SlideShowNextSlideEventHandler(this, &Form1::SlideShowNextSlide); ppt->Presentations->Open(textBox2->Text,Microsoft::Office::Core::MsoTriState::msoTrue,Microsoft::Office::Core::MsoTriState::msoTrue,Microsoft::Office::Core::MsoTriState::msoTrue); }else{ MessageBox::Show("ファイルが見つかりません。\r\nもう一度選択してください。","エラー",MessageBoxButtons::OK,MessageBoxIcon::Error); } } private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { //レイトハンディング System::Type^ classType = Type::GetTypeFromProgID("PowerPoint.Application"); System::Object^ ppt = Activator::CreateInstance(classType); array<Object^>^args = {true}; System::Reflection::Binder^ binder; ppt->GetType()->InvokeMember("Visible",System::Reflection::BindingFlags::SetProperty,binder,ppt,args); //イベント取得・・・ }
- 編集済み TARAKO33 2010年12月7日 4:12 変数名が間違っていたので修正しました
回答
すべての返信
-
System::Object^ pptをMicrosoft::Office::Interop::PowerPoint::Application^にdynamic_castしてみてください。
Microsoft::Office::Interop::PowerPoint::Application^ dcppt =
dynamic_cast<Microsoft::Office::Interop::PowerPoint::Application^>(ppt);でしょうか?やってみたのですがバージョンが違うofficeの場合例外エラーがでました
http://www.codeproject.com/KB/cs/zetalatebindingcomevents.aspx
を参考にC++に書き換えてみたんですが
connectionPointContainer.FindConnectionPoint(ref guid, out connectionPoint );
や
// Connect the sink.
int sinkCookie; connectionPoint.Advise ( sink, out sinkCookie );
のref,outの部分のC++での書き方が分からず困っています
なんとかコードを書けましたがイベントが取得できませんでした。
C#でも同様にやってみようと思います
タイトルはレイトバインディングでした・・・すいません
- 編集済み TARAKO33 2010年12月8日 14:48 追記
-
うまくいきませんでしたか。
>C++に書き換えてみた
C++/CLIですよね?C++ならWindows SDKのHeaderに宣言されている通り、引数を渡せばよいです。何れにせよ、ref・outのKeywordは必要ありません。
MSDNを見ると以下のように宣言されています。
void FindConnectionPoint( [InAttribute] Guid% riid, [OutAttribute] IConnectionPoint^% ppCP )
GuidはLocalに宣言したものをそのまま渡せばよいですし、IConnectionPointはIConnectionPoint ^で宣言した変数をそのまま渡してください。 ref・outは必要ありません。%(Tracking Reference)に置き換わっているとお考えください。 C++で言うところの参照(&)だと思えばよいです。
例えば、以下のような書き方になります。(using namespaceやそのMethodをもつClassの記述は省略しています。)
Guid guid("000209FE-0000-0000-C000-000000000046"); IConnectionPoint ^cp; FindConnectionPoint(guid,cp);
>なんとかコードを書けましたがイベントが取得できませんでした。
ここから追記でしょうか。C#に移行するとのことでしょうか。 -
C++/CLIです。すいません。書き方ありがとうございます。
イベントは取得できませんでした。
C#でIConnectionPointを使った
http://support.microsoft.com/kb/308825
があったので確実にできるかと思ってやってみましたがMicrosoft PowerPoint 11.0 Object Library(office2003)を利用したこと
以外はすべて同じで DispIDやGUIdも同じでしたがうまくいきませんでした 。
PowerPointの複数バージョンに対応しイベントを取得する方法はあるのでしょうか?