vsto - Couldn't use Activation Context API from within Excel 2007 Add-in on Windows XP/2003? -


I use VS2008 to develop an Excel 2007 add-in, within the add-in I activate the reference API I want to use COM class

The strange thing is that I can successfully install the COM class on Windows 7 / XP, buf fails on Windows XP / 2003.

Here is the code snippet

string codebase = this.GetType (). Assembly.CodeBase; String asmFullPath = new URI (codeBase) .Local Path; String comAssemblyPath = path.gate directoryname (asmFullPath); ACTCTX AC = new ACTCTX (); Ac.cbSize = Marshall Size (typeact (ACTCTX)); Ac.lpAssembly directory = comAssemblyPath; Ac.lpSource = Path.Combine (comAssemblyPath, "ComVver.x.manifest"); Ac.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID; IntPtr cookie; IntPtr hActCtx = CreateActCtxW (Ref AC); (Activate ActCTX (HctCTX, Out Cookie)) (Try {// Com Class IComViewer = New Comcast Client (Instant)}} Finally {DeactivateActCtx (0, Cookies);}} Else {// TODO: Error Message}

COM has been written in C ++ and looks like the manifest:

On Windows 2003 / XP, I found that the add-in In the Com Viewer.dll, I looked for the directory specified in the LipAdditional Directory instead of c: \ program files \ microsoft Office \ Office 12.

Can anyone help? Advance in Thank you.

Just think, in XP / 2003, the activation does not respect the context API LpAssembly Directory If you put the com file in the root manifest that indicates lpSource, in this case, Windows will only search for the com file that remains in executable.

Solution To create another mainstream ComViewer.x.manifest which appears depending on the original and pass it in lpSource In the above example, you can pass in the following manifest:

  & lt ;? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"? & Gt; & Lt; Assembly xmlns = "vase: schemas-microsoft-com: asm.v1" manifestVersion = "1.0" & gt; & Lt; Dependency & gt; & Lt; DependentAssembly & gt; & Lt; Assembly name = "commv. X" & gt; & Lt; / AssemblyIdentity & gt; & Lt; / DependentAssembly & gt; & Lt; / Dependencies & gt; & Lt; / Assembly & gt;  

Of course you should also add the element to the Comv.we.ManIFead.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -