Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 982507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:42:29+00:00 2026-05-16T04:42:29+00:00

I use VS2008 to develop a excel 2007 add-in, within add-in I want to

  • 0

I use VS2008 to develop a excel 2007 add-in, within add-in I want to use Activation Context API to instantiate a COM class.

The weird thing is I can instantiate the COM class successfully on Window 7, buf fails on Windows XP/2003.

Here’s the code-snippet

  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.
  }

The COM is written in C++ and the manifest looks like:

On Windows 2003/XP, I found that add-in looked for ComViewer.dll in c:\program files\microsoft Office\Office 12 rather than the directory I specified in lpAssemblyDirectory.

Anyone can help? thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:42:30+00:00Added an answer on May 16, 2026 at 4:42 am

    Just figure out that, in XP/2003, Activation Context API doesn’t respect lpAssemblyDirectory if you put COM file info within root manifest that lpSource points to, in this case Windows will only search COM file in the directory that executable resides in.

    The workaround is to create another mainfest that depends on original manifest ComViewer.x.manifest and pass it into lpSource. In above example you may pass in the following manifest:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <dependency>
    <dependentAssembly>
    <assemblyIdentity name="ComViewer.x" >
    </assemblyIdentity>
    </dependentAssembly>
    </dependency>
    </assembly>
    

    Of course you should add element to ComViewer.x.manifest as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a class within a T4 template in VS2008. Here is
I'm using VS2008 to develop my ASP.NET web site, I know how to use
We are attempting to use VS2008 Class Designer for a UML-like class diagram. However,
I tried to implement a singleton class in the following way (I use VS2008
I use VS2008 targetting .NET 2.0 Framework, and, just in case, no I can't
I am forced to use VS2008 for the bulk of my projects at work,
I'd like to use vs2008 to edit sitecore's xslt it is a regular xslt
I use the VS2008 command prompt for builds, TFS access etc. and the cygwin
can I use .net framework 4.0 in VS2008 ? If yes how can I
I'd like to use the Object Test Bench in VS2008. The docs - and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.