Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
DLL函数加载失败时显示行号
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolatl committed Oct 24, 2019
1 parent c1d9392 commit 8fb2b87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "api.h"
#undef DEFINE_QL_API

int errorLine;
bool isLoaded = false;
HMODULE libHandle;

int loadQQLightAPI(void) {
int loadQQLightAPI(int* pErrorLine) {

// 一个玄学问题,不加Sleep(1),只有一个插件时,插件刷新时会崩溃
Sleep(1);
Expand All @@ -18,7 +19,7 @@ int loadQQLightAPI(void) {
return -1;
}

#define GET_DLL_FUNC(dname, ename) if((dname = GetProcAddress(libHandle, ename)) == NULL) goto laodFuncError;
#define GET_DLL_FUNC(dname, ename) if((dname = GetProcAddress(libHandle, ename)) == NULL) { errorLine = __LINE__; goto laodFuncError; }

GET_DLL_FUNC(QL_getPluginPath, "Api_GetPath");
GET_DLL_FUNC(QL_printLog, "Api_SendLog");
Expand Down Expand Up @@ -57,5 +58,6 @@ int loadQQLightAPI(void) {

laodFuncError:
FreeLibrary(libHandle);
*pErrorLine = errorLine;
return -1;
}
2 changes: 1 addition & 1 deletion api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define QLWS_API_H

// loadQQLightAPI
EXTERN int loadQQLightAPI(void);
EXTERN int loadQQLightAPI(int* pErrorLine);

// QQLight API
EXTERN const char* __stdcall (*QL_getPluginPath)(const char* authCode);
Expand Down
9 changes: 6 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,12 @@ DllExport(int) Event_UpdataCookies(void) {
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {

if(loadQQLightAPI() != 0) {
MessageBox(NULL, "The message.dll load failed", "error", MB_OK);
int errorLine;
char message[256];

if(loadQQLightAPI(&errorLine) != 0) {
sprintf(message, "The message.dll load failed. l=%d", errorLine);
MessageBox(NULL, message, "error", MB_OK);
return FALSE;
}

Expand Down

0 comments on commit 8fb2b87

Please sign in to comment.