• <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的問題

              前一階段重溫了Windows中的HOOK,由此參考了《Windows via C/C++》中的示例程序——DIPS,但是我發現了一個有趣的問題。
              默認情況下,鏈接器并不會將支持XP或Vista的manifest鏈接到程序上,因此,生成的應用程序運行時的控件風格是經典Windows樣式,此時,DIPS小工具運行正常。
              但是,當加上如下這段代碼(適用于x86 CPU),問題就產生了。
            #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
              這意味著鏈接器將會把新的XP或Vista的manifest鏈接到程序上,使應用程序具有XP或Vista的控件樣式。這時,問題產生了。
              這里我貼出程序的主函數代碼:
            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);      // 請注意這里

               
            // 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函數(加紅色注釋那行),該函數是在接收一個來自explorer.exe進程的消息,這個消息是在掛鉤DLL注入之后,由掛鉤過濾函數發送的。掛鉤過濾函數代碼如下:
            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));
            }

              明顯地,這里發送了一個WM_NULL消息給DIPS進程,當使用經典樣式的控件時一切安好,經調試得到的MSG結構中的各個字段為正確的值。但是加上了上面那行鏈接命令后,調試得到的MSG結構的字段壓根就不是WM_NULL、0、0,而是一個數值為49211的消息,這樣導致了DIPS主線程喚醒,隨后的FindWindow可能會返回一個NULL,因為該消息并不是掛鉤過濾函數的發送的消息。當然,如果在這里Sleep一下,可以得到正確的窗口句柄,我在GetMessage函數上加了一個do-while循環,結果也的確是這樣,幾次循環之后可以收到消息為WM_NULL的消息,且參數均為0。
              但是我不明白為什么加上了一條鏈接命令會這樣?不妨大家都試試看,我用的IDE是VS2005。
              哪位高手可以來指導我一下呢?

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

            評論

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

            我也想知道原因  回復  更多評論   

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

            呵呵,樓上的也調試過了么?是不是我所說的問題啊?  回復  更多評論   

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

            @Zxjay
            呵呵,樓上的也調試過了么?是不是我所說的問題啊?  回復  更多評論   

            <2009年11月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久一本精品99久久精品66| 亚洲AV伊人久久青青草原| 97精品伊人久久大香线蕉app| 国产精品美女久久久久网| 精品久久久无码中文字幕| 7777精品久久久大香线蕉| 中文字幕一区二区三区久久网站| 久久影视综合亚洲| 久久精品国产亚洲AV麻豆网站| 精品欧美一区二区三区久久久| 久久天天躁狠狠躁夜夜网站| 久久99亚洲综合精品首页| 婷婷综合久久中文字幕蜜桃三电影| 国产成人精品久久综合 | 久久99精品久久只有精品| 久久精品国产72国产精福利| 人妻少妇久久中文字幕一区二区| 精品久久久久中文字| 国产精品久久久久…| 久久人人爽人人爽人人片AV不| 99久久精品免费看国产一区二区三区 | 精品熟女少妇a∨免费久久| 久久性生大片免费观看性| 91精品免费久久久久久久久| 日韩AV无码久久一区二区| 久久久亚洲欧洲日产国码是AV| 久久se精品一区二区影院| 国产L精品国产亚洲区久久 | 污污内射久久一区二区欧美日韩| 狠狠色婷婷综合天天久久丁香 | 亚洲国产精品无码久久SM| 久久人妻少妇嫩草AV无码蜜桃| 国产欧美一区二区久久| 久久久女人与动物群交毛片 | 久久综合九色综合久99| 99国产欧美久久久精品蜜芽| 久久久久久夜精品精品免费啦| 无码AV中文字幕久久专区| 久久丫精品国产亚洲av不卡| 久久99精品久久只有精品| 99久久久精品|