Re: Using language DLLs for strings ONLY
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 23:15:47 -0500
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
.
- Follow-Ups:
- Re: Using language DLLs for strings ONLY
- From: Mihai N.
- Re: Using language DLLs for strings ONLY
- References:
- Using language DLLs for strings ONLY
- From: Dan McCarty
- Using language DLLs for strings ONLY
- Prev by Date: Re: How to create a bitmap from raw data?
- Next by Date: Re: Puzzling font problem
- Previous by thread: Using language DLLs for strings ONLY
- Next by thread: Re: Using language DLLs for strings ONLY
- Index(es):
Relevant Pages
|