Solved

global variable

Posted on 1998-08-21
11
316 Views
Last Modified: 2010-08-05
How can i under D3 in WIN95/WIN NT4.0 define a global variable ?
I have several exe-files. The first one will create the global variable and set to an integer.
When the next exe-file is started it will ask the global variable and depending on its value do something.
 
0
Comment
Question by:titz
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
You can't make a variable global between different programs.

I suggest you write
1. the variable out to a file (e.g. an INI file), database
or
2. pass the value on the command line (given to the 2nd program when you run it)
or
3.  Wait until 2nd program starts, then 1st program talked to it via DDE, OLE or another protocol.

#2 is probably best for you - quickest and easiest
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
As Answers2000 mentioned that's a solution and maybe the one that doesn't need much coding..., but if you want it to be without any files this can be done only using pointers...At least that's what I think so..Crrect me if I'm wrong =)

/Viktor
0
 
LVL 1

Expert Comment

by:pjdb
Comment Utility
Not really pointer since the memory is not shared between instances. However, you can also share memory by mapping files in memory.
0
 
LVL 3

Expert Comment

by:rickpet
Comment Utility
Why not just send a custom message back and forth???simplier than memory mapped file...cleaner than registry/ini file

Rick
0
 
LVL 1

Author Comment

by:titz
Comment Utility
i want not to write to a file, because this can make problems.  e.b. if the pc is turned off (without shut down), or loss of voltage.
The 2nd program will not run parallel to the first, perhaps after the first. Therefore i was looking for such a thing like a global variable in memory.

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
I really suggest this solution
2. pass the value on the command line (given to the 2nd program when you run it)

If you really want to share a variable between programs you need to use some form of IPC (interprocess communication), which includes DDE, OLE, Pipes etc.  The other option is to use some form of shared memory, but you will have synchronozation problems(what happens if one program changes the value while the other program accesses it), and this involves a fair amount of code.


0
 
LVL 1

Expert Comment

by:Greedy
Comment Utility
Check out the WIN32 help file on Global Atom Table
I really don't have a clue what they would be used for as I have never used one...but it might get you into what you need ??

The Windows global atom table, which can contain up to 37 entries, is available to all applications. When an application places a string in the global atom table, the system generates an atom that is unique throughout the system. Any application that has the atom can obtain the string it identifies by querying the global atom table.

An application that defines a private clipboard-data format or DDE-data format for sharing data with other applications should place the format name in the global atom table. This technique prevents conflicts with the names of formats defined by the system or by other applications, and makes the identifiers (atoms) for the messages or formats available to the other applications.
0
 
LVL 5

Expert Comment

by:knowlton
Comment Utility
How often will this GLOBAL variable be "created"...once at the beginning of execution or at the user's request, or what?  I think writing the file out to an .INI is your best bet, here.  The file I/O should be almost instantaneous...so power outages would be your least concern...the timing on that would have to be near perfect.
0
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
Comment Utility
The idea in this case is to use some predefined memory block for storing shared variables between two apps. Here is a component that eases the task (a good example included):

http://bes.trendline.co.il/torry/vcl/system/sharedmm.zip

Also you can write the value in the registry. Here is a simple component:

http://bes.trendline.co.il/torry/vcl/system/arregvar.zip

--Matvey
0
 
LVL 1

Author Comment

by:titz
Comment Utility
i will try .
but i think that rickpet's comment shows the best way.
But i do not know how i can give him points ??
thanks for all who thought  about this problem
titz

0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
If you wanted to give te points to someonme else, you should have rejected my answere and not award the points to me.

I was hoping I at least understood the question right: you need a way to store shared variables between two apps. My answere does answere this question, but if you wanted something else, or some other solution - my apologies...

c u, Matvey
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now