Resource conflict on ON_UPDATE_COMMAND_UI
-
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.
-
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.
Try adding the following statement as the first line in every exported function of the DLL.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
«_Superman_»
I love work. It gives me something to do between weekends. -
Try adding the following statement as the first line in every exported function of the DLL.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
«_Superman_»
I love work. It gives me something to do between weekends.Do you mean code like this ?
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
pCmdUI->Enable(exe_flag);
}No. It doesn't work. Clicking on DLL's menu item will still have no effect. Is changing
#define DLL_RESOURCE_ID 1234
to
const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));
a elegant solution (To avoid resource ID conflict)? I don't know.
-
Do you mean code like this ?
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
pCmdUI->Enable(exe_flag);
}No. It doesn't work. Clicking on DLL's menu item will still have no effect. Is changing
#define DLL_RESOURCE_ID 1234
to
const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));
a elegant solution (To avoid resource ID conflict)? I don't know.
I meant adding in the DLL's code, not the EXE's.
«_Superman_»
I love work. It gives me something to do between weekends. -
I meant adding in the DLL's code, not the EXE's.
«_Superman_»
I love work. It gives me something to do between weekends.I cannot use your suggestion as I am using extension DLL. http://support.microsoft.com/kb/161589 However, I already did a similar thing even before your suggestion.
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_hResource);
}RestoreDLLState::~RestoreDLLState()
{
AfxSetResourceHandle(m_hInstOld);
}It doesn't work. :(
-
Do you mean code like this ?
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
pCmdUI->Enable(exe_flag);
}No. It doesn't work. Clicking on DLL's menu item will still have no effect. Is changing
#define DLL_RESOURCE_ID 1234
to
const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));
a elegant solution (To avoid resource ID conflict)? I don't know.
The RegisterWindowMessage Function (Windows)[^] defines a new window message that is guaranteed to be unique throughout the system, and is designed to generate at runtime message IDs that could be used for inter-process communications: using it solve your problem, but it could not be a good idea if you use it extensively, because it waste system resources. Anyway, the changement you are evaluating, requires that you manually modify the
resource.h
file on your project to remove the correspondant#define
and produce a situation where the resource editor is not able to load and handle your resource script file (i.e. project_name.rc), then you should modify it manually.