C# supports pointer.

  • Thread starter Thread starter Guest
  • Start date Start date
Rulin Hong said:
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?
 
Dim ptr As IntPtr

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"
 
Mike Labosh said:
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
 
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" <[email protected]> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ ×
ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:[email protected]...
 
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

| >> 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"
|
|
 

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

Back
Top