Skip to content

Commit

Permalink
fix: 修复 MUSIC 需要依赖 initgraph() 初始化的问题 (#159 引入) (#231)
Browse files Browse the repository at this point in the history
* adjust: 允许 dll 单独加载

* fix: 修复 MUSIC 需要依赖 initgraph() 初始化的问题(#159 引入)

* refactor: dll import 中移除冗余的初始化部分
  • Loading branch information
yixy-only authored Oct 4, 2024
1 parent 67b7180 commit 72784b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
38 changes: 3 additions & 35 deletions src/ege_dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/ege_dllimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MUSIC::MUSIC()
{
m_DID = MUSIC_ERROR;
m_dwCallBack = 0;
dll::loadWinmmDll();
}

// Class MUSIC Destruction
Expand Down

0 comments on commit 72784b9

Please sign in to comment.