Question on resource-only DLL
edwardlau@hactl.com.hk Thursday, July 25, 1996 Environment: VC++ 4.0 under Win 95 I have an application which would load a string-table-resource-only DLL. The application has it's own resource but not the string table resource. So whenever I have to gain access to the string table entry, I have to call the below member function : void CMultiLangDlg::SetLangText() { // before this function is called, m_hInst is loaded as the // instance of the DLL HINSTANCE hInstanceRCExe; if (m_hInst != NULL) { // save the application's resource handle hInstanceRCExe = AfxGetResourceHandle(); // set to use DLL's resource AfxSetResourceHandle(m_hInst); } CString tmpstr; tmpstr.LoadString(IDS_WNDTITLE); SetWindowText(tmpstr); tmpstr.LoadString(IDS_OKBUTT); SetDlgItemText(IDOK, tmpstr); tmpstr.LoadString(IDS_CANCELBUTT); SetDlgItemText(IDCANCEL, tmpstr); tmpstr.LoadString(IDS_CAPTION); SetDlgItemText(IDC_STATIC_TEXT1, tmpstr); // restore to use application's own resource if (m_hInst != NULL) AfxSetResourceHandle(hInstanceRCExe); } However, I find it rather inefficient to switch between application's own resource and the DLL's (say, if I have many dialogs that should be popup but use the string resource from DLL). Is there any method to 'add' to string table resource from the DLL to the application's own resource pool, say, in the application's InitInstance function? Thanks in advance.... Edward, PEI, edwardlau@hactl.com.hk
Garret Wilson -- Garret@MentorComputer.com Monday, July 29, 1996 edwardlau@hactl.com.hk wrote: > > Environment: VC++ 4.0 under Win 95 > > I have an application which would load a string-table-resource-only > DLL. The application has it's own resource but not the string table > resource. So whenever I have to gain access to the string table entry, > I have to call the below member function : > > void CMultiLangDlg::SetLangText() > { > // before this function is called, m_hInst is loaded as the > // instance of the DLL > HINSTANCE hInstanceRCExe; > if (m_hInst != NULL) > { > // save the application's resource handle > hInstanceRCExe = AfxGetResourceHandle(); > // set to use DLL's resource > AfxSetResourceHandle(m_hInst); > } > > CString tmpstr; > tmpstr.LoadString(IDS_WNDTITLE); > SetWindowText(tmpstr); > tmpstr.LoadString(IDS_OKBUTT); > SetDlgItemText(IDOK, tmpstr); > tmpstr.LoadString(IDS_CANCELBUTT); > SetDlgItemText(IDCANCEL, tmpstr); > tmpstr.LoadString(IDS_CAPTION); > SetDlgItemText(IDC_STATIC_TEXT1, tmpstr); > > // restore to use application's own resource > if (m_hInst != NULL) > AfxSetResourceHandle(hInstanceRCExe); > > } > > However, I find it rather inefficient to switch between application's > own resource and the DLL's (say, if I have many dialogs that should be > popup but use the string resource from DLL). Is there any method to > 'add' to string table resource from the DLL to the application's own > resource pool, say, in the application's InitInstance function? > > Thanks in advance.... > > Edward, PEI, edwardlau@hactl.com.hk Edward, You could get the handle to the DLL one time, and then just load a string from the DLL like this: //returns a CString from a resource in module instance CString CStringFromResource(const HINSTANCE instance, const UINT id) { char szBuffer[255]; //use whatever size you know is big enough LoadString(instance, id, szBuffer, 255); //load the string from the resource return CString(szBuffer); //return a string based upon the buffer } Just put CStringFromResource in place of each tmpstr.LoadString() call, which will allow you to specify the DLL. I don't have MSVC++ loaded, but from your code I'm guessing that CString.LoadString() doesn't allow you to specify a module. I think that's why I wrote this routine previously. Hope this helps, Garret -- ***************************************************************************** Mentor Computer Solutions - (918) 789-2734 - http://www.MentorComputer.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Visit our web site for software for the classroom, software development tools and more. Products include GradeScan, which creates and prints tests and then scans and grades them and records the scores in the integrated gradebook.
Pete Chestna -- pchestna@highground.com Monday, August 05, 1996 At 10:21 AM 7/29/96 -0500, you wrote: >edwardlau@hactl.com.hk wrote: >> >> Environment: VC++ 4.0 under Win 95 >> >> I have an application which would load a string-table-resource-only >> DLL. The application has it's own resource but not the string table >> resource. So whenever I have to gain access to the string table entry, >> I have to call the below member function : >> >> void CMultiLangDlg::SetLangText() >> { >> // before this function is called, m_hInst is loaded as the >> // instance of the DLL >> HINSTANCE hInstanceRCExe; >> if (m_hInst != NULL) >> { >> // save the application's resource handle >> hInstanceRCExe = AfxGetResourceHandle(); >> // set to use DLL's resource >> AfxSetResourceHandle(m_hInst); >> } >> >> CString tmpstr; >> tmpstr.LoadString(IDS_WNDTITLE); >> SetWindowText(tmpstr); >> tmpstr.LoadString(IDS_OKBUTT); >> SetDlgItemText(IDOK, tmpstr); >> tmpstr.LoadString(IDS_CANCELBUTT); >> SetDlgItemText(IDCANCEL, tmpstr); >> tmpstr.LoadString(IDS_CAPTION); >> SetDlgItemText(IDC_STATIC_TEXT1, tmpstr); >> >> // restore to use application's own resource >> if (m_hInst != NULL) >> AfxSetResourceHandle(hInstanceRCExe); >> >> } >> >> However, I find it rather inefficient to switch between application's >> own resource and the DLL's (say, if I have many dialogs that should be >> popup but use the string resource from DLL). Is there any method to >> 'add' to string table resource from the DLL to the application's own >> resource pool, say, in the application's InitInstance function? >> >> Thanks in advance.... >> >> Edward, PEI, edwardlau@hactl.com.hk > >Edward, > >You could get the handle to the DLL one time, and then just load a >string from the DLL like this: > >//returns a CString from a resource in module instance >CString CStringFromResource(const HINSTANCE instance, const UINT id) >{ > char szBuffer[255]; //use whatever size you know is big enough > LoadString(instance, id, szBuffer, 255); //load the string from the >resource > return CString(szBuffer); //return a string based upon the buffer >} > >Just put CStringFromResource in place of each tmpstr.LoadString() call, >which will allow you to specify the DLL. I don't have MSVC++ loaded, but >from your code I'm guessing that CString.LoadString() doesn't allow you >to specify a module. I think that's why I wrote this routine previously. > >Hope this helps, > >Garret >-- > If your application indeed doesn't have a string table resource, you have an easy answer. Make you String-table-only-dll an AFX_EXTENSION_DLL. Once you do that, the CString.LoadString calls AfxFindResource (or something very close). This walks the chain from the applications resources to the registered AfxExtension resources and will always find the strings in your dll automagically. Pete --- "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
tomm@wrq.com Friday, August 09, 1996 Environment: VC++ 4.2, NT 3.5 // .Here is one way to embed a dialog in another dialog.. // I don't claim it's the best way but it works perfectly. ////////////////////////////////////////////////////////////////////////////// // // Function: CBHODlg::OnInitDialog() // // Description: embed a dialog box as a 'control' // // Returns: BOOL. // ////////////////////////////////////////////////////////////////////////////// BOOL CBHODlg::OnInitDialog() { CDialog::OnInitDialog(); // .position the sub-table dialog and display it CRect rectAnchor; CRect rectSubTable; // .NOTE: when you create the sub-table dialog resource, // make certain it has a style of 'child' // otherwise, the following code will not position // the sub-table dialog correctly. // NOTE: (m_dlgSubTable is an instance of your embedded dialog class) m_dlgSubTable.Create(IDD_DIALOG_HOST_OS_VERSION, this); // . an invisible, disabled edit control made as small as possible // on the parent dialog is used to 'anchor' the location of the // top left corner of the sub-table dialog. // // there are probably better ways to do this.. but I found this // method makes it simple to quickly make tiny adjustments to // the embedded control's position CWnd* pWnd = GetDlgItem(IDC_EDIT_ANCHOR); // .GetWindowRect() returns screen coordinates of 'anchor' control pWnd->GetWindowRect(&rectAnchor); // .convert the screen coordinates to client coordinates for the subsequent // call to MoveWindow() ScreenToClient(&rectAnchor); // .get the size of the sub table dialog m_dlgSubTable.GetClientRect(&rectSubTable); // .position the window over the anchor - (for a child window, MoveWindow() wants // client coordinates) m_dlgSubTable.MoveWindow(rectAnchor.left, rectAnchor.top, rectSubTable.right, rectSubTable.bottom, FALSE); // .display the embedded dialog control window m_dlgSubTable.ShowWindow(TRUE); return(TRUE); } //////////////////// .end function: CBHODlg::OnInitDialog() Thomas Murtola WRQ, Inc. 1500 Dexter Avenue North Seattle, WA 98109 tomm@wrq.com ______________________________ Reply Separator _________________________________ Subject: Re: Question on resource-only DLL Author: mfc-l@netcom.com at CCINTNET Date: 8/7/96 8:28 PM At 10:21 AM 7/29/96 -0500, you wrote: >edwardlau@hactl.com.hk wrote: >> >> Environment: VC++ 4.0 under Win 95 >> >> I have an application which would load a string-table-resource-only >> DLL. The application has it's own resource but not the string table >> resource. So whenever I have to gain access to the string table entry, >> I have to call the below member function : >> >> void CMultiLangDlg::SetLangText() >> { >> // before this function is called, m_hInst is loaded as the >> // instance of the DLL >> HINSTANCE hInstanceRCExe; >> if (m_hInst != NULL) >> { >> // save the application's resource handle >> hInstanceRCExe = AfxGetResourceHandle(); >> // set to use DLL's resource >> AfxSetResourceHandle(m_hInst); >> } >> >> CString tmpstr; >> tmpstr.LoadString(IDS_WNDTITLE); >> SetWindowText(tmpstr); >> tmpstr.LoadString(IDS_OKBUTT); >> SetDlgItemText(IDOK, tmpstr); >> tmpstr.LoadString(IDS_CANCELBUTT); >> SetDlgItemText(IDCANCEL, tmpstr); >> tmpstr.LoadString(IDS_CAPTION); >> SetDlgItemText(IDC_STATIC_TEXT1, tmpstr); >> >> // restore to use application's own resource >> if (m_hInst != NULL) >> AfxSetResourceHandle(hInstanceRCExe); >> >> } >> >> However, I find it rather inefficient to switch between application's >> own resource and the DLL's (say, if I have many dialogs that should be >> popup but use the string resource from DLL). Is there any method to >> 'add' to string table resource from the DLL to the application's own >> resource pool, say, in the application's InitInstance function? >> >> Thanks in advance.... >> >> Edward, PEI, edwardlau@hactl.com.hk > >Edward, > >You could get the handle to the DLL one time, and then just load a >string from the DLL like this: > >//returns a CString from a resource in module instance >CString CStringFromResource(const HINSTANCE instance, const UINT id) >{ > char szBuffer[255]; //use whatever size you know is big enough > LoadString(instance, id, szBuffer, 255); //load the string from the >resource > return CString(szBuffer); //return a string based upon the buffer >} > >Just put CStringFromResource in place of each tmpstr.LoadString() call, >which will allow you to specify the DLL. I don't have MSVC++ loaded, but >from your code I'm guessing that CString.LoadString() doesn't allow you >to specify a module. I think that's why I wrote this routine previously. > >Hope this helps, > >Garret >-- > If your application indeed doesn't have a string table resource, you have an easy answer. Make you String-table-only-dll an AFX_EXTENSION_DLL. Once you do that, the CString.LoadString calls AfxFindResource (or something very close). This walks the chain from the applications resources to the registered AfxExtension resources and will always find the strings in your dll automagically. Pete --- "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
| Вернуться в корень Архива |