using pointers in vb.net

JoshK

Newcomer
Joined
Apr 12, 2006
Messages
10
Location
Akron, OH
Anyone know if it is possible to use 'pointers' in vb.net to read and write to another program's memory stack as you can in c++. If anyone could give me a quick rundown or point me to a good resource on doing this it would be most appreciated
 
This is a very advanced topic, and I'm not too sure that you are going to find a satisfactory answer here. This is certainly not the type of thing that .Net is designed for. The most reasonable approach, I would think, is to create a DLL in C++ that can be consumed by VB if, for some reason, you need the front end of the application to be .Net.

That being said, have you actually done this in C++? If so, what specific issue(s) have you run into trying to do this in VB? Obviously, VB does not have direct support for pointers, but pointer operations can generally be performed via the Windows API.
 
Unsafe Keyword

You can't do this directly in VB.Net. Marble's two suggestions look quite promising, but they aren't nearly as easy as pointers in C++. .Net is really designed to prevent those sorts of things from happening (and one of the biggest criticisms of VB.Net is the lack of ability to do pointers at any level). That's the managed part of .Net. In fact, I think there might also be further safety checks that cause a .Net app to dump if you somehow manage to overwrite part of its stack or the stack is compromised in some way but I'd have to check up on that.

Probably the best option might be to write a .Net DLL in either C# or C++.Net (then you won't have to extern the library as you would with a Win32 DLL written in C++) and use it in a VB.Net program. You can get direct access to memory/pointers (basically as you are used to coming from C++) in C# with the unsafe keyword.
 
thats what I though also, but I keep seeing people or articles that say you can. example, read this:
http://www.123aspx.com/redir.aspx?res=31302

he shows, although I havn't tried it yet, that you can read and write directly to the heap with marshal.

I'm asking, because I work for a MMO currency seller, for some games someone has developed apps in c++ that has the offset to a certain games money variable. So then when we deliver gold to our customer, the app sees it and reports back to a DB for inventory tracking. I already know VB.net, and the whole point of this thread is to see if it is possible to do the same thing in VB. I know you say no, but I just want to make sure before I devote time to learning c# or c++

It's ok if I cant do it in vb, but in that case would c# be ok for doing this or would i be better off in the long run to learn c++.

Note, I cant remember where I read it, but I think I heard somewhere that in c# you can use pointers, but it is impossible to have a pointer to a memory address outside of the c# program's own memory space, meaning I couldn't get to the game memory space to get the value, is that true??
 
System.Marshal allows access to the managed heap (and maybe other memory, not sure), but I would have to assume that it performs certain saftey checks to help ensure that what you do is legit (meaning it doesn't pose a threat to the managed environment or security). C# does have pointers but they are crippled. I am pretty sure that they are only allowed to point to value type objects on the managed heap, and exist mainly for the purpose of speeding things up when it comes to arrays of structs.

As mskeel made a point of, .Net is designed to work in a "Managed Environment" which specificly does not require, and therefore intentionally restricts, potentially unsafe operations such as direct pointer access. In VB (and even C# for the most part) they lock pointers up and throw away the key. C++ on the other hand, is designed for exactly this kind of thing.

If you really want to try this in VB, then consider the methods I recommended above. I don't even know if they will work, but I'm guessing that it would be your best bet if you don't want to get your hands too dirty.
 
Back
Top