🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Dynamic DLL..Help!

#15645
From: Alan Bellingham
Date: Thu, 19 Jun 2003 16:15
68 lines
4073 bytes
Loz <noemail@nowhere.com> wrote:

>I seem to be talking to myself a lot at the moment!

A sign of madness ...

>My current findings are thus...
>
>I don't think there ever was an issue with __cdecl or __stdcall, I think 
>it was more an issue of additional threads calling the DllEntryPoint 
>multiple times which was confusing me.
>
>I've encapsulated my initialisation code within the DllEntryPoint by 
>checking for DLL_PROCESS_ATTACH and then my uninitialising / destructor 
>code within the entry point by checking for DLL_PROCESS_DETACH when it's 
>finally unloaded.  This works fine.
>
>My issue regarding multiple instances of the DLL - I've since discovered 
>that I can only load one instance of a DLL per 'process'.  Every time I 
>load the dll using LoadLibrary, it simply increments a count within the 
>dll .  I think this means that any globals within the DLL are shared 
>within the calling process so I don't actually have a separate instance.  
>To create, manage and use multiple instances of classes within the DLL, 
>I need to create my own management code.  Is this correct?

Yes, that is correct. If you got a separate instance of the DLL (rather,
of its data segment - the code and const data segments should never
change, so can be shared between processes) each time you loaded it
without previously unloading it, you could really blow Windows out of
the water.

(Under 16-bit Windows, it wasn't even per process - you got one copy of
the DLL between all processes currently using it. I implemented a shared
memory manager that way allowing memory to be passed between programs.
Don't go there - converting to 32-bit Windows took ages.)

>For example, within my dll I have classes that declare TCP and UDP 
>Client and Server engines.  Access to these components is through a 
>defined interface.  If I want to create both a TCP and UDP Server, I 
>would have to create two pointers internal to the DLL, one for managing 
>the TCP object, and one for the UDP object.  
>
>What I was trying to do before was declare one pointer per 'dll 
>instance' that would access the 'instance object type' but because I 
>can't create 'separate DLL instances', the pointer was being use to 
>create one object, and then being used again to create the next object.  
>Hence this didn't work!  
>
>I think I've got it right?  Can anyone confirm this for me please?  

Still correct.

The problems you've been having explain much of the rationale behind
COM. With COM, you don't 'load a DLL', you create an instance of an
object, and the framework loads the DLL if required (assuming in-process
COM objects here). Then, the actual 'instance pointers' are the COM
interface pointers, and you write your COM objects to not have global
pointers.

Effectively, the COM framework does the management that you've just
worked out you need to do.

I'd suggest that the clean, elegant way to do this would be to create
COM servers.

Alan Bellingham
-- 
alanb@episys.com
Technical Details
Message-ID: <orn3fv428rthodv84bfolq6uviudao0ir1@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <Xns939EA95FE5225Loz@207.105.83.65> <Xns939F5F8BEC2F4Loz@207.105.83.65> <Xns939F8DB60F221Loz@207.105.83.65> <Xns939FA9809D1BCLoz@207.105.83.65>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,96f04d20cd206c09
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-06-19 09:21:45 PST
From: Alan Bellingham <alanb@episys.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Dynamic DLL..Help!
Date: Thu, 19 Jun 2003 17:15:57 +0100
Reply-To: alanb@episys.com
Message-ID: <orn3fv428rthodv84bfolq6uviudao0ir1@4ax.com>
References: <Xns939EA95FE5225Loz@207.105.83.65> <Xns939F5F8BEC2F4Loz@207.105.83.65> <Xns939F8DB60F221Loz@207.105.83.65> <Xns939FA9809D1BCLoz@207.105.83.65>
X-Newsreader: Forte Agent 1.92/32.572
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 193.129.251.130
X-Trace: newsgroups.borland.com 1056039314 193.129.251.130 (19 Jun 2003 09:15:14 -0700)
Lines: 68
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail