日期:2014-05-17  浏览次数:20899 次

mixerGetLineInfo 得不到返回的结构体的字符串内容??
想做一个XP下的音量控制方面的程序。是通过一个MFC的代码改的,但是刚到 函数mixerGetLineInfo 时就不对了...不知如何修改... 求帮助~~~

下面分别贴上 C#里面的代码 和 MFC下的代码 以及他们的执行效果图。

MFC的一段代码和效果图 如下:
要加上
#include <mmsystem.h>
#pragma comment(lib,"Winmm.lib")

void C_mfc_vc6Dlg::OnButton1() 
{
m_hMixer = NULL;
::ZeroMemory(&m_mxcaps, sizeof(MIXERCAPS));

if (m_nNumMixers != 0)
{
if (::mixerOpen(&m_hMixer,
0,
reinterpret_cast<DWORD>(this->GetSafeHwnd()),
NULL,
MIXER_OBJECTF_MIXER | CALLBACK_WINDOW)
!= MMSYSERR_NOERROR)
{
::MessageBox(this->GetSafeHwnd(), "mixerOpen failed", "", 0);
return;
}

if (::mixerGetDevCaps(reinterpret_cast<UINT>(m_hMixer),
  &m_mxcaps, sizeof(MIXERCAPS))
!= MMSYSERR_NOERROR)
{
::MessageBox(this->GetSafeHwnd(), "mixerGetDevCaps failed", "", 0);
return;
}
}

if (m_hMixer == NULL)
{
::MessageBox(this->GetSafeHwnd(), "m_hMixer == NULL", "", 0);
return;
}

// get dwLineID
MIXERLINE mxl;
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
if (::mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(m_hMixer),
   &mxl,
   MIXER_OBJECTF_HMIXER |
   MIXER_GETLINEINFOF_COMPONENTTYPE)
!= MMSYSERR_NOERROR)
{
::MessageBox(this->GetSafeHwnd(), "mixerGetLineInfo failed", "", 0);
return;
}

char buf[128] = {0};
sprintf(buf, "%X, %d", mxl.dwLineID, mxl.dwLineID);
::MessageBox(0, mxl.szName, buf, 0);
}



C# 的一段代码和效果图 如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace _cs_test
{
    public partial class Form1 : Form
    {
        public const uint MAXPNAMELEN = 32;
        public const uint CALLBACK_WINDOW = 0x00010000;
        public const uint MIXER_OBJECTF_MIXER = 0x00000000;
        public const uint MMSYSERR_NOERROR = 0;
        public const uint MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = 4;
        public const uint MIXER_OBJECTF_HANDLE = 0x80000000;
        public const uint MIXER_OBJECTF_HMIXER = (MIXER_OBJECTF_HANDLE | MIXER_OBJECTF_MIXER);
        public const uint MIXER_GETLINEINFOF_COMPONENTTYPE = 0x00000003;
  &n