summaryrefslogtreecommitdiff
path: root/src/Fl.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2010-09-27 14:57:53 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2010-09-27 14:57:53 +0000
commitb010bce1af756d007d194eba16202dd9dcba80c7 (patch)
tree6f9ca34d3fbf08a1147b314c85e1194618216358 /src/Fl.cxx
parent5c968a2589f3a32a01d17db0130ead4e778fbd80 (diff)
Fixed unbalanced Windows OleInitialize/OleUnitialize calls
when loading/unloading the FLTK dll (STR #2417) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7706 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl.cxx')
-rw-r--r--src/Fl.cxx24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index bc8abb928..55dedea96 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -484,13 +484,35 @@ int Fl::run() {
}
#ifdef WIN32
+
+// Function to initialize COM/OLE for usage. This must be done only once.
+// We define a flag to register whether we called it:
+static char oleInitialized = 0;
+
+// This calls the Windows function OleInitialize() exactly once.
+void fl_OleInitialize() {
+ if (!oleInitialized) {
+ OleInitialize(0L);
+ oleInitialized = 1;
+ }
+}
+
+// This calls the Windows function OleUninitialize() only, if
+// OleInitialize has been called before.
+void fl_OleUninitialize() {
+ if (oleInitialized) {
+ OleUninitialize();
+ oleInitialized = 0;
+ }
+}
+
class Fl_Win32_At_Exit {
public:
Fl_Win32_At_Exit() { }
~Fl_Win32_At_Exit() {
fl_free_fonts(); // do some WIN32 cleanup
fl_cleanup_pens();
- OleUninitialize();
+ fl_OleUninitialize();
fl_brush_action(1);
fl_cleanup_dc_list();
}