Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

global variable

Posted on 1998-08-21
11
Medium Priority
?
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

722 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