作者ljhgc (是向往亦或逃避)
看板C_Sharp
标题[问题] ArgumentException
时间Thu Oct 28 19:27:30 2010
小弟想要在win7底下作音量控制
我使用了这里的code
http://www.java2s.com/Code/CSharp/Windows/SoundUtils.htm
我又另外在public class EndpointVolume加上一个function
public string GetCurrentDeviceId()
{
string strId = null;
try
{
int retVal = imd.GetId(ref strId);
if (retVal != 0)
throw new Exception(string.Format("IMMDevice.GetId() failed!);
return strId;
}
catch (Exception ex)
{
throw ex;
}
}
想要去抓取现在device的 ID值
可是都会出现
System.ArgumentException: Value does not fall within the expected range.
请问有人知道这是为什麽会这样吗? 又该如何解决
小弟我被这exception卡了好几天
麻烦各位指教了~谢谢
※ 编辑: ljhgc 来自: 220.130.148.139 (10/28 19:30)
1F:推 taba:不会是少打双引号和)吧? 10/28 20:21
2F:→ pico2k:strId 不能是null 10/28 20:37
3F:→ ljhgc:双引那个是我在编辑不小心删到,抱歉 10/28 21:30
4F:→ ljhgc:不能是null,那应该用什麽? 我也有试过strId="",结果一样 10/28 21:31
5F:推 heyshi:strId=null 那你觉得imd.GetId(ref strId)会回传啥啊?? 10/29 01:02
6F:→ ljhgc:是我误解吗? 在C#理string不是类似指标吗? strId应该会指到 10/29 11:03
7F:→ ljhgc:id字串的位置不是吗? 10/29 11:04
9F:→ ljhgc:谢谢h大的资料,但我不要是拦截ArgumentException,我目的 10/29 13:33
10F:→ ljhgc:是要取得device Id, 我是有想到办法绕过这个问题了,用 10/29 13:33
11F:→ ljhgc:IntPtr去接,再把IntPtr指的位置转成string 10/29 13:34