Problems during initialization and exit of gdiplus in DLL

Source: Internet
Author: User
Reprinted others' articles because they encountered similar problems in actual projects. Use GDIPlus2009-08-04 in DLL Project

The project needs to be changed some time ago. Therefore, I changed some of the project's GDI to GDI +, mainly to increase the support for image formats, so I have no time to read things, because I used to be familiar with GDI +, I used it directly.

Add gdiplusstartup and gdiplusshutdown of gdiplus to the dllmain of several projects at the beginning. However, it is found that the registration output remains unchanged at the time of production and must be manually canceled. I haven't encountered any major problems in use, so I will temporarily leave it there.

Today's work is coming to an end. Let's analyze this problem. First, it was identified as caused by gdiplus, and then searched for a lot of information. It was found that there was a problem with the initialization of GDI +. In the DLL project, You Cannot initialize the GDI + in the dllmain file.

See 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 CILS gdiplusstartup and your own shutdown function that CILS 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 + CILS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.