Board index » cppbuilder » Help: Problems with resource strings.
A Nonymous
![]() CBuilder Developer |
Help: Problems with resource strings.2007-03-20 01:16:14 AM cppbuilder89 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? |