I'm using Delphi and Add-in Express VCL to develop an Excel COM Add-in. To enable theming in my forms, I'm using a manifest and activation contexts, as it's written in David Heffernan's answer here:
Apply Windows Theme to Office Com add-in
Based on the linked post, here is my code:
var
  ActivationContext: TActivationContext;
begin
  try
    ActivationContext := TActivationContext.Create;
    try
      ShowMessage('Exception comes after this');
    finally
      ActivationContext.Free;
    end;
  except
    on E:Exception do
      ShowMessage(Format(SErrorString, [E.ClassName, E.Message]));
  end;
end;
The message dialog is properly displayed (themed!) but when ActivationContext.Free is called (which calls DeactivateActCtx(0, FCookie);) I'm getting the following exception:
EExternalException: External exception C000000D
Please note that I've inserted ShowMessage in the above code for demonstration purposes, normally I'm creating and showing a form with the same results (error).
How can I get around this?
Update: Here is the manifest in question:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="*"
    name="AddinName"
    type="win32"
/>
<description>Addin description</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
My Res file:
2 24 "XP.manifest"
The code to include the res file:
{$R XPManifest\xp_manifest.RES}
Is it important for AddinName to match the name of the Delphi project?
One more note: the add-in is compiled for 64-bit Excel.