Avoid Registration Free COM manifest problems with Activation Context API

來源:互聯網
上載者:User
Avoid Registration Free COM manifest problems with Activation Context API Gopalakrishna Palem 26 Mar 2007 1:01 PM
  • Comments 0

Having difficulties while loading the Side-by-Side assembly manifests for Registration-Free COM?

Perhaps Activation context API could come to your rescue (Ref: http://msdn2.microsoft.com/en-us/library/aa374166.aspx).

The activation context structure lets you explicitly specify the path of the manifest to be loaded, among other things, using the CreateActCtx and ActivateActCtx functions.

In the sample code below, when we try to create an instance of a COM component (that is not registered using RegSvr32), we encounter a failure. However, after creating an activation context that refers to the path of the Side-by-Side manifest and activating it, the CoCreateInstance succeeds.

 IMyComponent* pObj = NULL;  // CoCreateInstance Fails without the component being registered  HRESULT hr = CoCreateInstance(CLSID_MyComponent, NULL, CLSCTX_INPROC_SERVER, IID_IMyComponent, (void**)&pObj);

 ACTCTX actctx;

 ZeroMemory(&actctx, sizeof(actctx));

 actctx.cbSize = sizeof(actctx);

 actctx.lpSource = szManifestFilePath; // Path to the Side-by-Side Manifest File

 HANDLE pActCtx = CreateActCtx(&actctx);

 if(pActCtx == INVALID_HANDLE_VALUE) { return E_FAIL; }

 ULONG_PTR lpCookie;

 if(ActivateActCtx(pActCtx, &lpCookie))
 {   // CoCreateInstance should succeed now.     hr = CoCreateInstance(CLSID_MyComponent, NULL, CLSCTX_INPROC_SERVER, IID_IMyComponent, (void**)&pObj);
   DeactivateActCtx(0, lpCookie);
 }

 ReleaseActCtx(pActCtx);

 return hr;

The advantage here is that we can at run-time decide which manifest file to load and can have control over when to load (instead of letting the loader do it at the application loading time). The manifest file path specified in the activation context could be any valid file system path. However, the COM DLL being referred by the manifest should reside within the same sub-directory structure as that of the manifest.

For a description on the format of the manifest files that should be used for Side-by-Side assemblies, refer to http://msdn2.microsoft.com/en-us/library/aa375632.aspx.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.