2013年1月28日 星期一

shell extension 不工作並且 QueryInterface 收到 IID_IMarshal 等等奇怪的參數

在撰寫 shell extension 遇到一個問題
看起來我的 COM server 程式似乎沒有錯 但就是不工作
後來發現我的 QueryInterface 被 windows shell 呼叫好多次
參數是奇怪的 IID_IMarshal 之類參數
上網查了一下才發現是因為忘了註冊 threadingmodel
在這邊
設定好 threadingmodel 後就能正常工作了

Windows shell and desktop windows layer

Linux 原生是文字界面 它的 shell 是文字介面的例如 bash shell
Windows 是原生支援圖形介面的系統 它的 shell 也是圖形介面的 就是 explorer.exe

在螢幕上看到的東西都是屬於 explorer 創造出來的 window
下圖可以顯示 explorer 的階層



progman 就是 explorer 創建出來的頂層視窗 用 GetShellWindow API 可以取得它的 Handle
它的 class name 就是 "progman"

但是其實在 progman 之上還有一個最頂層 window 它被 progman 覆蓋所以看不到
這個 window 就是 desktop window 它是一個特殊的 系統定義的視窗 是所有其他視窗的祖先
GetDesktopWindow API 可以取得它的 Handle
這個 window 是被 csrss.exe 創造出來的
它的 class name 是 "#32769"

系統中一些重要元件例如 taskbar or desktop 都是被 explorer 創建出來的 window
是 progman 的後代

reference:
http://stackoverflow.com/questions/1669111/how-do-i-get-the-window-handle-of-the-desktop
http://blogs.microsoft.co.il/blogs/pavely/archive/2011/06/18/getshellwindow-vs-getdesktopwindow.aspx
http://technet.microsoft.com/en-us/magazine/gg213851.aspx
http://www.k8w.net/technology/develop/200710/67.html