Re: Using language DLLs for strings ONLY



Due to both serious design flaws and, as far as I can tell, a complete misunderstanding of
C++, Microsoft never gave us the following useful method. When I do this, I have


CString LoadStringFromDLL(HINSTANCE dll, UINT str)
{
HINSTANCE old = AfxGetResourceHandle();
AfxSetResourcveHandle(dll);
CString s;
s.LoadString(str);
AfxSetResourceHandle(old);
return s;
}

Of course, the OBVIOUS method would be to provide operations such as
CString::LoadString(UINT id, HINSTANCE dll), but that would be too much like blindingly
obvious (I wonder sometimes that many of the MFC functions were done by C programmers who
had a whole day of "C++ for C programmers" orientation). Similar calls for LoadBitmap,
LoadCursor, etc. would be equally obvious extensions.

Do not consider subclassing CString. Given the triviality of the above function, there
seems to be no useful purpose served in subclassing it anyway.
joe
On 30 Jan 2006 14:58:35 -0800, "Dan McCarty" <dmccarty@xxxxxxxxx> wrote:

>(Cross-posted to ms.public.windowsce.embedded, sorry to people who read
>both groups)
>
>I've created a per-language DLL with some string resources and when my
>app loads I'm trying to load the module and get the string resources
>from there instead.
>
>The test code that does it is simply:
> HINSTANCE hRes = NULL;
> hRes= LoadLibrary(_T("res0C0A.dll"));
> if (hRes)
> AfxSetResourceHandle(hRes);
>
>My problem is that after setting the resource handle to the other DLL,
>the app tries to load ALL resources from that DLL (which of course
>fails).
>
>It seems my options are either to create virtually identical DLL's
>(with the exception of the translated strings) or to subclass CString
>and read strings from the int'l DLL but other resource from the app's
>resources.
>
>Are these my only two options? Or am I overlooking something else?
>
>Thanks,
>Dan.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Using language DLLs for strings ONLY
    ... I've created a per-language DLL with some string resources and when my ... app loads I'm trying to load the module and get the string resources ... My problem is that after setting the resource handle to the other DLL, ...
    (microsoft.public.vc.mfc)
  • Using language DLLs for strings ONLY
    ... I've created a per-language DLL with some string resources and when my ... app loads I'm trying to load the module and get the string resources ... My problem is that after setting the resource handle to the other DLL, ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: LoadString() not working
    ... There is a call to set the resource handle to direct the resources to be loaded from your ... >I have a resource only DLL that contains all string related resources. ... I added two additional string resources and these particular ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: #pragma lib buggers everything up
    ... A lot of the resources are relevant to the static ... a client exe, and I experienced these too, i.e. the exe can't use any ... Have a resource-only DLL, you might say, - yes, I did consider this but the ... > and often on a particular version of the compiler and particular compiler ...
    (microsoft.public.vc.language)
  • Re: Localization of my MFC application
    ... We create a set of resource files for each separate program (.EXE, .DLL, ... My resources are not so large that it makes a big ... > We have an application which has an exe and uses two MFC extension DLLs ...
    (microsoft.public.vc.mfc)