|
-
Oct 9th, 2001, 07:44 AM
#1
Thread Starter
Fanatic Member
pointers in vb ?
Ive had .net for a few weeks now and only really just started to use it. vb.net has become alot more like visual c++ now which i think is a plus. Some of the new code changes like the returns for functions, try catch, and the new string variables are just plain awsome, but does it support pointers?
If it dont then that would be a big downside to the program, ok so it would have a very steep learning curve but in the long run i think it would be a more succesful programming language with pointers implemented. ( Imagine vb apps with 'proper' plugin support? wow )
oh, off topic, does vb7 still require runtimes? i know it requires framenet but so does vc.net, right?
-
Oct 9th, 2001, 10:45 AM
#2
No VB.Net doesn't have pointers, and I don't agree with you about the fact that the lack of pointers is a downside to the language. Personally, and I am an old C/C++ programmer, I think pointers is terrible. All modern languages exclude the use of pointer, even C# haven't included them (you don't have to tell me that you actually can use pointers in C# if you mark the project as unmanaged).
And the CLR is the run-time files. If they are installed you can install your application with XCopy if you like.
-
Oct 19th, 2001, 05:48 AM
#3
New Member
you might notice that by default when declaring a sub you see a by val in there (or something to that effect) the closest you will get to pointers would be changing it to by ref . of course, those would be by value, and by reference, respectively...it is not really a pointer, but well bah, you are a c/c++ programmer you get the idea
-
Oct 23rd, 2001, 08:15 AM
#4
You can use pointers in vb.net!!
I will post an example as soon as I get home.
There are things to keep in mind though.
You first need to pin the variable, because otherwise the garbage collector could move the contents to a different location (the garbage collector compacts the memory, a sort of defragmentation)
-
Oct 23rd, 2001, 11:23 AM
#5
OK, here we go.
Make sure to import the interopservices:
Code:
Option Explicit On
Imports System.Runtime.InteropServices
and then wherever you need it something like this
Code:
Dim sSample As String = Space(128) ' this is the variable we get the pointer for
' pin variable and create
' GC handle instance
Dim gh As GCHandle = GCHandle.Alloc(sSample , GCHandleType.Pinned)
' get address of variable
Dim ptrRet As IntPtr = gh.AddrOfPinnedObject()
' OK, now ptrRet contains your pointer.
' Please be aware that an IntPtr is an integer on a 32 bit OS and a Long on a 64 bit OS
' So ptrRet.ToInt32 will cause an overflow on a 64 bit OS
' do not forget to free the handle and unpin variable
' so garbage collector can do it's work
gh.Free()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|