设置COM专用程序集的探测路径 [英] Set probing path of COM Private Assemblies

查看:126
本文介绍了设置COM专用程序集的探测路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想实现以下

我有一个MFC应用程序.单击该应用程序应加载一个COM dll(例如MyDLL.dll).MyDLL.dll是未注册的私有程序集.

我有以下一段代码:

Hi,

I want to achieve the following

I have a MFC Application. This Application on click of button should load a COM dll (say MyDLL.dll) MyDLL.dll is a private assembly which is NOT registered.

I have the following piece of code segment:

actCtx.cbSize = sizeof(ACTCTX);
actCtx.lpSource = _T("C:\\SampleProject1.manifest");
actCtx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
actCtx.lpAssemblyDirectory = _T("C:\\Sample");

HANDLE hCtx = ::CreateActCtx(&actCtx);

if (hCtx == INVALID_HANDLE_VALUE)
{
      MessageBox(
                     NULL,
                    _T("INVALID_HANDLE_VALUE"),
                      "Error Message",
                       MB_OK
                      );
		hCtx = NULL;
		
}
else
{
if (::ActivateActCtx(hCtx, &cookie))
{
 ::CoInitialize(NULL);
 hr = ::CoCreateInstance(CLSID_MyClass, NULL, CLSCTX_INPROC, IID_IDispatch, (void**)&ptrMyDisp);
         
ptrMyDisp->QueryInterface(IID_IMyClass,(void **)&ptrMyClass);
ptrMyClass->Add(1,2);
			
::DeactivateActCtx(0,cookie);
::ReleaseActCtx(hCtx);

hCtx = NULL;
}
}


SampleProject1.manifest包含对MYDLL.dll的引用.
我的MFC应用程序从C:\ MFCApplication \ Release文件夹执行.如果将MYDLL.dll放在C:\ MFCApplication \ Release文件夹中,则一切正常.

但是,我打算将各种dll保留在其他位置.因此,我将探测路径指定为C:\ Sample.但是,如果我从C:\ MFCApplication文件夹中删除dll,则仅将它们放在C:\ Sample中,应用程序在CoCreateInstance()之后返回类未注册错误".
如何为我的私有程序集dll提供探测路径


-------------------------------------------------- ------------------------------


SampleProject1.manifest contains a reference to MYDLL.dll

My MFC application executes from C:\MFCApplication\Release folder. If I place MYDLL.dll at C:\MFCApplication\Release folder things work correctly.

However I intend to keep the various dlls at some other place. Thus I have specified probing path as C:\Sample. However if I remove the dlls from C:\MFCApplication folder and place them only at C:\Sample the application returns "Class Not Registered error" after CoCreateInstance().

How do I provide a probing path for my private assembly dlls


--------------------------------------------------------------------------------

推荐答案

错误类未注册错误"应向您表明您的COM对象确实已注册.移动它们时,环境无法找到它们.

移动它们时,请重新运行注册.

请注意,在创建对象时,Visual Studio会为您注册对象.因此,即使您没有明确注册它们,它们仍然得到注册...
The error "Class Not Registered error" should indicate to you that your COM objects are indeed registered. When you move them, then the environment can''t find them.

When you move them, rerun the registration.

Note that Visual Studio will register your objects for you, when you create them. So even though you didn''t explicitly register them, they still got registered...


这篇关于设置COM专用程序集的探测路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆