From 72784b93102b7fd3459cd6ed42a965df692f0980 Mon Sep 17 00:00:00 2001 From: yixy <34703796+yixy-only@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:38:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20MUSIC=20=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BE=9D=E8=B5=96=20initgraph()=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E9=97=AE=E9=A2=98=20(#159=20=E5=BC=95?= =?UTF-8?q?=E5=85=A5)=20(#231)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adjust: 允许 dll 单独加载 * fix: 修复 MUSIC 需要依赖 initgraph() 初始化的问题(#159 引入) * refactor: dll import 中移除冗余的初始化部分 --- src/ege_dllimport.cpp | 38 +++----------------------------------- src/ege_dllimport.h | 11 ++++++++++- src/music.cpp | 1 + 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/ege_dllimport.cpp b/src/ege_dllimport.cpp index 662be84..9023f10 100644 --- a/src/ege_dllimport.cpp +++ b/src/ege_dllimport.cpp @@ -27,14 +27,7 @@ namespace dll static HIMC (WINAPI *func_ImmGetContext)(HWND); static BOOL (WINAPI *func_ImmSetCompositionWindow)(HIMC , LPCOMPOSITIONFORM); - static void initImm32Dll() - { - imm32Dll = NULL; - func_ImmGetContext = NULL; - func_ImmSetCompositionWindow = NULL; - } - - static bool loadImm32Dll() + bool loadImm32Dll() { if(imm32Dll == NULL) { imm32Dll = LoadLibraryA("imm32.dll"); @@ -83,14 +76,7 @@ namespace dll static BOOL (WINAPI *func_AlphaBlend)(HDC hdcDest,int xoriginDest,int yoriginDest,int wDest,int hDest,HDC hdcSrc,int xoriginSrc,int yoriginSrc,int wSrc,int hSrc,BLENDFUNCTION ftn); static BOOL (WINAPI *func_GradientFill)(HDC hdc, PTRIVERTEX pVertex, ULONG nVertex, PVOID pMesh, ULONG nMesh, ULONG ulMode); - static void initMsimg32Dll() - { - msimg32Dll = NULL; - func_AlphaBlend = NULL; - func_GradientFill = NULL; - } - - static bool loadMsimg32Dll() + bool loadMsimg32Dll() { // -- msimg32.dll -- if (msimg32Dll == NULL) { @@ -142,17 +128,7 @@ namespace dll static MMRESULT (WINAPI *func_timeKillEvent)(UINT uTimerID); static MCIERROR (WINAPI *func_mciSendCommandW)(MCIDEVICEID mciId,UINT uMsg,DWORD_PTR dwParam1,DWORD_PTR dwParam2); - static void initWinmmDll() - { - winmmDll = NULL; - func_timeBeginPeriod = NULL; - func_timeEndPeriod = NULL; - func_timeSetEvent = NULL; - func_timeKillEvent = NULL; - func_mciSendCommandW = NULL; - } - - static bool loadWinmmDll() + bool loadWinmmDll() { // winmm.dll if (winmmDll == NULL) { @@ -251,14 +227,6 @@ namespace dll void loadDllsIfNot() { static bool loadingIsFinished = false; - static bool firstCall = true; // 初次调用标记, 因不同编译单元初始化顺序未保证, 防止静态变量未初始化 - - if (firstCall) { - initImm32Dll(); - initMsimg32Dll(); - initWinmmDll(); - firstCall = false; - } if (!loadingIsFinished) { bool isSuccessful = true; diff --git a/src/ege_dllimport.h b/src/ege_dllimport.h index c68a6dc..1ef2e6f 100644 --- a/src/ege_dllimport.h +++ b/src/ege_dllimport.h @@ -5,9 +5,18 @@ namespace dll { - // 如果没加载 dll 则进行加载 + // 加载所有的 dll (可重复调用) void loadDllsIfNot(); + // 加载 winmm.dll (可重复调用) + bool loadWinmmDll(); + + // 加载 msimg32.dll (可重复调用) + bool loadMsimg32Dll(); + + // 加载 imm32.dll (可重复调用) + bool loadImm32Dll(); + // 释放所有加载的 dll void freeDlls(); diff --git a/src/music.cpp b/src/music.cpp index 7dc16ce..79fdc3c 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -29,6 +29,7 @@ MUSIC::MUSIC() { m_DID = MUSIC_ERROR; m_dwCallBack = 0; + dll::loadWinmmDll(); } // Class MUSIC Destruction