|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
C# supports pointer."Rulin Hong" <RulinH***@discussions.microsoft.com> schrieb: C# supports pointers only inside 'unsafe' blocks which are only useful in > What do we do for pointer in VB.NET? 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/> "Crouchie1998" <crouchie1998@spamcop.net> schrieb hehe. :-))> Dim ptr As IntPtr Armin >> Dim ptr As IntPtr You guys are *evil*. Let me see some VB.NET code that dereferences ptr and > > hehe. :-)) 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" <mlab***@hotmail.com> schrieb dim b(499) as byte> > > Dim ptr As IntPtr > > > > hehe. :-)) > > You guys are *evil*. Let me see some VB.NET code that dereferences > ptr and I'll be impressed. Marshal.Copy(ptr, b, 0, 500) msgbox b(17) 'reference to b(17) ;-) Armin 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" | | 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 |
|||||||||||||||||||||||