🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Instantiating and calling a class contained in a DLL

#8704
From: Andrue Cope [TeamB]
Date: Tue, 28 Sep 2004 11:20
47 lines
2455 bytes
Roger Warren wrote:

> Thank you all for your input. I have much to consider, and will look
> at 'Packages' before making any rash decisions.

The alternative way to 'export' objects from a DLL is to use a handle
based methodology. The handle can either be an index into an array of
object pointers (held DLL side) or a pointer to the object instance
itself. For the latter option it is usually prudent to present the
pointer to the outside world as a 'void *' so as to deter the caller
from attempting to dereference it directly.

Basically this means that your method:

void TestDLLClass::TestMethod(AnsiString &s)
{
  Application->MessageBox(s.c_str(), "DLL", MB_OK);
}

Would become either:

void TestDLLClass::TestMethod(AnsiString &s,
                              int         handle)
{
  myObjects[ handle ]->MessageBox(s.c_str(), "DLL", MB_OK);
}

or

void TestDLLClass::TestMethod(AnsiString &s,
                              void * handle)
{
  reinterpret_cast<TMyObject *>( handle )->
    MessageBox(s.c_str(), "DLL", MB_OK);
}

Both methods have good and bad points but there's not a lot to choose
between them. If you do go that route post for further advice since the
above examples are a bit crude and could be 'prettified' :)

But if you decide you do want to export classes as you originally
proposed then there's nothing wrong with that. My comments were just
pointing out a possible issue.
-- 
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <41594910@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4154a05c$1@newsgroups.borland.com> <4157c9e7@newsgroups.borland.com> <415931b4@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e81079fc94e5a83
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address>
Subject: Re: Instantiating and calling a class contained in a DLL
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4154a05c$1@newsgroups.borland.com> <4157c9e7@newsgroups.borland.com> <415931b4@newsgroups.borland.com>
User-Agent: XanaNews/1.16.4.6
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
NNTP-Posting-Host: 217.207.223.34
Message-ID: <41594910@newsgroups.borland.com>
Date: 28 Sep 2004 04:20:48 -0700
X-Trace: newsgroups.borland.com 1096370448 217.207.223.34 (28 Sep 2004 04:20:48 -0700)
Lines: 47
X-Authenticated-User: acope
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail