-
March 16th, 2014, 09:21 PM
#1
2 programs, 1 dll sharing variable.
hello again, just wondering if you guys could help me again.
my goal:
have 1 program handle the UI
have that program store variables to a DLL
have the 2nd program grab the stored variables to reform some number crunching, without interfering with the UI program, and once done, have it drop the answers back into that DLL, so that the UI can grab it when it's ready.
I have made the 2 programs, + dll (sorry, there is a lot of code, so I won't post it, unless you have a theory, to wich I can post how I achieved, whatever it is your theory is about)
What I've Achieved:
the first program accesses the dll, and loads up a variable (and stays connected to the dll, so that the Dll instance doesn't reset)
I've gotten the DLL to output the variable to make sure it's received it, and stored it to it's own global variable.
the second program connects to the dll successfully, but when it tries to retrieve the data, it returns 0's (NULL's)
My research:
from what I've read, so long the dll is connected to a program, all additional programs will attach to the same instance.
how do I make the global variable in the dll be accessible to both programs? (without resorting to saving it to the HDD Idealy)
thank you!
-
March 17th, 2014, 06:11 AM
#2
Re: 2 programs, 1 dll sharing variable.
One way of doing this is with memory mapped files.
See http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
Another way is to use named data segments so that each process has access to the same named segment
See http://msdn.microsoft.com/en-us/library/thfhx4st.aspx
http://www.codeproject.com/Articles/...gment-in-a-DLL
http://msdn.microsoft.com/en-us/library/sf9b18xk.aspx
When I just want to share a few simple variables between processed, I tend to use named data segments.
Last edited by 2kaud; March 17th, 2014 at 06:14 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 17th, 2014, 08:00 AM
#3
Re: 2 programs, 1 dll sharing variable.
Originally Posted by peteandperry
store variables to a DLL
Technically speaking, you cannot store variables to a DLL. A DLL is just a collection of program code that can be shared between applications.
What you are looking for is globally allocated memory. Have a look here:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Nobody cares how it works as long as it works
-
March 17th, 2014, 11:59 AM
#4
Re: 2 programs, 1 dll sharing variable.
2kaud & zerver.
Thank you so much! look like any one of those will do the job perfectly!
thanks
-
March 19th, 2014, 04:22 AM
#5
Re: 2 programs, 1 dll sharing variable.
Best regards,
Igor
-
March 19th, 2014, 11:43 AM
#6
Re: 2 programs, 1 dll sharing variable.
-
March 20th, 2014, 07:47 AM
#7
Re: 2 programs, 1 dll sharing variable.
@Codeplug:
It's true, but it's also somewhat of a bogus argument. This will only protect you from unauthorised access from other windows users.
Oops, did that guy forget to mention that you can apply the same type of security descriptors on the DLL as you can on the mapped file. If user-level restriction is needed, then both the shared section in a dll and the mapped file can be protected.
But yes, shared memory has several issues, regardless of how you try to protect it.
THe DLL shared section can be an issue on a terminal server with multiple users havign active desktop sessions on the same machine at the same time. But without care, even the mapped file will have issues with this.
ANd with the right tools and capabilities, you can make any exe do just about anything you want. Give a capable user a proper debugger and a basic compiler, and they can do all sorts of nasty stuff if they get enough privileges on the machine.
something to Always be aware of
-
March 20th, 2014, 07:50 AM
#8
Re: 2 programs, 1 dll sharing variable.
@Codeplug:
It's true, but it's also somewhat of a bogus argument. This will only protect you from unauthorised access from other windows users.
Oops, did that guy forget to mention that you can apply the same type of security descriptors on the DLL as you can on the mapped file. If user-level restriction is needed, then both the shared section in a dll and the mapped file can be protected.
But yes, shared memory has several issues, regardless of how you try to protect it.
THe DLL shared section can be an issue on a terminal server with multiple users havign active desktop sessions on the same machine at the same time. But without care, even the mapped file will have issues with this.
ANd with the right tools and capabilities, you can make any exe do just about anything you want. Give a capable user a proper debugger and a basic compiler, and they can do all sorts of nasty stuff if they get enough privileges on the machine.
something to Always be aware of
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|