Programms memory adress location access?

T

TIM

for example i have one simple programm

int main()
{
int test = NULL;
while(1){
printf("%d\n",test);
getch();
test++;
}
return 0;
}

After compiling and running it, i want to access to its memory adress
location(under windows) from other programm(which i want to write, but
dont know how or better say, from to start :)) and find this "test"
variable and change its value during programm run-time. How i can do it
from external programm written in C++? Any help would be appreciated. THX.
 
R

Rob Williscroft

TIM wrote in in comp.lang.c++:
for example i have one simple programm

int main()
{
int test = NULL;
while(1){
printf("%d\n",test);
getch();
test++;
}
return 0;
}

After compiling and running it, i want to access to its memory adress
location(under windows) from other programm(which i want to write, but
dont know how or better say, from to start :)) and find this "test"
variable and change its value during programm run-time. How i can do
it from external programm written in C++? Any help would be
appreciated. THX.

Alas Standard C++, has nothing to say about accesing data or code
in *other* programmes.

You should ask this in a windows programming newsgroup say:

comp.os.ms-windows.programmer.win32

<off-topic>

You should IMO rethink your question, what you ask above can only
really be done by a debugger, which will require a programme
compiled with debuging information, if this is what you want to
do ask about it directly, also such things are not only os specific
but compiler specific, so ask in a newsgroup that supports your
compiler.

Some terms you might want to google up on:

IPC - Inter Process Communications
RPC - Remote Procedure Calls
COM - Component Object Model (win32 /mostly/)

</off-topic>

HTH.

Rob.
 
J

Jeff Schwab

TIM said:
for example i have one simple programm

int main()
{
int test = NULL;
while(1){
printf("%d\n",test);
getch();
test++;
}
return 0;
}

After compiling and running it, i want to access to its memory adress
location(under windows) from other programm(which i want to write, but
dont know how or better say, from to start :)) and find this "test"
variable and change its value during programm run-time. How i can do it
from external programm written in C++? Any help would be appreciated. THX.

Sorry, there's no standard way to do this in C++. Try asking in a
Windows group.
 
K

Kevin Goodsell

TIM said:
for example i have one simple programm

int main()
{
int test = NULL;

NULL is undeclared (and if it were defined the usual way, it would be
very strange to assign it to an int).
while(1){
printf("%d\n",test);
getch();

Neither of these functions are declared, so this should not compile.

This will eventually overflow, giving undefined behavior.
}
return 0;
}

-Kevin
 
A

Alf P. Steinbach

* Kevin Goodsell said:
NULL is undeclared (and if it were defined the usual way, it would be
very strange to assign it to an int).

Uhm, Kevin, this is [comp.lang.c++] you're replying in. I agree that it
is strange to use NULL in such a context, but in C++ the strangeness does
not flow from the definition of NULL, which is required to be 0 (unfortunate
in my opinion, but that's the way it turned out in the standards battle). In
C++ the strangeness flows only from convention and perhaps aesthetics.
 
K

Kevin Goodsell

Alf said:
* Kevin Goodsell said:
NULL is undeclared (and if it were defined the usual way, it would be
very strange to assign it to an int).


Uhm, Kevin, this is [comp.lang.c++] you're replying in. I agree that it
is strange to use NULL in such a context, but in C++ the strangeness does
not flow from the definition of NULL, which is required to be 0 (unfortunate
in my opinion, but that's the way it turned out in the standards battle). In
C++ the strangeness flows only from convention and perhaps aesthetics.

Yes, what I said wasn't really what I meant. What I meant was that
'NULL' could be some identifier that the OP created, e.g.

int NULL = 7;

In which case the code wouldn't be completely weird (though using NULL
as an identifier declared in your program is probably a bad idea, since
it is likely to conflict with the standard NULL).

If, on the other hand, the NULL in question was supposed to be the
standard NULL, then it's strange to use it with ints, since it is
intended to represent a null pointer.

-Kevin
 
?

=?iso-8859-2?Q?Rados=B3aw?= Grzanka

* Kevin Goodsell said:
NULL is undeclared (and if it were defined the usual way, it would be
very strange to assign it to an int).

Uhm, Kevin, this is [comp.lang.c++] you're replying in. I agree that it
is strange to use NULL in such a context, but in C++ the strangeness does
not flow from the definition of NULL, which is required to be 0 (unfortunate
in my opinion, but that's the way it turned out in the standards battle). In
C++ the strangeness flows only from convention and perhaps aesthetics.

I thought NULL is platform dependend.. At least Bjarne Stroustrup writes
so.

Best Regards,
Radek.
 
K

Kevin Goodsell

Rados³aw Grzanka said:
I thought NULL is platform dependend.. At least Bjarne Stroustrup writes
so.

NULL expands to an implementation-defined null pointer constant. But
that's a very narrow category -- it must be an integer constant
expression with the value 0. So it could be (1 - 1) or (!!!!!!!1), but
realistically you are unlikely to find NULL defined as something other
than 0 or 0L (or something very similar).

You might be confusing NULL (a standard macro) and null pointer
constants with the concept of a pointer that is null. A null pointer
constant (such as NULL, or 0) when converted to a pointer, gives a null
pointer. The representation used for a null pointer is undefined, so
could vary from system to system. In other words, a pointer to address 0
may or may not be a null pointer, but an integer constant expression
with the value 0, when converted to a pointer, must be translated to a
null pointer (even if that means that it becomes something like 0xFF00FF00).

-Kevin
 
T

TIM

Kevin said:
NULL is undeclared (and if it were defined the usual way, it would be
very strange to assign it to an int).



Neither of these functions are declared, so this should not compile.



This will eventually overflow, giving undefined behavior.


-Kevin
LOL i just havent written here include files
#include <iostream>
#include <conio.h>
there is all declarations(and will compile without a problem), but
anyway thats not the question i aksed.
thx.
i just wanted to make programm such ARTMOBNEY if you heard of it...
 
K

Kevin Goodsell

TIM said:
LOL i just havent written here include files
#include <iostream>
#include <conio.h>
there is all declarations(and will compile without a problem), but
anyway thats not the question i aksed.

When posting code you should always post the *complete* code (check the
FAQ, section 5 for a more detailed discussion of how to post code). It
looks like your question was already answered. I was just commenting on
the problems with the code you posted.

For future reference <conio.h> is not standard C++, so you should not
use it in portable programs or include it in code posted here.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top