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.
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!
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:
<Category("Appearance")>
Public Property Text() As String
'...
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.