Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages
Started by A Nonymous
Mon, 19 Mar 2007 17:16
Help: Problems with resource strings.
Author: A Nonymous
Date: Mon, 19 Mar 2007 17:16
Date: Mon, 19 Mar 2007 17:16
87 lines
3262 bytes
3262 bytes
I opened Pandoras box when I added themeing to my application. Now I am
trying to externalize the themes into resource only dlls. This turned
out to be pretty simple, and ALMOST everything works. I can read
imbedded text files, bitmaps from the resource dll like a charm.
The problems is how to read items from a STRINGTABLE in the resources.
I have tried several iterations of what looks like a simple task but
either it just silently fails to load the string, or I get an AV error.
I did a search and found several Delphi examples and used them as a
basis for my own test program. My Delphi test works perfectly:
procedure TForm1.ButtonClick(Sender: TObject);
var
h: THandle;
tmpStream: TResourceStream;
begin
h := LoadLibrary('bitmaps.dll');
try
if h <> 0 then
begin
ElLabel1.Caption := GetResourceString(h,1000);
tmpStream := TResourceStream.Create( h, 'NewTheme', 'TEXT' );
try
sm1.LoadFromStream( tmpStream );
finally
tmpStream.Free;
end;
Image.Picture.Bitmap.LoadFromResourceName(h,'ButtonUp');
end;
finally
FreeLibrary(h);
end;
end;
Since my app is written in C++ I tried to implement it in C++ but ran
into this problem. This version doesn't error, but will not load the
Label-> Caption. Everything else works fine. I left some comments so
you could see some of the other things I was trying.
void __fastcall TForm2::ButtonClick(TObject *Sender)
{
//HANDLE hlib;
//HINSTANCE hlib;
THandle * hlib;
hlib = (THandle *)LoadLibrary("IceBlue.DLL");
try
{
if (hlib)
{
// get data from a string table
Label->Caption.LoadString(hlib,1);
//ResourceString *r;
//r->module = hlib;
//r->ident = 1;
//Label->Caption = System::LoadResourceString(r);
// get data from a bitmap resource
//Image->Picture->Bitmap->LoadFromResourceName((unsigned int)hlib,
"ilBg72");
ilBg72->ResInstLoad((unsigned int)hlib,rtBitmap,"ilBg72",clWhite);
ilBg72->GetBitmap(0,Image->Picture->Bitmap);
// get data from a text resource
TResourceStream * tmpStream;
tmpStream = new TResourceStream((unsigned int)
hlib,"StyleManager","TEXT");
try
{
sm1->LoadFromStream(tmpStream);
}
__finally
{
delete tmpStream;
}
}
}
__finally
{
FreeLibrary(hlib);
}
}
I thought the bitmaps, or the resource stream would be a problem, but
they turned out to be easy.
What dumb mistake am I making?
Re: Help: Problems with resource strings.
Author: Bob Gonder
Date: Mon, 19 Mar 2007 17:20
Date: Mon, 19 Mar 2007 17:20
14 lines
1289 bytes
1289 bytes
A Nonymous wrote:
> if (hlib)
> {
> // get data from a string table
> Label->Caption.LoadString(hlib,1);
Did you try LoadStr(hlib,1) instead?
Alternative:
TChar buffer[1024];
LoadString( hlib,1, buffer, 1024 );
Label->Caption = buffer;
Re: Help: Problems with resource strings.
Author: A Nonymous
Date: Mon, 19 Mar 2007 18:43
Date: Mon, 19 Mar 2007 18:43
27 lines
1523 bytes
1523 bytes
Bob Gonder <notbg@notmindspring.invalid> wrote in
news:tchtv21urvo96jf5cvpdflura0mg7ogqq9@4ax.com:
> A Nonymous wrote:
>
>> if (hlib)
>> {
>> // get data from a string table
>> Label->Caption.LoadString(hlib,1);
>
> Did you try LoadStr(hlib,1) instead?
>
Yes, LoadStr genreates AV...
> Alternative:
>
> TChar buffer[1024];
> LoadString( hlib,1, buffer, 1024 );
> Label->Caption = buffer;
>
This with (TCHAR) works... I am sure I tried this and it did not work. It
may have been the type of hlib I was using at the time. I tried HANDLE,
HINSTANCE, and THandle but I guess I just didn't get the right combination.
Thanks.
Re: Problems with resource strings.
Author: Remy Lebeau (TeamB)
Date: Mon, 19 Mar 2007 21:22
Date: Mon, 19 Mar 2007 21:22
23 lines
1712 bytes
1712 bytes
"A Nonymous" <anonymous@hotmail.com> wrote in message
news:Xns98F872A803C84anonymoushotmailcom@207.105.83.66...
> Since my app is written in C++ I tried to implement it in C++
> but ran into this problem. This version doesn't error, but will
> not load the Label-> Caption.
It is loading the string data just fine, but you are not actually
assigning the data to the Caption property. That is why it remains
empty. You are calling the Caption property's getter method to
receive a temporary AnsiString, and then you are calling LoadString()
on that temporary, but you are not assigning the temporary back to the
property afterwards. You need to change this:
Label->Caption.LoadString(hlib,1);
To this instead:
Label->Caption = AnsiString().LoadString(hlib,1);
Gambit
Re: Problems with resource strings.
Author: A Nonymous
Date: Tue, 20 Mar 2007 04:50
Date: Tue, 20 Mar 2007 04:50
11 lines
999 bytes
999 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote in news:45fef11d$1 @newsgroups.borland.com: > Label->Caption = AnsiString().LoadString(hlib,1); > I see said the blind man. That explains one or two other oddities I have noticed. Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads