[問題] ArgumentException

看板C_Sharp作者 (是嚮往亦或逃避)時間15年前 (2010/10/28 19:27), 編輯推噓3(308)
留言11則, 4人參與, 最新討論串1/1
小弟想要在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)

10/28 20:21, , 1F
不會是少打雙引號和)吧?
10/28 20:21, 1F

10/28 20:37, , 2F
strId 不能是null
10/28 20:37, 2F

10/28 21:30, , 3F
雙引那個是我在編輯不小心刪到,抱歉
10/28 21:30, 3F

10/28 21:31, , 4F
不能是null,那應該用什麼? 我也有試過strId="",結果一樣
10/28 21:31, 4F

10/29 01:02, , 5F
strId=null 那你覺得imd.GetId(ref strId)會回傳啥啊??
10/29 01:02, 5F

10/29 11:03, , 6F
是我誤解嗎? 在C#理string不是類似指標嗎? strId應該會指到
10/29 11:03, 6F

10/29 11:04, , 7F
id字串的位置不是嗎?
10/29 11:04, 7F

10/29 12:11, , 8F
http://0rz.tw/Ozxwy catch 你可以再接那兩個衍生例外 看看
10/29 12:11, 8F

10/29 13:33, , 9F
謝謝h大的資料,但我不要是攔截ArgumentException,我目的
10/29 13:33, 9F

10/29 13:33, , 10F
是要取得device Id, 我是有想到辦法繞過這個問題了,用
10/29 13:33, 10F

10/29 13:34, , 11F
IntPtr去接,再把IntPtr指的位置轉成string
10/29 13:34, 11F
文章代碼(AID): #1CoLucve (C_Sharp)