[問題] console模式下 使否有類似WndProc的方法取得message?

看板C_Sharp (C#)作者 (阿維)時間7年前 (2017/09/15 13:45), 編輯推噓1(108)
留言9則, 3人參與, 最新討論串1/1
這問題困擾我好久 希望知道的高手能夠指點一下 問題: 原本有一個C#視窗程式 這個程式呼叫別人寫的API [DllImport(@"..\API.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool GetInformation(IntPtr app ); 呼叫這個API 他就會把一些資訊用Message回傳 並且將一些參數 或是特定資訊紀錄在Msg LParam WParam 等等 為了要取得這些資訊 在視窗程式中會去複寫WndProc這個方 去取得Message 並且過濾只拿GetInformation所回傳的訊息: protected override void WndProc(ref Message m) { if (m.Msg == APIMessage) { int wParam = m.WParam.ToInt32(); int lParam = m.LParam.ToInt32(); switch (wParam) { case (int)...... break; .... } } base.WndProc(ref m); } 我的問題是 今天如果我採用console模式去呼叫API 我想請問 在console模式下 使否有類似WndProc 這樣的方法 可以去取得呼叫API後所回傳的Message呢??? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.96.158.75 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1505454305.A.D13.html

09/17 16:10, , 1F
我試了 最後都得到Error: Access is denied.
09/17 16:10, 1F

09/18 16:16, , 2F
請問您是用怎樣方法 可以分享一下嗎
09/18 16:16, 2F

09/18 17:03, , 3F
The console window belongs to the CSRSS process, not
09/18 17:03, 3F

09/18 17:03, , 4F
the CMD.EXE process. CSRSS is a critical system servic
09/18 17:03, 4F

09/18 17:04, , 5F
that is protected and cannot be hooked without special
09/18 17:04, 5F

09/18 17:04, , 6F
debug privileges.
09/18 17:04, 6F

09/18 17:08, , 7F
我是用 user32::SetWindowProc
09/18 17:08, 7F

11/03 14:01, , 8F
如果用console呼叫一個隱藏的winform,那個winform接受wn
11/03 14:01, 8F

11/03 14:01, , 9F
dproc呢?
11/03 14:01, 9F
文章代碼(AID): #1PksZXqJ (C_Sharp)
文章代碼(AID): #1PksZXqJ (C_Sharp)