Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

ActivateActCtx (kernel32)
 
.
Summary
The ActivateActCtx function activates the specified activation context. It does this by pushing the specified activation context to the top of the activation stack. The specified activation context is thus associated with the current thread and any appropriate side-by-side API functions.

C# Signature:

[DllImport("Kernel32.dll", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ActivateActCtx(IntPtr hActCtx, out IntPtr lpCookie);

VB Signature:

Declare Function ActivateActCtx Lib "Kernel32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

MFC automatically manages activation context switching for fusion/winsxs support.

Interop dll's don't. I had to add support for this in our application. To do so, define

these adt's and values:

[StructLayout(LayoutKind.Sequential)]

    private struct ACTCTX
    {
    public int cbSize;
    public uint dwFlags;
    public string lpSource;
    public ushort wProcessorArchitecture;
    public ushort wLangId;
    public string lpAssemblyDirectory;
    public UInt16 lpResourceName;
    public string lpApplicationName;
    }

    private const uint ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID = 0x001;
    private const uint ACTCTX_FLAG_LANGID_VALID = 0x002;
    private const uint ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID = 0x004;
    private const uint ACTCTX_FLAG_RESOURCE_NAME_VALID = 0x008;
    private const uint ACTCTX_FLAG_SET_PROCESS_DEFAULT = 0x010;
    private const uint ACTCTX_FLAG_APPLICATION_NAME_VALID = 0x020;
    private const uint ACTCTX_FLAG_HMODULE_VALID = 0x080;

    private const uint RT_MANIFEST = 24;
    private const uint CREATEPROCESS_MANIFEST_RESOURCE_ID = 1;
    private const uint ISOLATIONAWARE_MANIFEST_RESOURCE_ID = 2;
    private const uint ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID = 3;

To create the context:

private bool EnsureActivateContextCreated()
    {
    string rgchFullModulePath = null;
    rgchFullModulePath = System.Reflection.Assembly.GetExecutingAssembly().Location;

    actCtx = new ACTCTX();
    actCtx.cbSize = Marshal.SizeOf(typeof(ACTCTX));
    actCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
    actCtx.lpSource = rgchFullModulePath;
    actCtx.lpResourceName = ISOLATIONAWARE_MANIFEST_RESOURCE_ID;

    hActCtx = CreateActCtx(ref actCtx);
    contextCreationSucceeded = (hActCtx != new IntPtr(-1));

    if (!contextCreationSucceeded)
    {
        actCtx.lpResourceName = ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID;
        hActCtx = CreateActCtx(ref actCtx);
        contextCreationSucceeded = (hActCtx != new IntPtr(-1));
    }
    if (!contextCreationSucceeded)
    {
        actCtx.lpResourceName = CREATEPROCESS_MANIFEST_RESOURCE_ID;
        hActCtx = CreateActCtx(ref actCtx);
        contextCreationSucceeded = (hActCtx != new IntPtr(-1));
    }

    return contextCreationSucceeded;
    }

Now, in all your function calls, call Activate and Deactivate to get the fusion manifest of you file!

Read up on the "Programming the Context Activation API" at msdn for more info.

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions