天天看點

ocx Exitinstance GdiplusShutdown ActiveX gdi+問

在vc加入gdi+時在app::Exitinstance 調用GdiplusShutdown函數會出現卡死現象,如注冊控件時候regsvr32卡死,運作控件退出時卡死/挂上.解決這個更文字在于,在其他地方初始化gdi+和清除gdi+,如架構構造和析構函數實作

但是如果是在Activex中則需要改變。

 GdiplusStartup 和GdiplusShutdown不能在dllmain中被調用,因為activex中的App類的Initinstance是在dllmain中被調用的,是以也不能在activex app類中的initinstance中調用,否則可能會導緻死鎖。

解決辦法

msdn:

1 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. 

2 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. 

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

另:這個文章中有相關的讨論

http://topic.csdn.net/u/20111005/16/d353c25a-b269-4ecb-8a6b-c1af2341d7f1.html