調試dll和exe載入失敗

來源:互聯網
上載者:User

如果啟動程式時出現《應用程式正常初始化(0xc0000142)失敗。請單擊“確定”,終止應用程式》這種錯誤,可以先用depends.exe這個工具來看依賴沒有問題。如果沒有問題,可以用resourcehacker之類的工具看exe和dll的資源段的manifest資訊,通過這個來看依賴的crt是否正確,特別要注意不同dll之間這個資訊可能不一樣(一個exe不能同時載入多個版本的crt)。如果還不能解決,只能通過調試器來分析了。通過devenv.exe 《程式路徑》來啟動程式,然後開啟下面的檔案,並在相應地方設定斷點:

 

dll的進入點:

C:/Program Files/Microsoft Visual Studio 8/VC/crt/src/dllcrt0.c

BOOL WINAPI

_DllMainCRTStartup(

        HANDLE  hDllHandle,

        DWORD   dwReason,

        LPVOID  lpreserved

        )

{

if (dwReason == DLL_PROCESS_ATTACH)

        {

/*

         * The /GS security cookie must be initialized before any exception

         * handling targetting the current image is registered.  No function

         * using exception handling can be called in the current image until

         * after __security_init_cookie has been called.

         */

            __security_init_cookie();

        }

return __DllMainCRTStartup(hDllHandle, dwReason, lpreserved);

}

調試dll載入失敗也可在C:/Program Files/Microsoft Visual Studio 8/VC/crt/src/dllcrt0.c的100行設定斷點。

BOOL WINAPI _CRT_INIT(

        HANDLE  hDllHandle,

        DWORD   dwReason,

        LPVOID  lpreserved

        )

 

 

exe部分

C:/Program Files/Microsoft Visual Studio 8/VC/crt/src/crt0.c的199行為exe的進入點

_declspec(noinline)

int

__tmainCRTStartup(

void

         )

C:/Program Files/Microsoft Visual Studio 8/VC/crt/src/_file.c的112行為初始化stdio的函數

int __cdecl __initstdio(void)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.