Results 1 to 3 of 3

Thread: Syntax Question (I think)

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    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 2012
    Posts
    8,245

    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
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width