DLL中GDIPlus初始化和退出時注意的問題

來源:互聯網
上載者:User
轉載的別人的文章,因為自己也在實際工程中遇到類似的問題。DLL工程中使用GDIPlus2009-08-04 14:51

前段時間項目的需求有所更改,因此我將工程中部分GDI改為了GDI+,主要是為了增加圖片格式的支援,沒時間看東西了,而因為我以前對於GDI+比較熟,所以就直接用GDI+了。

一開始在幾個工程的Dllmain中添加Gdiplus的GdiplusStartup和GdiplusShutdown,不過發現在產生時 註冊輸出一步老卡在那裡不動,必須手動取消產生。在使用上倒沒遇到什麼大問題,因此也就暫時扔那裡了。

今天工作暫告一段落,就來分析這個問題。首先定位到是gdiplus引起的,而後搜尋了不少資料,發現是對於GDI+的初始化有問題,在dll工程中不能在dllmain檔案中進行GDI+的初始化。

詳見http://msdn.microsoft.com/en-us/library/ms534077(VS.85).aspx

Remarks 


You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown. 


You can call GdiplusStartup on one thread and call GdiplusShutdown on another thread as long as you delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown. 


Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain. If you want to create a DLL that uses GDI+, you should use one of the following techniques to initialize GDI+: 



Require your clients to call GdiplusStartup before they call the functions in your DLL and to call GdiplusShutdown when they have finished using your DLL. 

Export your own startup function that calls GdiplusStartup and your own shutdown function that calls GdiplusShutdown. Require your clients to call your startup function before they call other functions in your DLL and to call your shutdown function when they
have finished using your DLL. 

Call GdiplusStartup and GdiplusShutdown in each of your functions that make GDI+ calls.

聯繫我們

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