Article View: borland.public.cppbuilder.internationalization
Article #246Re: Unicode and LoadString
From: Peter Van Hove
Date: Thu, 02 Jun 2005 13:04
Date: Thu, 02 Jun 2005 13:04
80 lines
3488 bytes
3488 bytes
The VCL limitations aside, you best use your own code to get the Unicode
strings out the dll.
At least then you have the true unicode strings, without being limited by
various possible conversions of all sorts done in the background, and if you
"hand" the result as wchar_t pointers to VCL AnsiString members (e.g.
label->Caption = ) you will see that all works nicely, beit that the system
will have to be setup for this particular language (because of the VCL
limitation, so nothing to do with the unicode itself or the dll or how the
unicode was retrieved from the dll)
E.g. :
(PS.
- wstring is from the standard c++ library
- if handle is NULL, the resource is loaded from the exe, if the handle is a
handle to a dll, the resource is loaded from the dll.
- identifier is the numer of the resource.)
//---------------------------------------------------------------------------
wstring LoadString(int Identifier, HANDLE Resource)
{
wstring mystring ;
UINT block = (Identifier >> 4) + 1 ; // Compute block number.
UINT num = Identifier & 0xf ; // Compute offset into block.
HRSRC hRC = FindResource(
Resource, // resource-module handle
MAKEINTRESOURCE(block) , // pointer to resource name
RT_STRING // pointer to resource type
); // If the function fails, the return value is NULL.
HGLOBAL hgl = NULL ;
if (!hRC && Resource)
{
// If not found in the dll, try the built in resource
hRC = FindResource(
NULL, // resource-module handle
MAKEINTRESOURCE(block) , // pointer to resource name
RT_STRING // pointer to resource type
);
Resource = NULL ;
}
LPWSTR str = NULL ;
if (hRC)
{
hgl = LoadResource(Resource, hRC); // If hRC is NULL, FindResource()
failed
str = (LPWSTR)LockResource(hgl);
}
// int len = 0 ;
if (str)
{
for (UINT i = 0; i < num; i++)
{
str += *str + 1 ;
}
mystring.assign(str + 1, *str) ;
// len = *str ;
}
return mystring ;
}
//---------------------------------------------------------------------------
Best Regards,
Peter
-------------------------------------------------------
Peter Van Hove
CD and DVD Data recovery
Peter@Smart-Projects.net
www.Smart-Projects.net
www.IsoBuster.com
-------------------------------------------------------
Technical Details
Message-ID:
<429f03d4@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<427905c4$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10297d,94c782bbe2550585 X-Google-Attributes: gid10297d,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Peter Van Hove" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> From: "Peter Van Hove" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> Newsgroups: borland.public.cppbuilder.internationalization References: <427905c4$1@newsgroups.borland.com> Subject: Re: Unicode and LoadString Date: Thu, 2 Jun 2005 15:04:20 +0200 Lines: 82 Organization: Smart Projects X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 84.195.108.101 Message-ID: <429f03d4@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1117717460 84.195.108.101 (2 Jun 2005 06:04:20 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail