🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to fallback to a default resource when LoadLibrary fails?

#10240
From: Remy Lebeau (TeamB)
Date: Fri, 07 May 2004 03:08
46 lines
2413 bytes
"Malte Persike" <me@privacy.net> wrote in message
news:uqrl909k4la2uga70tfr248ufjll2t6f6b@4ax.com...

> What I would like to do is to load the stringtable from
> the DLL if it exists somewhere in the search path. If not,
> the stringtable in the EXE should be used.
>
> Is there a "standard" way to accomplish this?

Simply give your DLL a specific filename that your code always looks for.
If the file exists, call LoadLibrary() and store the handle.  Then, when you
need a specific string, load the string from the DLL if available, otherwise
fallback to the EXE if not available or fails.  AnsiString has a LoadStr()
method that can help you.  For example (untested):

    HINSTANCE hSTModule = NULL;

    __fastcall TForm1::TForm1(TComponent *Owner)
        : TForm(Owner)
    {
        AnsiString filename = ExtractFilePath(Application->ExeName) +
"somefile.dll";
        if( FileExists(filename) )
            hSTModule = ::LoadLibrary(filename.c_str());
    }

    __fastcall TForm1::~TForm1()
    {
        if( hSTModule != NULL )
            ::FreeLibrary(hSTModule);
    }

    AnsiString __fastcall GetStringFromTable(UINT uID)
    {
        if( hSTModule != NULL )
        {
            AnsiString str = AnsiString::LoadStr(hSTModule, uID);
            if( str.Length() > 0 )
                return str;
        }
        return AnsiString::LoadStr((HINSTANCE)HInstance, uID);
    }


Gambit
Technical Details
Message-ID: <409afef0@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!atl-c02.usenetserver.com!news.usenetserver.com!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <uqrl909k4la2uga70tfr248ufjll2t6f6b@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,a2edea02879f485
X-Google-Attributes: gid10cc67,public
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <uqrl909k4la2uga70tfr248ufjll2t6f6b@4ax.com>
Subject: Re: How to fallback to a default resource when LoadLibrary fails?
Date: Thu, 6 May 2004 20:08:15 -0700
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.138.253
Message-ID: <409afef0@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1083899632 67.22.138.253 (6 May 2004 20:13:52 -0700)
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!atl-c02.usenetserver.com!news.usenetserver.com!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail