🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

DLL with string resource

#3039
From: --== Alain ==--
Date: Fri, 15 Sep 2006 12:31
76 lines
3168 bytes
Hi,

I have old DLLs which contain stringtable as resource.
if i use them via my DLL class wrapper, everything works well.

Now i've created a new DLL via BDS2006, *.h and *.cpp file are similar 
to old DLL files. when i compile the new DLL everything is ok.

I have problem when i use it.
BDS2006 returns me the following error :
Project TESTLNG.exe raised exception class EAccessViolation with message 
'Access violation at address 00000000. Read of address 00000000'

the problem seems to be located to the GetResStr function.

here is my *.h file of my class wrapper:
//---------------------------------------------------------------------------
#include <System.hpp>

#ifndef CARDLLWrapperH
#define CARDLLWrapperH

//------------------------------------------------------------------------------
static HINSTANCE m_hlibLoc;
String FAR __pascal (*locGetString)(long);

class CARDLLWrapper
{
   private:
   public:
     HINSTANCE __fastcall InitializeLoc(AnsiString DLLName);
     void __fastcall TerminateLoc(HINSTANCE hlibLoc);
     String __fastcall GetResStr(long Index);
};
//---------------------------------------------------------------------------
#endif



here is my *.cpp file :
//---------------------------------------------------------------------------
#pragma hdrstop
#include "CARDLLWrapper.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//------------------------------------------------------------------------------
HINSTANCE __fastcall CARDLLWrapper::InitializeLoc(AnsiString DLLName)
{
     m_hlibLoc=LoadLibrary((DLLName + String(".dll")).c_str());
     if (m_hlibLoc != NULL)
     {
       (FARPROC) locGetString=GetProcAddress(m_hlibLoc,"GETSTRING");
        return m_hlibLoc;
     }
     else
     {
         return 0;
     }
}
//------------------------------------------------------------------------------
String __fastcall CARDLLWrapper::GetResStr(long Index)
{
     static String strRes;
     strRes=locGetString(Index);
     return strRes;
}

in my DLL locGetString is declared as following :

extern "C" String __export GetString(int Index);

String GetString(int Index)
{
     String res=AnsiString::LoadStr((int)Index);
     return res;
}
Technical Details
Message-ID: <450a9d28$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ec1cf73b7a665924,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 15 Sep 2006 14:31:49 +0200
From: --== Alain ==-- <nospam@noemail.com>
User-Agent: Thunderbird 2.0a1 (Windows/20060724)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: DLL with string resource
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 87.197.185.238
Message-ID: <450a9d28$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1158323496 87.197.185.238 (15 Sep 2006 05:31:36 -0700)
Lines: 76
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail