On 2004-10-07, Sakharam Phapale <(E-Mail Removed)> wrote:
> Hi All,
> How to declare the following statement in following structure.
>
> szPname As String * MAXPNAMELEN
>
>
> Public Structure MIXERCAPS
> public wMid As Integer
> public wPid As Integer
> public vDriverVersion As Long
> public szPname As String * MAXPNAMELEN
> public fdwSupport As Long
> public cDestinations As Long
> End Structure
>
> Thanks and Regards.
> Sakharam Phapale.
>
>
Looking at the MSDN docs now...... Ok:
' Replace XX with correct value...
Public Const MAXPNAMELEN As Integer = XX
<StructLayout (LayoutKind.Sequential, CharSet := CharSet.Auto)> _
Public Structure MIXERCAPS
Public wMid As Short
Public wPid As Short
' You'll have to see what type MMVERSION really is,
' but from the description it sounds like a 2-byte integer
' also known as a WORD in API speak and a Short in VB.NET
Public vDriverVersion As Short
<MarshalAs (UnmanagedType.ByValTStr, SizeConst := MAXPNAMELEN)>
Public szPname As String
Public fdwSupport As Integer
Public cDestinations As Integer
End Structure
Be aware that VB6 declarations are not going to be valid for most API
calls. Data types have changed size. Here is a small table to sum up
the differences:
Data Type VB6 Size VB.NET Size
___________________________________
Byte 8-bit 8-bit
Short N/A 16-bit (same size as VB6 Integer)
Integer 16-bit 32-bit
Long 32-bit 64-bit
So, basically when calling api calls from VB.NET - use Short where you
used integer in VB6 and Integer where you used Long. You can use Long
where you would have used Currency in VB6.
Also, notice the CharSet attribute on the structure. This is done so
that it will be converted to the proper charset for the current
platform. This eliminates a lot of the problems with calling API calls
in VB6 - you couldn't call Unicode functions, at least not with out some
hacks

To use this structure in the function, the CharSet attribute
will have to be set there as well - but VB.NET Declare has a way of
handling that (I'm going to assume your using mixerGetDevCaps)...
Public Declare Auto Function mixerGetDevCaps Lib "winmm.dll" _
(ByVal uMxId As System.IntPtr, _
ByRef pmxcaps As MIXERCAPS, _
ByVal cbmxcaps As Integer) As Integer
By using the Auto clause of the declare statement we avoid having to
alias this function to the A version, because the runtime will call the
function most appropriate to the current platform - which is the W
version on NT based OS's.
--
Tom Shelton [MVP]