By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,167 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,167 IT Pros & Developers. It's quick & easy.

Share data between different dlls

P: n/a
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

Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
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

Nov 17 '05 #2

P: n/a
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)

Jrgen Devlieghere
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
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

Nov 17 '05 #3

P: n/a
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

"Antti Keskinen" wrote:
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
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
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


Nov 17 '05 #4

P: n/a
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

"Jürgen Devlieghere" wrote:
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
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
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


Nov 17 '05 #5

P: n/a
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

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
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

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.