I suggest you ...

Allow Unsafe Code and Pointers in VB.

Make it so pointers can be cast in unsafe contexts for complex interop coding ...

Public Unsafe Function x(y as SomeStruct) As ResultStruct
Dim p As Object? ' use Object? as an alternative to (void *)
p = InteropCall(y?) ' use ? to get the address of something.
Return CType(@p, ResultStruct) ' use @ to dereference.
End Function

89 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Nathaniel Moschkin shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

Thanks for taking the time to share this suggestion. This item has been around for a couple of versions of Visual Studio and we haven’t acted on it. Looking at the VS “15” plans, we’re not going to take action on this item, so we’re going to close it. If the suggestion is still relevant, please either take a look to see if there’s another suggestion that’s similar that you can vote on, or open a new suggestion.

- The Visual Studio Team

4 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Edin Omeragic commented  ·   ·  Flag as inappropriate

    Using generic Pointer like suggested @Richter03, but i think that adding unsafe keyword and options to enable unsafe code like in c# is annoying, it something that can be handled by analyzers.

  • Richter03 commented  ·   ·  Flag as inappropriate

    I think it isn't good idea to adapt those syntax from C family, it will be confusing like Nathaniel said.
    In vb language, I love to see it like this.

    'Pointer is structure that content object's address and object type signature.
    Dim ObjPoint As Pointer(Of Object) = AddressOf MyObject

    'select field of object can support by Intellisense.
    Dim FieldPoint As Pointer(Of Integer) = ObjPointer.MyFirstField

    Dim Value As Integer = FieldPoint.Value

    Dim ArrayPoint As Pointer(Of Long()) = AddressOf MyArray

    'move address 8 bytes as size of array member and set value of that address to 10.
    ArrayPoint.Index.Next().Set = 10

    'Something more advance, like convert Integer to byte array.

    Dim Contain(3) As Byte
    Dim BytesArray As Pointer(Of Byte()) = AddressOf Contain
    BytesArray.Index.Indirect.Set(Of Integer) = &HF0F1F2F3

    'Contain = {240, 241, 242, 243}

  • Nathaniel Moschkin commented  ·   ·  Flag as inappropriate

    Or maybe just use the & and * characters as in C, if the ? will be confusing. Possibly a more appropriate syntax for the cast would be @CType(p, ResultStruct?)

Feedback and Knowledge Base