[try Beta version]
Not logged in

 
display address instead of value

Jul 12, 2019 at 9:56pm
hello, i'm making a trainer for a game and i want to display the address in a textbox instead of the value.
i have this so far:
 
textBox1->Text = Value.ToString();

this displays the value in the textbox, but i want it to display the address. any ideas?
Jul 12, 2019 at 11:13pm
This comes the question, the address of what?

What is Value?

That isn't std::string, so....

You could offer the address of Value, turned into a string (since textBox1 probably must take a string of some kind).

That comes back to what is Value?

Some classes store the data as members, some as pointers. What does Value use?

If Value stored data via pointer, the address of Value is that of the instance of the class, not of the data that pointer points to.

It can get complicated.

Jul 12, 2019 at 11:28pm
i see, is there any simple way without making it complicated?
Jul 12, 2019 at 11:32pm
Without knowing what type Value is, I can't even consider an answer.

If all you want is the address of the Value instance (which may or may not be what you really need), you could:

1
2
3
typedef unsigned long  ptr_type;

ptr_type p = reinterpret_cast< ptr_type >( &Value );


...then, use whatever you like to turn a number like unsigned long into a string using, likely, hex output.

Of course, exactly what type ptr_type should be typedef'd to be depends on the platform (32 or 64 bit pointers).

Bottom line, when you start working with pointers, you're working at the level of the CPU, and "simple" just isn't going to be part of that, most of the time.
Jul 12, 2019 at 11:33pm
the value is a 4 byte, which is int.
Jul 13, 2019 at 12:17am
....then what type allows that to call "ToString"?

Integers themselves don't have such a member function (or any member function).

If the value is 4 bytes (32 bits), that's fine, but that doesn't say what size a pointer is.

We need to know sizeof( &Value )
Last edited on Jul 13, 2019 at 12:21am
Jul 13, 2019 at 12:37am
The ToString() method is not a built-in C++ thing.
So either you wrote that or you are compiling using an additional library that provides that.
In your previous thread, you say Char::IsDigit(...). Again, unless you made this it had to come from something you are using in addition to C++.

What is your programming environment, framework, and/or additional libraries that you are using?
Last edited on Jul 13, 2019 at 12:37am
Jul 13, 2019 at 12:51am
im using .net c++/cli
the pointer is a DWORD, value is an int
Jul 13, 2019 at 1:27am
All bets are off.

Objects in .NET aren't stable - they move whenever garbage collection chooses. C++/CLI allows for pinning pointers, but they're only valid as long as you hold the pin. The concept of pointers in C++/CLI is not quite the same as generalized C++, and depending on what you're really doing, may be meaningless from one moment to the next.

Frankly, if you already new the answer in C++, you'd have some awareness of the nature of the C++/CLI from the switch to the "CLI" part, and you'd already know it probably isn't a valid rabbit hole to plunder.

My advise would be to learn C++ long before you dive into C++/CLI, lest you end up completely confused about C++ itself. Learning C++/CLI before mastery of C++ is learning two subjects at once, without clearly recognizing where one stops and the other takes over.

Last edited on Jul 13, 2019 at 1:30am
Topic archived. No new replies allowed.