Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C++
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 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


--------------------------------------------------------------------------------
Posted

1 solution

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...
 
Share this answer
 
Comments
SB_CodeForFun 2-Jan-12 2:41am    
I have ensured that MYDLL.dll is not registered.

I am trying to achieve Reg Free COM which I am able to achieve if I install MYDLL.dll in WinSxS folder and use it as shared side by side assembly.

However I want to achieve the same using private assemblies wherein I can specify the probing path if the native DLL is not found in WinSxS

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900