看板 C_Sharp 關於我們 聯絡資訊
小弟想要在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)
taba:不會是少打雙引號和)吧? 10/28 20:21
pico2k:strId 不能是null 10/28 20:37
ljhgc:雙引那個是我在編輯不小心刪到,抱歉 10/28 21:30
ljhgc:不能是null,那應該用什麼? 我也有試過strId="",結果一樣 10/28 21:31
heyshi:strId=null 那你覺得imd.GetId(ref strId)會回傳啥啊?? 10/29 01:02
ljhgc:是我誤解嗎? 在C#理string不是類似指標嗎? strId應該會指到 10/29 11:03
ljhgc:id字串的位置不是嗎? 10/29 11:04
heyshi:http://0rz.tw/Ozxwy catch 你可以再接那兩個衍生例外 看看 10/29 12:11
ljhgc:謝謝h大的資料,但我不要是攔截ArgumentException,我目的 10/29 13:33
ljhgc:是要取得device Id, 我是有想到辦法繞過這個問題了,用 10/29 13:33
ljhgc:IntPtr去接,再把IntPtr指的位置轉成string 10/29 13:34