C++ AFX_MANAGE_STATE(AfxGetStaticModuleState())的作用

來源:互聯網
上載者:User

AFX_MANAGE_STATE(AfxGetStaticModuleState())的作用:用於模組切換時的狀態保護,

1.AfxGetStaticModuleState()指向當前模組狀態;

2.當前函數調用結束後原模組的狀態自動被恢複;

3.用於DLL中所調用MFC函數、類、資源時的模組狀態切換;

[MSDN]

By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:

AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope

也就是說,並不是每一個dll的輸出函數前都要調用它,只有在要輸出對話框等用到資源時要調用!

dll中資源是共用的用了這個函數的防止不同的進程修改資源產生錯誤!

預設情況下MFC使用主應用程式的資源控制代碼來載入資源模板,而DLL中的資源模板是存在於DLL模板中,因此要使用這一語句切換到

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.