Results 1 to 3 of 3

Thread: Syntax Question (I think)

  1. #1
    Hyperactive Member Poppa Mintin's Avatar
    Join Date
    Mar 09
    Location
    Near Lincoln, Lincolnshire, England.
    Posts
    314

    Syntax Question (I think)

    Hi,

    Can you tell me please the meaning and purpose of " <MarshalAs(UnmanagedType.U4)> " in the following code?


    Code:
    Private Declare Function mixerOpen Lib "winmm.dll" _
            (ByRef phmx As Integer, <MarshalAs(UnmanagedType.U4)> ByVal uMxId As Integer, ByVal _
            dwCallback As Integer, ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
    In particular the purpose of anything between the 'Less than' and 'Greater than' characters.

    Poppa.
    Last edited by Poppa Mintin; Aug 12th, 2012 at 11:15 AM. Reason: Spelling !
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,546

    Re: Syntax Question (I think)

    Marshal Class

    Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code.


    In other words it prevents functions outside the usual scope of the vb.net environment breaking stuff!

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,860

    Re: Syntax Question (I think)

    The chevrons are used to denote an attribute. There are many more attributes than just MarshalAs and they are used for many and varied purposes. For instance, the way you see properties displayed in the Properties window for a control is determined by several attributes. For instance, the Text property of a control is listed in the Appearance section of the Properties window, which is achieved by declaring the property like this:
    vb.net Code:
    1. <Category("Appearance")>
    2. Public Property Text() As String
    3.     '...
    4. End Property
    Attributes are metadata, i.e. they are not part of the type or member itself but they are information about the type or member. In your example, the attribute determines how that member is mapped to and from unmanaged code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •