Home All Groups Group Topic Archive Search About
Author
27 Jun 2005 5:46 PM
Rulin Hong
What do we do for pointer in VB.NET?

Thanks

Author
27 Jun 2005 6:03 PM
Herfried K. Wagner [MVP]
"Rulin Hong" <RulinH***@discussions.microsoft.com> schrieb:
> What do we do for pointer in VB.NET?

C# supports pointers only inside 'unsafe' blocks which are only useful in
some very rare cases.  VB.NET gladly doesn't support them.  What do you want
to archieve?

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jun 2005 6:05 PM
Crouchie1998
Dim ptr As IntPtr

Crouchie1998
BA (HONS) MCP MCSE
Author
27 Jun 2005 6:39 PM
Armin Zingler
"Crouchie1998" <crouchie1998@spamcop.net> schrieb
> Dim ptr As IntPtr

hehe. :-))

Armin
Author
27 Jun 2005 10:41 PM
Mike Labosh
>> Dim ptr As IntPtr
>
> hehe. :-))

You guys are *evil*.  Let me see some VB.NET code that dereferences ptr and
I'll be impressed.

--
Peace & happy computing,

Mike Labosh, MCSD

"Mr. McKittrick, after very careful consideration, I have
come to the conclusion that this new system SUCKS."
-- General Barringer, "War Games"
Author
28 Jun 2005 12:29 AM
Armin Zingler
"Mike Labosh" <mlab***@hotmail.com> schrieb
> > > Dim ptr As IntPtr
> >
> > hehe. :-))
>
> You guys are *evil*.  Let me see some VB.NET code that dereferences
> ptr and I'll be impressed.

dim b(499) as byte
Marshal.Copy(ptr, b, 0, 500)

msgbox b(17)    'reference to b(17)

;-)


Armin
Author
28 Jun 2005 2:03 PM
Jay B. Harlow [MVP - Outlook]
Mike,
As Armin suggests, there are a number of methods on
System.Runtime.InteropServices.Marshal class that allows you to dereference
an IntPtr.

Marshal.Read* & Marshal.Write* may be "better" to use then Marshal.Copy. I
find Marshal.PtrToStructure & Marshal.StructureToPtr to be extremely useful
in some interop cases.

Of course Marshal.PtrToString* & Marshal.StringTo* are invaluable when
dealing with strings.

I've even used Marshal.GetObjectForIUnknown once or twice...

Hope this helps
Jay

Show quoteHide quote
"Mike Labosh" <mlab***@hotmail.com> wrote in message
news:%232z2sl2eFHA.584@TK2MSFTNGP15.phx.gbl...
| >> Dim ptr As IntPtr
| >
| > hehe. :-))
|
| You guys are *evil*.  Let me see some VB.NET code that dereferences ptr
and
| I'll be impressed.
|
| --
| Peace & happy computing,
|
| Mike Labosh, MCSD
|
| "Mr. McKittrick, after very careful consideration, I have
| come to the conclusion that this new system SUCKS."
| -- General Barringer, "War Games"
|
|
Author
28 Jun 2005 11:13 AM
Dragon
Hello Rulin,

If you have an variable and you want its address:
~
Dim GCH as GCHandle = GCHandle.Alloc(YourVar, GCHandleType.Pinned)
REM now GCH.AddrOfPinnedObject is pointer to your var so do whatever you
want
GCH.Free()
~

On the other hand, if you have an address, you can get a value:
~
DesiredValue = CType(Marshal.PtrToStructure(YourPointer,
DesiredValue.GetType), TypeOfDesiredValue)
~
Note that this time you actually get COPY of the value.

Marshal and GCHandle are located in System.Runtime.InteropServices
namespace.

Hope this helps

Dragon

"Rulin Hong" <RulinH***@discussions.microsoft.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ ×
ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
Show quoteHide quote
news:46643BD9-8CD2-4085-B1C9-F26CD1F6DFB0@microsoft.com...
> What do we do for pointer in VB.NET?
>
> Thanks