Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Share data between different dlls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rich - 06 May 2005 10:06 GMT
Hi there,

For a quite big application, I need to get large amount of data within a
static library (xxx.lib) and put them in a database (a class, say we call it
CData), and then make it accessible by a few different dynamic library files
(yyy.dll, …). I’ve tried to create a global class object of CData*, say
pData, by declaring it as an external in the header and initiate it in the
cpp of a dll file. But it doesn’t work. Other dlls will complain about
undefined variable of CData * pData in their obj when I am trying to link
them. It would be greatly appreciated if anyone could give me some
suggestions how to realize this.

Thanks in advance.

Rich
Antti Keskinen - 06 May 2005 11:37 GMT
Hello !

It seems you're approaching the problem from a wrong point of view. If you
have a static library that contains the data, then you put this data into a
database, and have several dynamic-link libraries that use this data, then
why don't you use the database itself to share the data ?

The static library can be linked with multiple DLLs, but the instance of
data is not consistent (= is not the same) across DLLs linked with the
library. Each DLL will get a seperate copy of the data via the static
library. If the static library is not linked with the DLL, the DLL will not
have the data at all.

The best solution to this problem is to utilize the database. This means
that the static library contains routines that will automatically invoke a
connection to the database, download the necessary data, and place it into a
data structure usable by the DLL to which it's linked. The advantage is that
whenever the DLL is loaded, the data received by the static library is
dictated by the database. Thus, if the database access is updatable
(refreshable recordset), each DLL will constantly have an updated copy of
the data to work with. The downside of this solution is it's complexity:
database access and synchronization are not the easiest of tasks.

Other alternative solutions might exist, such as using the Clipboard, but
they're quite prone to errors caused by simultaneous execution of other
software (like a drawing program or Office program accessing the clipboard).

I hope this answers your question. If it does not, post a follow-up,
describing your problem in further detail. The original scenario post wasn't
very clear on what you were trying to do, and what available resources you
had to do it with.

-Antti Keskinen

> Hi there,
>
[quoted text clipped - 13 lines]
>
> Rich
Rich - 06 May 2005 23:56 GMT
Thanks Anttti for your suggestions.

Being aware of different instances of a static library if linked in
different dlls, I was trying to use your "best solution" in this scenario. My
trouble is when I put some code in the static library and get the data out to
a dll, everything being fine by now, but when I complie and link another dll
which also use this static library, the linker complains that the Database
variable is unresolved external. Another thing I am not very sure is if I
have to declare the database variable as static in the dll to store the data,
to make sure other dlls can get the right data. I mean if the data will
"stay" there.

Thanks again.

Rich

> Hello !
>
[quoted text clipped - 47 lines]
> >
> > Rich
Jürgen Devlieghere - 06 May 2005 15:11 GMT
Rich,

dll's have a seperate data segment, so each dll must contain all data it
needs. You'll see this quickly enough: your linker will complain about
'unreselved externals'.

If you really want to keep the data in memory, this could be a way:
- have a function in your main program that gives access to the data. This
function must be exported using the dllexport keyword
- let each dll find that function and use it (use GetProcAddress to find the
function pointer)

Jürgen Devlieghere
> Hi there,
>
[quoted text clipped - 13 lines]
>
> Rich
Rich - 07 May 2005 00:01 GMT
Thanks Jürgen.

It would be an easy way to handle this problem, if I can change the main
program. But in my case, the main program is not accessible for me or I am
not allowed to change it, what I can add to the application is only static
libraries and dlls/extensions.

Thanks again.
Rich

> Rich,
>
[quoted text clipped - 26 lines]
> >
> > Rich
sutphinwb@nospam.nospam - 10 May 2005 05:23 GMT
What about Win32 shared memory?  Seems like your dlls are behaving like out
of process dlls which are like separate applications except they run on the
same thread.  You could map a chunk of shared memory and stuff the data in
there.  Of course from what I've seen, shared memory is a fixed length so
you'd have to make a guess about the size of your segment.

Bill

> Hi there,
>
[quoted text clipped - 13 lines]
>
> Rich

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.