🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2271

Help: Problems with resource strings.

#2271
From: A Nonymous
Date: Mon, 19 Mar 2007 17:16
87 lines
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?
Technical Details
Message-ID: <Xns98F872A803C84anonymoushotmailcom@207.105.83.66>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,714830e17a60e95b,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Help: Problems with resource strings.
From: A Nonymous <anonymous@hotmail.com>
Message-ID: <Xns98F872A803C84anonymoushotmailcom@207.105.83.66>
User-Agent: Xnews/5.04.25
NNTP-Posting-Host: 74.254.162.162
Date: 19 Mar 2007 09:16:14 -0800
X-Trace: newsgroups.borland.com 1174320974 74.254.162.162 (19 Mar 2007 09:16:14 -0800)
Lines: 87
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail