waveInGetDevCaps

waveInGetDevCaps

Post by Mik » Thu, 13 Feb 2003 07:07:14



Are any of the waveInXXX APIs supported on the CF?

I have been having very little luck finding samples.

There are all sorts of samples in C++ and eVC, and many for waveOutXXX
for .Net, but not waveIn for CF.

Right now I am stuck on getting the device capabilities using
waveInGetDevCaps.
It returns a "Not Supported" error.

Here's the abridged code:

[ StructLayout( LayoutKind.Sequential)]
public struct WAVEINCAPS
{
        public short wMid;
        public short wPid;
        public int vDriverVersion;
        public string szPname;
        public int dwFormats;
        public short wChannels;

Quote:}

[ DllImport( "coredll.dll")]
private static extern int waveInOpen (ref int lphWaveIn, int
uDeviceID, ref WAVEFORMAT lpFormat, int dwCallback, int dwInstance,
int dwFlags);

[ DllImport( "coredll.dll")]
private static extern int waveInGetDevCaps (int uDeviceID, ref
WAVEINCAPS lpCaps, int uSize);

[ DllImport( "coredll.dll")]
private static extern int waveInGetNumDevs ();

[ DllImport( "coredll.dll")]
private static extern int waveInPrepareHeader (int hWaveIn, ref
WAVEHDR lpWaveInHdr, int uSize);

[ DllImport( "coredll.dll")]
private static extern int waveInStart (int hWaveIn);

public void GetDevice()
{
        //There is only one device on the PPC, but i used this anyway
        //to see if I can get it to work. It works.
        int deviceID = waveInGetNumDevs() - 1;

        //decalre the WAVEINCAPS to pass to the API
        WAVEINCAPS devCaps;

        //I read somewhere that the struct needs
        //to be initialized, so I did this:
        devCaps.dwFormats = 0;
        devCaps.szPname = "";
        devCaps.vDriverVersion = 0;
        devCaps.wChannels = 0;
        devCaps.wMid = 0;
        devCaps.wPid = 0;

        //It also requires a size of the struct, so I passed it
        //a large number so it will not cut it off
        //(?? What's the "Right" way??)

        int ret = waveInGetDevCaps(deviceID, ref devCaps, 1000);
//Fails here             ^

        //I guess I should then call these
        //waveInOpen
        //waveInPrepareHeader
        //waveInStart

Quote:}

 
 
 

waveInGetDevCaps

Post by Scott Holden [MSF » Fri, 28 Feb 2003 08:56:55


The .NET Compact Framework only has a limited support for p/invoke
marshaling. One of the limitations is that you can not p/invoke a struct
that contains a reference type. In this case, your WAVEINCAPS contains a
string reference.

From the question in your code about the right way to get the size...you
should use System.Runtime.InteropServices.Marshal.SizeOf(object) to get the
unmanaged size of the object.

Scott Holden
NET Compact Framework
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

Please do not send email directly to this alias. This alias is for newsgroup
purposes only. To correspond with me directly, remove the 'online' and
'news'
from my alias. This is to prevent automated spam to my alias.

--------------------


>Newsgroups: microsoft.public.dotnet.framework.compactframework
>Subject: waveInGetDevCaps
>Date: 11 Feb 2003 14:07:14 -0800
>Organization: http://groups.google.com/

>Are any of the waveInXXX APIs supported on the CF?

>I have been having very little luck finding samples.

>There are all sorts of samples in C++ and eVC, and many for waveOutXXX
>for .Net, but not waveIn for CF.

>Right now I am stuck on getting the device capabilities using
>waveInGetDevCaps.
>It returns a "Not Supported" error.

>Here's the abridged code:

>[ StructLayout( LayoutKind.Sequential)]
>public struct WAVEINCAPS
>{
>    public short wMid;
>    public short wPid;
>    public int vDriverVersion;
>    public string szPname;
>    public int dwFormats;
>    public short wChannels;
>}

>[ DllImport( "coredll.dll")]
>private static extern int waveInOpen (ref int lphWaveIn, int
>uDeviceID, ref WAVEFORMAT lpFormat, int dwCallback, int dwInstance,
>int dwFlags);

>[ DllImport( "coredll.dll")]
>private static extern int waveInGetDevCaps (int uDeviceID, ref
>WAVEINCAPS lpCaps, int uSize);

>[ DllImport( "coredll.dll")]
>private static extern int waveInGetNumDevs ();

>[ DllImport( "coredll.dll")]
>private static extern int waveInPrepareHeader (int hWaveIn, ref
>WAVEHDR lpWaveInHdr, int uSize);

>[ DllImport( "coredll.dll")]
>private static extern int waveInStart (int hWaveIn);

>public void GetDevice()
>{
>    //There is only one device on the PPC, but i used this anyway
>    //to see if I can get it to work. It works.
>    int deviceID = waveInGetNumDevs() - 1;

>    //decalre the WAVEINCAPS to pass to the API
>    WAVEINCAPS devCaps;

>    //I read somewhere that the struct needs
>    //to be initialized, so I did this:
>    devCaps.dwFormats = 0;
>    devCaps.szPname = "";
>    devCaps.vDriverVersion = 0;
>    devCaps.wChannels = 0;
>    devCaps.wMid = 0;
>    devCaps.wPid = 0;

>    //It also requires a size of the struct, so I passed it
>    //a large number so it will not cut it off
>    //(?? What's the "Right" way??)

>    int ret = waveInGetDevCaps(deviceID, ref devCaps, 1000);
>//Fails here             ^

>    //I guess I should then call these
>    //waveInOpen
>    //waveInPrepareHeader
>    //waveInStart

>}