• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            《Windows via C/C++》中示例程序DIPS的問(wèn)題

              前一階段重溫了Windows中的HOOK,由此參考了《Windows via C/C++》中的示例程序——DIPS,但是我發(fā)現(xiàn)了一個(gè)有趣的問(wèn)題。
              默認(rèn)情況下,鏈接器并不會(huì)將支持XP或Vista的manifest鏈接到程序上,因此,生成的應(yīng)用程序運(yùn)行時(shí)的控件風(fēng)格是經(jīng)典Windows樣式,此時(shí),DIPS小工具運(yùn)行正常。
              但是,當(dāng)加上如下這段代碼(適用于x86 CPU),問(wèn)題就產(chǎn)生了。
            #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
              這意味著鏈接器將會(huì)把新的XP或Vista的manifest鏈接到程序上,使應(yīng)用程序具有XP或Vista的控件樣式。這時(shí),問(wèn)題產(chǎn)生了。
              這里我貼出程序的主函數(shù)代碼:
            int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR pszCmdLine, int{

               
            // Convert command-line character to uppercase.
               CharUpperBuff(pszCmdLine, 1);
               TCHAR cWhatToDo 
            = pszCmdLine[0];

               
            if ((cWhatToDo != TEXT('S')) && (cWhatToDo != TEXT('R'))) {

                  
            // An invalid command-line argument; prompt the user.
                  cWhatToDo = 0;
               }


               
            if (cWhatToDo == 0{
                  
            // No command-line argument was used to tell us what to
                  
            // do; show usage dialog box and prompt the user.
                  switch (DialogBox(hInstExe, MAKEINTRESOURCE(IDD_DIPS), NULL, Dlg_Proc)) {
                     
            case IDC_SAVE:    
                        cWhatToDo 
            = TEXT('S'); 
                        
            break;

                     
            case IDC_RESTORE: 
                        cWhatToDo 
            = TEXT('R');
                        
            break;
                  }

               }


               
            if (cWhatToDo == 0{
                  
            // The user doesn't want to do anything.
                  return(0);
               }

               
               
            // The Desktop ListView window is the grandchild of the ProgMan window.
               HWND hWndLV = GetFirstChild(GetFirstChild(
                  FindWindow(TEXT(
            "ProgMan"), NULL)));
               chASSERT(IsWindow(hWndLV));

               
            // Set hook that injects our DLL into the Explorer's address space. After 
               
            // setting the hook, the DIPS hidden modeless dialog box is created. We 
               
            // send messages to this window to tell it what we want it to do.
               chVERIFY(SetDIPSHook(GetWindowThreadProcessId(hWndLV, NULL)));

               
            // Wait for the DIPS server window to be created.
               MSG msg;
               GetMessage(
            &msg, NULL, 00);      // 請(qǐng)注意這里

               
            // Find the handle of the hidden dialog box window.
               HWND hWndDIPS = FindWindow(NULL, TEXT("Wintellect DIPS"));

               
            // Make sure that the window was created.
               chASSERT(IsWindow(hWndDIPS));

               
            // Tell the DIPS window which ListView window to manipulate
               
            // and whether the items should be saved or restored.
               BOOL bSave = (cWhatToDo == TEXT('S'));
               SendMessage(hWndDIPS, WM_APP, (WPARAM) hWndLV, bSave);

               
            // Tell the DIPS window to destroy itself. Use SendMessage 
               
            // instead of PostMessage so that we know the window is 
               
            // destroyed before the hook is removed.
               SendMessage(hWndDIPS, WM_CLOSE, 00);

               
            // Make sure that the window was destroyed.
               chASSERT(!IsWindow(hWndDIPS));

               
            // Unhook the DLL, removing the DIPS dialog box procedure 
               
            // from the Explorer's address space.
               SetDIPSHook(0);  

               
            return(0);
            }

              看到上面代碼中的GetMessage函數(shù)(加紅色注釋那行),該函數(shù)是在接收一個(gè)來(lái)自explorer.exe進(jìn)程的消息,這個(gè)消息是在掛鉤DLL注入之后,由掛鉤過(guò)濾函數(shù)發(fā)送的。掛鉤過(guò)濾函數(shù)代碼如下:
            LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) {

               
            static BOOL bFirstTime = TRUE;

               
            if (bFirstTime) {
                  
            // The DLL just got injected.
                  bFirstTime = FALSE;

                  
            // Uncomment the line below to invoke the debugger 
                  
            // on the process that just got the injected DLL.
                  
            // ForceDebugBreak();

                  
            // Create the DIPS Server window to handle the client request.
                  CreateDialog(g_hInstDll, MAKEINTRESOURCE(IDD_DIPS), NULL, Dlg_Proc);

                  
            // Tell the DIPS application that the server is up 
                  
            // and ready to handle requests.
                  PostThreadMessage(g_dwThreadIdDIPS, WM_NULL, 00);
               }


               
            return(CallNextHookEx(g_hHook, nCode, wParam, lParam));
            }

              明顯地,這里發(fā)送了一個(gè)WM_NULL消息給DIPS進(jìn)程,當(dāng)使用經(jīng)典樣式的控件時(shí)一切安好,經(jīng)調(diào)試得到的MSG結(jié)構(gòu)中的各個(gè)字段為正確的值。但是加上了上面那行鏈接命令后,調(diào)試得到的MSG結(jié)構(gòu)的字段壓根就不是WM_NULL、0、0,而是一個(gè)數(shù)值為49211的消息,這樣導(dǎo)致了DIPS主線程喚醒,隨后的FindWindow可能會(huì)返回一個(gè)NULL,因?yàn)樵撓⒉⒉皇菕煦^過(guò)濾函數(shù)的發(fā)送的消息。當(dāng)然,如果在這里Sleep一下,可以得到正確的窗口句柄,我在GetMessage函數(shù)上加了一個(gè)do-while循環(huán),結(jié)果也的確是這樣,幾次循環(huán)之后可以收到消息為WM_NULL的消息,且參數(shù)均為0。
              但是我不明白為什么加上了一條鏈接命令會(huì)這樣?不妨大家都試試看,我用的IDE是VS2005。
              哪位高手可以來(lái)指導(dǎo)我一下呢?

            posted on 2009-06-13 13:37 小虎無(wú)憂 閱讀(1793) 評(píng)論(3)  編輯 收藏 引用 所屬分類: DLL

            評(píng)論

            # re: 《Windows via C/C++》中示例程序DIPS的問(wèn)題 2009-06-17 17:21 Zxjay

            我也想知道原因  回復(fù)  更多評(píng)論   

            # re: 《Windows via C/C++》中示例程序DIPS的問(wèn)題 2009-06-22 13:45 小虎無(wú)憂

            呵呵,樓上的也調(diào)試過(guò)了么?是不是我所說(shuō)的問(wèn)題啊?  回復(fù)  更多評(píng)論   

            # re: 《Windows via C/C++》中示例程序DIPS的問(wèn)題 2009-06-22 13:45 小虎無(wú)憂

            @Zxjay
            呵呵,樓上的也調(diào)試過(guò)了么?是不是我所說(shuō)的問(wèn)題啊?  回復(fù)  更多評(píng)論   

            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲精品无码久久久久久| 亚洲国产精品18久久久久久| 欧美亚洲另类久久综合| 麻豆亚洲AV永久无码精品久久| 熟妇人妻久久中文字幕| 久久综合九色综合97_久久久| 久久婷婷五月综合成人D啪| 人妻无码αv中文字幕久久琪琪布| 大伊人青草狠狠久久| 亚洲国产精品综合久久网络| 麻豆亚洲AV永久无码精品久久| 伊人丁香狠狠色综合久久| 2021最新久久久视精品爱| 久久99精品综合国产首页| 无码人妻久久久一区二区三区| 精品久久8x国产免费观看| 亚洲国产精品嫩草影院久久| A狠狠久久蜜臀婷色中文网| 精品久久久久成人码免费动漫| 欧美精品一本久久男人的天堂| 亚洲人成无码久久电影网站| 爱做久久久久久| 天天综合久久久网| 国产精品久久久久久久久免费| 久久精品国产清自在天天线| 久久久无码精品午夜| 国产精品久久久天天影视香蕉| 人妻无码久久一区二区三区免费 | 一本久久a久久精品亚洲| 久久国产精品波多野结衣AV| 久久99精品久久久久久| 丁香狠狠色婷婷久久综合| 久久综合香蕉国产蜜臀AV| 四虎亚洲国产成人久久精品| 精品熟女少妇aⅴ免费久久| 国内精品久久久久久不卡影院| 99久久超碰中文字幕伊人| 国产精品久久久久9999| 国产精品岛国久久久久| 美女写真久久影院| 久久人人爽人人精品视频|