Discussion:
Load a library twice simultaneously
(too old to reply)
Donato
2008-06-29 22:03:24 UTC
Permalink
Hi all,
I need to load a my library twice simultaneously, but the allocations inside
the libraries are commons between them, and so there are conflicts; while,
if I load the same libray (I do a copy) with two names differents, all work
fine.
The question is: do exist a way for load the same library twice, with
separate processes?
Thanks
Alan Bellingham
2008-06-29 22:18:10 UTC
Permalink
Post by Donato
I need to load a my library twice simultaneously, but the allocations inside
the libraries are commons between them, and so there are conflicts; while,
if I load the same libray (I do a copy) with two names differents, all work
fine.
Is this Windows NT or better, or is it WIndows 95/98/ME?

If the former, there should be no problem, as unless you've taken a lot
of effort, the processes just cannot know about each other.

Alan Bellingham
--
Team Browns
<url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions
<url:http://www.borland.com/newsgroups/netiquette.html> netiquette
Donato
2008-06-29 22:40:26 UTC
Permalink
Hi Alan,
Post by Alan Bellingham
Is this Windows NT or better, or is it WIndows 95/98/ME?
If the former, there should be no problem, as unless you've taken a lot
of effort, the processes just cannot know about each other.
the OS is WinXP. and in the library I've simple vcl class:

TStringList *ListRow;
HINSTANCE CurrentHinstance;
TApplication *OriginalApplication;
extern "C" __declspec(dllexport) void drvInit(TApplication
*SenderApplication)
{
OriginalApplication=Application;
Application=SenderApplication;
ListRow=new TStringList();
..
..
}
extern "C" __declspec(dllexport) void drvDone()
{
..
..
delete ListRow;
Application=OriginalApplication;
}
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
CurrentHinstance=hinst;
return 1;
}

Thank you
Donato
2008-06-30 19:14:28 UTC
Permalink
I think the conflict is caused by global variables; is there a way for to
declare the variables in separate instances?
Thanks
Bob Gonder
2008-07-01 01:13:15 UTC
Permalink
Post by Donato
I think the conflict is caused by global variables; is there a way for to
declare the variables in separate instances?
Each executable gets it own set of globals.

App1.c
- - -
int main(void)
{
LoadLibrary("MyDLL");
getch(); //pause
return 0
}
- - -
After compiling:
c:\MyApps>Start app1.exe
c:\MyApps>Start app1.exe
Each App1 has it's own set of globals, not shared.

OTOH,
App2.c
- - -
int main(void)
{
H1 = LoadLibrary("MyDLL");
H2 = LoadLibrary("MyDLL");
getch(); //pause
return 0
}
- - -
After compiling:
c:\MyApps>Start app2.exe
App2 has only one copy of MyDLL, one set of globals.

IOW your problem lies elsewhere.
Donato
2008-07-02 04:46:47 UTC
Permalink
A last question:
I'm not sure that the structure for manage the handle of application is
correct (previous post). Is better to use the reason variable
(DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH) of DllEntryPoint procedure?
Thanks a lot
Bye

Loading...