CPropertySheet problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

We have a property sheet that is created in one dll, and on that property
sheet, there is a property page that is created in another dll. So, the
property sheet and the property page come from different module states. Now,
in CPropertySheet::OnKickIdle(), it calls GetActivePage(), which then sends a
message in order to get the handle to the active page. Given the handle, it
then calls CWnd::FromHandle() to get the pointer to the CPropertyPage. The
problem is that the CPropertyPage was initialized in a different module state
than the CPropertySheet, and so the map of handles-to-pointers does not
include the property page. Since the handle is not found in the map, MFC
creates a temporary CWnd object and gives us that back. But this object isn't
a CPropertyPage, and so GetActivePage() fails. I can think of three
possibilities here...

(1) Creating a page in one dll and adding it to a sheet in another dll is
not legal/supported, and so we shouldn't even try to do it,

(2) The code in CPropertySheet should not do a FromHandle() because that is
assuming that we are in the correct module state for the active page,

(3) There is something else we have to do to make this work.
 
Saran said:
Hi all,

We have a property sheet that is created in one dll, and on that property
sheet, there is a property page that is created in another dll. So, the
property sheet and the property page come from different module states. Now,
in CPropertySheet::OnKickIdle(), it calls GetActivePage(), which then sends a
message in order to get the handle to the active page. Given the handle, it
then calls CWnd::FromHandle() to get the pointer to the CPropertyPage. The
problem is that the CPropertyPage was initialized in a different module state
than the CPropertySheet, and so the map of handles-to-pointers does not
include the property page. Since the handle is not found in the map, MFC
creates a temporary CWnd object and gives us that back. But this object isn't
a CPropertyPage, and so GetActivePage() fails. I can think of three
possibilities here...

(1) Creating a page in one dll and adding it to a sheet in another dll is
not legal/supported, and so we shouldn't even try to do it,

(2) The code in CPropertySheet should not do a FromHandle() because that is
assuming that we are in the correct module state for the active page,

(3) There is something else we have to do to make this work.

Is there any chance you can use extension DLLs? I've written many MFC
extension DLLs, and I've never once worried about module state. I do define
resource ranges for each DLL and adhere to them when I create their
resources. You can create a sample MFC EXE project and note where the
various resource IDs begin; your extension DLL ID space then would start
substantially beyond those IDs. To avoid stepping on MFC's ID space, see
these tech notes:

TN020: ID Naming and Numbering Conventions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_MFCNOTES_TN020.asp

TN033: DLL Version of MFC
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_MFCNOTES_TN033.asp
 
Hi Doug-

I can't use extension DLLs. I am dealing with large applications which can
be configured differently, and so we have to keep some code in separate
top-level dlls. So, this brings me back to where I started. Either:

(1) Microsoft does not intend CPropertySheets to own CPropertyPages whose
resources come from different module states, or

(2) CPropertySheet should not be calling FromHandle the way it currently is,
or

(3) There is some trick to get this to work...

Thanks
Saran
 
Back
Top