pointer in visual basic

  • Thread starter Thread starter srirajpaul
  • Start date Start date
S

srirajpaul

Is it posssible to get the address of a variable in visual basic
I mean something in c++ like
int *ptr;
int a=1;
ptr = &a;

thanks for any help that can be offered,
sriraj
 
Is it posssible to get the address of a variable in visual basic
I mean something in c++ like
int *ptr;
int a=1;
ptr = &a;

thanks for any help that can be offered,
sriraj

Well... Technically, yes you can. But why do you want it? There
really isn't a lot you can do with it once you have it anyway, and
anything you manage to do is likely to be dangerous anyway :)
 
Is it posssible to get the address of a variable in visual basic
I mean something in c++ like
int *ptr;
int a=1;
ptr = &a;

There is no direct equivalent.

Depending on the situation, one of the following solutions may apply:

* Use references instead of pointers (see: reference types, value types,
operators '=', 'Is', 'IsNot').

* Declare the parameter as 'ByRef' when using p/invoke.

* Use 'Marshal.Alloc*' to reserve an unmanaged block of memory and then
use 'Marshal.Write*'/'Marshal.Copy' to copy data to the memory area. Then
you can pass around the pointer pointing to the memory location.

* Use 'GCHandle.AddrOfPinnedObject' to pin a managed object in memory
(rarely useful).
 
Back
Top