Problem invoking Dialog box in DLL(_AFXDLL)
Milind Changire -- mrc@corus.com Thursday, August 29, 1996 Environment: VC++ 4.0, Windows NT 3.51 Hello People! I have a problem invoking a dialog box in a DLL compiled with _AFXDLL compiler setting. DLL is Appwizard generated. [MFC AppWizard DLL] I have the same compiler settings for my application as well i.e. _AFXDLL Dialog box in the application loads up fine, but not in the DLL. I call a DLL exported function in which I load the dialog. I tried to implement this with "Using MFC in Static Lib" That worked just fine. Then for my DLL (_AFXDLL) I did the following: I then used AfxSetResourceHandle() to set the resource handle to that of the DLL in my exported function, before instantiating the dialog object. Called dlg.DoModal() and then restored the Application resource handle by AfxSetResourceHandle(). Then I could load the dialogs from the EXE as well as from the DLL. -------------------------- IS THIS THE _ONLY_ WAY TO GET DIALOGS RUNNING WITH THE _AFXDLL OPTION? CAN I AVIOD SETTING/RESETTING THE RESOURCE HANDLE EACH TIME I LOAD A DIALOG FROM THE DLL (_AFXDLL)? BTW, I'm happy to know that things work fine using the "MFC Static Lib" option, but I'd like to know about this option as well. -------------------------- TIA -Milind [Thank you David, for the 'Environment' related reminder.]
Anthony DiBlasio -- Tony_DiBlasio@msn.com Friday, August 30, 1996 In order to use any resource from a DLL (other than an extension DLL) you must change the module state information to use the correct module's resources. You can either do it the way you explained, or a much cleaner way is to use the following macro: AFX_MANAGE_STATE(AfxGetStaticModuleState()); This macro instantiates a C++ object that in the constructor changes the module state, and in the destructor changes it back. Tony_DiBlasio@msn.com ---------- From: owner-mfc-l@majordomo.netcom.com on behalf of Milind Changire Sent: Thursday, August 29, 1996 3:10 AM To: MFC-L Subject: Problem invoking Dialog box in DLL(_AFXDLL) Environment: VC++ 4.0, Windows NT 3.51 Hello People! I have a problem invoking a dialog box in a DLL compiled with _AFXDLL compiler setting. DLL is Appwizard generated. [MFC AppWizard DLL] I have the same compiler settings for my application as well i.e. _AFXDLL Dialog box in the application loads up fine, but not in the DLL. I call a DLL exported function in which I load the dialog. I tried to implement this with "Using MFC in Static Lib" That worked just fine. Then for my DLL (_AFXDLL) I did the following: I then used AfxSetResourceHandle() to set the resource handle to that of the DLL in my exported function, before instantiating the dialog object. Called dlg.DoModal() and then restored the Application resource handle by AfxSetResourceHandle(). Then I could load the dialogs from the EXE as well as from the DLL. -------------------------- IS THIS THE _ONLY_ WAY TO GET DIALOGS RUNNING WITH THE _AFXDLL OPTION? CAN I AVIOD SETTING/RESETTING THE RESOURCE HANDLE EACH TIME I LOAD A DIALOG FROM THE DLL (_AFXDLL)? BTW, I'm happy to know that things work fine using the "MFC Static Lib" option, but I'd like to know about this option as well. -------------------------- TIA -Milind [Thank you David, for the 'Environment' related reminder.]
Roger Austin -- R.Austin@ioh.ac.uk Monday, September 02, 1996 An AppWizard-generated MFC extension DLL (_AFXDLL) contains all the code needed to find your (dialog) resources, provided you link your app using MFC in a shared DLL and call the DLL initialisation function provided by AppWizard. This function creates a CDynaLink object and adds it to a linked list maintained by your EXE. Whenever you try to load a resource, the MFC framework first uses the default resource handle (the EXE, if you have not changed it) and if it fails to find the resource, it then walks the list of CDynaLink objects, looking in each of the DLL's. The key point here, and probably the source of your problem, is that it will return the first resource it finds having a matching ID. Thus your resource IDs need to be GLOBALLY unique (i.e. across both EXE and any other extension DLLs). This can be a pain, but with a bit of tweaking in your resource symbol header files you can ensure that automatically-generated IDs remain unique (look for the APS_NEXT_XXX symbols and beware of restrictions on ID ranges). Roger > ---------- > From: owner-mfc-l@majordomo.netcom.com on behalf of Milind Changire > Sent: Thursday, August 29, 1996 3:10 AM > To: MFC-L > Subject: Problem invoking Dialog box in DLL(_AFXDLL) > > > Environment: VC++ 4.0, Windows NT 3.51 > > Hello People! > > I have a problem invoking a dialog box in a DLL compiled with _AFXDLL > compiler setting. DLL is Appwizard generated. [MFC AppWizard DLL] I have > the same compiler settings for my application as well i.e. _AFXDLL > > Dialog box in the application loads up fine, but not in the DLL. I call a > DLL exported function in which I load the dialog. > > I tried to implement this with "Using MFC in Static Lib" That worked just > fine. > > Then for my DLL (_AFXDLL) I did the following: > I then used AfxSetResourceHandle() to set the resource handle to that of > the DLL in my exported function, before instantiating the dialog object. > Called dlg.DoModal() and then restored the Application resource handle by > AfxSetResourceHandle(). Then I could load the dialogs from the EXE as well > as from the DLL. > > -------------------------- > > IS THIS THE _ONLY_ WAY TO GET DIALOGS RUNNING WITH THE _AFXDLL OPTION? > > CAN I AVIOD SETTING/RESETTING THE RESOURCE HANDLE EACH TIME I LOAD A > DIALOG FROM THE DLL (_AFXDLL)? > > BTW, I'm happy to know that things work fine using the "MFC Static Lib" > option, but I'd like to know about this option as well. > -------------------------- > > TIA > > -Milind > > [Thank you David, for the 'Environment' related reminder.] > >
Pete Chestna -- pchestna@highground.com Tuesday, September 03, 1996 [Mini-digest: 2 responses] Without telling MFC explicitely where your resources are, the only way to do extension DLLs is to give all of your resources unique IDs within the entire product. That means that all DLGs must have unique IDs, same for Bitmaps, etc. You will then be guaranteed to find and load the correct items. Pete At 12:40 PM 8/29/96 +0530, you wrote: > >Environment: VC++ 4.0, Windows NT 3.51 > >Hello People! > >I have a problem invoking a dialog box in a DLL compiled with _AFXDLL >compiler setting. DLL is Appwizard generated. [MFC AppWizard DLL] I have >the same compiler settings for my application as well i.e. _AFXDLL > >Dialog box in the application loads up fine, but not in the DLL. I call a >DLL exported function in which I load the dialog. > >I tried to implement this with "Using MFC in Static Lib" That worked just >fine. > >Then for my DLL (_AFXDLL) I did the following: >I then used AfxSetResourceHandle() to set the resource handle to that of >the DLL in my exported function, before instantiating the dialog object. >Called dlg.DoModal() and then restored the Application resource handle by >AfxSetResourceHandle(). Then I could load the dialogs from the EXE as well >as from the DLL. > >-------------------------- > >IS THIS THE _ONLY_ WAY TO GET DIALOGS RUNNING WITH THE _AFXDLL OPTION? > >CAN I AVIOD SETTING/RESETTING THE RESOURCE HANDLE EACH TIME I LOAD A >DIALOG FROM THE DLL (_AFXDLL)? > >BTW, I'm happy to know that things work fine using the "MFC Static Lib" >option, but I'd like to know about this option as well. >-------------------------- > >TIA > >-Milind > >[Thank you David, for the 'Environment' related reminder.] > --- "To you -- is it movement or is it action? Peter J. Chestna It is contact or just reaction? HighGround Systems And you -- revolution or just resistance? PChestna@highground.com Is it living, or just existence?" - RUSH (508) 263-5588 x.125 -----From: Branko ZurkovichAnother way to make your application find the proper DLL is to put the following statement at the beginning of each exported function: AFX_MANAGE_STATE(AfxGetStaticModuleState( )); Hope this helps... Branko Zurkovic Senior Software Engineer ESSA Software
| Вернуться в корень Архива |