Modeless dialog box and DLL
Severino Delaurenti -- del@alpha.ico.olivetti.com Tuesday, February 27, 1996 I'm using Visual C++ 2.1 on Windows 95 I'm trying to write a DLL, using MFC in a shared DLL, which displays a modeless dialog box whose template is located in the RC file as IDD_MY_DIALOG. My DllMain function looks like that: DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { if (dwReason == DLL_PROCESS_ATTACH) { TRACE0("TWAIN.DLL Initializing!\n"); afxCurrentInstanceHandle = hInstance; afxCurrentResourceHandle = hInstance; // Extension DLL one-time initialization AfxInitExtensionModule(twainDLL, hInstance); // Insert this DLL into the resource chain new CDynLinkLibrary(twainDLL); } . etc. . } When I call the Create function with the following code CMyDlg MyDlg; MyDlg.Create ("IDD_MY_DIALOG"); I get on the Output window the following message: ERROR: Cannot find dialog template named 'IDD_MY_DIALOG'. Stepping through the MFC source code I noticed that the function _AfxCheckDialogTemplate () returned FALSE after calling the API function ::FindResource () that returned NULL. Now: I'm sure that in my RC file the template is present. Somebody can tell me what is wrong about the code ? Thanks in advance.
David W. Gillett -- DGILLETT@expertedge.com Thursday, February 29, 1996 [Mini-digest: 3 responses] > When I call the Create function with the following code > > CMyDlg MyDlg; > MyDlg.Create ("IDD_MY_DIALOG"); > > I get on the Output window the following message: > > ERROR: Cannot find dialog template named 'IDD_MY_DIALOG'. I'm about 93% certain that you'll find that the ID of your dialog template is not a *string*, let alone the string "IDD_MY_DIALOG". It's far, far more likely that its ID is a *number*, and that in resource.h you will find a line that looks like #define IDD_MY_DIALOG nnn where nnn is the number in question. Try removing the quotes around the parameter you're passing to Create(). Dave -----From: michaelThe last time I developed a shared DLL with a modeless dialog box the calling program passed its main window handle. For example, MySharedDLL (CMDIFrameWnd*)AfxGetMainWnd()); Your DLL would create the dialog as follows: CMyDlg* pDlg; pDlg = new CMyDlg; pDlg->Create(IDD_MYDIALOG, pMainWnd); Notes: 1: The parameter pMainWnd is the window handle passed by the caller. 2. I had to "new" the dialog pointer. This is a departure from convention but I couldn't make it work without it. Michael L. Thal Data Tree Corporation voice: (619)231-3300 fax: (619)231-3301 -----From: DAVISTOD@gw2k.com The answer to this question can be found by accessing TN057, either on the MS Development Library CD, or it might be on the VC++ 2.1 Help, also. The path to get to this technote on MS Dev Library is Product Documentation Languages Visual C++ 4.0 (32-bit) MFC Notes MFC Technical Notes Index TN057 Or do a query for TN057. Basically, you need to tell MFC to load resources from your DLL. The technote gives all the gory details. Todd Davis Gateway 2000
| Вернуться в корень Архива |