0
votes

I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE

ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE, OnUpdateExeButtonResource)

void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
        pCmdUI->Enable(exe_flag);

}

This EXE application will load another DLL class.

DLL class is having a menu item resource with ID DLL_MENU_RESOURCE.

Unfortunately, EXE_BUTTON_RESOURCE and DLL_MENU_RESOURCE is having the same resource ID. To avoid them have conflict ID is pretty difficult, as they are two separate projects.

Whenever exe_flag, which is the member for EXE turn to false, this will affect menu in DLL too. Clicking on DLL_MENU_RESOURCE menu will have no effect at all.

How can I avoid this trap? Having manual inspection on their resource.h files is not an option for me, as they are 2 separate projects, managed by 2 separate teams.

Once, I thought it might be resource conflicting problem. Hence, in DLL code which show the right clicked menu, I have the following code the load DLL resource, and restore back EXE resource when done.

void DLL::OnContextMenu(CWnd* pWnd, CPoint point) 
{
    RestoreDLLState ext;
        ...
}

RestoreDLLState will load global DLL resource, and load back its original resource once done.

RestoreDLLState::RestoreDLLState()
{
    m_hInstOld = AfxGetResourceHandle();
    AfxSetResourceHandle(g_hDLLResource);
}

RestoreDLLState::~RestoreDLLState()
{
    AfxSetResourceHandle(m_hInstOld);
}

That doesn't work. My guess is that, the action to enable/disable resource with particular ID, will propagate from EXE till DLL, regardless what is the default resource being loaded currently.

To be honest, I had posted the similar question to Code Project and microsoft.public.vc.mfc, but didn't get much useful comment out from there.

1

1 Answers