PsycleWTL:Win32 GUI Genericsを使用した再構築

公開:2004-12-29 07:54
更新:2020-02-15 04:36
カテゴリ:psycle wtl,windows,audio,tracker

PsycleWTLはマルチランゲージ対応にしたために、リソースを国別にDLL化してます。WTLではリソースをDLLで供給する場合の仕組みが用意されているので、容易にリソースDLLに対応させることができましたが、Win32 GUI Genericsは、exeにくっついているリソースのみ読みこむようにデザインされています。

これはまずいので、その部分を改造することにしました。
バージョンアップの時の対応が面倒くさいので、あんまりライブラリには手を入れたくないんですが...

どこを改造するかですが、リソースを読み込む際に呼んでいるdefault_instance()の部分をリソースDLLから読み込めるように改造します。

具体的には、リソースDLLのハンドルを保持するSingleton クラスを用意し、リソースを読み込む際にはそのハンドルを使用するようにします。


000312  namespace detail {
000313      class res_handle {
000314      public:
000315          ~res_handle(void);
000316          static res_handle & instance(){
000317              if(m_pres_handle.get() == NULL){
000318                  boost::mutex::scoped_lock _lock(m_mutex);
000319                  if(m_pres_handle.get() == NULL){
000320                      m_pres_handle = std::auto_ptr<res_handle>(new res_handle());
000321                  }
000322              }
000323              return (*m_pres_handle);
000324          }
000325          
000326          operator HINSTANCE() {
000327              return m_handle;
000328          };
000329 
000330      private:
000331          res_handle(){m_handle = default_instance();};
000332          HINSTANCE m_handle;
000333          static std::auto_ptr<res_handle> m_pres_handle;
000334          static boost::mutex m_mutex;
000335      };
000336  };
000337 
000338  inline HINSTANCE resource_instance() { return static_cast<HINSTANCE>(detail::res_handle::instance());};

よく見てみると、ハンドルメンバに代入する部分がないですね。 追加しないと...。