私は VS2008 を使用して Excel 2007 アドインを開発しています。アドイン内でアクティベーション コンテキスト API を使用して COM クラスをインスタンス化したいと考えています。
奇妙なことに、Windows 7 では COM クラスを正常にインスタンス化できますが、Windows XP/2003 では buf が失敗します。
ここにコードスニペットがあります
  string codeBase = this.GetType().Assembly.CodeBase;
  string asmFullPath = new Uri(codeBase).LocalPath;
  string comAssemblyPath = Path.GetDirectoryName(asmFullPath);
  ACTCTX ac = new ACTCTX();
  ac.cbSize = Marshal.SizeOf(typeof(ACTCTX));
  ac.lpAssemblyDirectory = comAssemblyPath;
  ac.lpSource = Path.Combine(comAssemblyPath, "ComViewer.x.manifest");
  ac.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
  IntPtr cookie;
  IntPtr hActCtx = CreateActCtxW(ref ac);
  if (ActivateActCtx(hActCtx, out cookie))
  {
    try
    {
      //instantiate COM class
      IComViewer = new ComViewerClass();
    }
    finally
    {
      DeactivateActCtx(0, cookie);
    }
  }
  else
  {
    //TODO: Error message.
  }
COM は C++ で記述されており、マニフェストは次のようになります。
Windows 2003/XP では、アドインが lpAssemblyDirectory で指定したディレクトリではなく、c:\program files\microsoft Office\Office 12 で ComViewer.dll を検索することがわかりました。
誰でも助けることができますか?前もって感謝します。