Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

global variable

Posted on 1998-08-21
11
Medium Priority
?
326 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
ID: 1337417
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
ID: 1337418
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
ID: 1337419
Not really pointer since the memory is not shared between instances. However, you can also share memory by mapping files in memory.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:rickpet
ID: 1337420
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
ID: 1337421
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
 
LVL 8

Expert Comment

by:Answers2000
ID: 1337422
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
ID: 1337423
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:Tom Knowlton
ID: 1337424
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 100 total points
ID: 1337425
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
ID: 1337426
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
ID: 1337427
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

886 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