Răsfoiți Sursa

1、获取DLL自身路径名;
2、所有接口添加失败时的日志输出;

scbc.sat2 5 ani în urmă
părinte
comite
7a8f2a15c3
2 a modificat fișierele cu 36 adăugiri și 61 ștergeri
  1. 13 1
      SATHTTP/SATHTTP/Global.cpp
  2. 23 60
      SATHTTP/SATHTTP/SATHTTP.cpp

+ 13 - 1
SATHTTP/SATHTTP/Global.cpp

@@ -20,6 +20,7 @@
 #include <WinIoCtl.h>
 #pragma comment(lib, "SetupAPI.lib")
 
+//#include <psapi.h>
 
 namespace GLOBAL
 {
@@ -145,7 +146,18 @@ namespace GLOBAL
 		TCHAR szDrive[_MAX_DRIVE] = { 0 };
 		TCHAR szDir[_MAX_DIR] = { 0 };
 		TCHAR szExt[_MAX_EXT] = { 0 };
-		DWORD dwRet = ::GetModuleFileName(NULL, g_szCurModuleFileName, sizeof(g_szCurModuleFileName) / sizeof(TCHAR));
+
+		HMODULE hModule = NULL;
+		// 获取当前DLL模块路径,参数2使用DLL中任意一个函数变量名即可;
+		GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)&IsValidLunanrDate, &hModule);
+		if ( hModule )
+		{	
+			GetModuleFileName(hModule, g_szCurModuleFileName, sizeof(g_szCurModuleFileName) / sizeof(TCHAR));
+		}
+		else
+		{
+			GetModuleFileName(NULL, g_szCurModuleFileName, sizeof(g_szCurModuleFileName) / sizeof(TCHAR));
+		}
 
 		_tsplitpath_s(g_szCurModuleFileName, szDrive, szDir, g_szFna, g_szExt);
 		StringCchCat(g_szCurModuleDir, MAX_PATH, szDrive);

+ 23 - 60
SATHTTP/SATHTTP/SATHTTP.cpp

@@ -27,6 +27,8 @@ __if_not_exists(ProcessJob)
 	}
 }
 
+#define SETLOG GLOBAL::WriteTextLog("请求失败(%s)=%ld:\r请求=%s\r返回=%s", __FUNCDNAME__, curlCode, post_data.c_str(), reponse.c_str())
+
 #ifdef __CONSOLE__
 
 // 唯一的应用程序对象
@@ -156,9 +158,6 @@ SATHTTP_API int Login(std::string url, const SATHTTP::STLoginReq &stLoginReq, SA
 	char *pText = cJSON_Print(pRoot);
 	std::string post_data = "requestMsg=";
 	post_data.append(CharEncoding::EnCode_UTF8URL(pText));
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -181,9 +180,6 @@ SATHTTP_API int Login(std::string url, const SATHTTP::STLoginReq &stLoginReq, SA
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -217,6 +213,8 @@ SATHTTP_API int Login(std::string url, const SATHTTP::STLoginReq &stLoginReq, SA
 		}
 	}
 
+	SETLOG;
+
 	return FALSE;
 }
 
@@ -283,9 +281,6 @@ SATHTTP_API int UpdateDeviceMessage(std::string url, const SATHTTP::STUpdateDevi
 	char *pText = cJSON_Print(pRoot);
 	std::string post_data = "requestMsg=";
 	post_data.append(CharEncoding::EnCode_UTF8URL(pText));
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -308,9 +303,7 @@ SATHTTP_API int UpdateDeviceMessage(std::string url, const SATHTTP::STUpdateDevi
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -342,6 +335,7 @@ SATHTTP_API int UpdateDeviceMessage(std::string url, const SATHTTP::STUpdateDevi
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -385,9 +379,6 @@ SATHTTP_API int Heartbeat(std::string url, const SATHTTP::STHeartbeatReq &stHear
 	char *pText = cJSON_Print(pRoot);
 	std::string post_data = "requestMsg=";
 	post_data.append(CharEncoding::EnCode_UTF8URL(pText));
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -410,9 +401,7 @@ SATHTTP_API int Heartbeat(std::string url, const SATHTTP::STHeartbeatReq &stHear
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -557,6 +546,7 @@ SATHTTP_API int Heartbeat(std::string url, const SATHTTP::STHeartbeatReq &stHear
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -588,9 +578,6 @@ SATHTTP_API int SetResult(std::string url, const SATHTTP::STNotifyJobStartReq &s
 	std::string post_data = "requestMsg=";
 	post_data.append(pText);
 	//post_data.append(CharEncoding::EnCode_UTF8URL(pText));
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -613,9 +600,7 @@ SATHTTP_API int SetResult(std::string url, const SATHTTP::STNotifyJobStartReq &s
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -647,6 +632,7 @@ SATHTTP_API int SetResult(std::string url, const SATHTTP::STNotifyJobStartReq &s
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -710,9 +696,6 @@ SATHTTP_API int SetResultList(std::string url, const SATHTTP::STJobProcessReq &s
 	std::string post_data = "requestMsg=";
 	post_data.append(CharEncoding::EnCode_GB2312URL(pText));
 	//post_data.append(pText);
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -735,9 +718,7 @@ SATHTTP_API int SetResultList(std::string url, const SATHTTP::STJobProcessReq &s
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -769,6 +750,7 @@ SATHTTP_API int SetResultList(std::string url, const SATHTTP::STJobProcessReq &s
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -795,9 +777,6 @@ SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATHT
 	char *pText = cJSON_Print(pRoot);
 	std::string post_data = "requestMsg=";
 	post_data.append(CharEncoding::EnCode_UTF8URL(pText));
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -820,9 +799,7 @@ SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATHT
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -864,6 +841,7 @@ SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATHT
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -889,9 +867,6 @@ SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::stri
 	char *pText = cJSON_Print(pRoot);
 	std::string post_data = "requestMsg=";
 	post_data.append(CharEncoding::EnCode_UTF8URL(pText));
-#ifdef _DEBUG
-	//OutputDebugString((std::string(pText)+"\n").c_str());
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -975,6 +950,7 @@ SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::stri
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -1023,9 +999,7 @@ SATHTTP_API int StopTaskFromRunner(std::string url, std::string strInstnaceId, S
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -1052,6 +1026,7 @@ SATHTTP_API int StopTaskFromRunner(std::string url, std::string strInstnaceId, S
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -1081,9 +1056,6 @@ SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATHTTP::STSaveLogReq &
 	//std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
 	// POST表单提交,此处不需要转url格式,注意避坑!
 	std::string post_data = pText;
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -1106,9 +1078,7 @@ SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATHTTP::STSaveLogReq &
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -1135,6 +1105,7 @@ SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATHTTP::STSaveLogReq &
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -1183,9 +1154,6 @@ SATHTTP_API int SaveResultFile(std::string url, const SATHTTP::STSaveFileReq &st
 	//std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
 	// POST表单提交,此处不需要转url格式,注意避坑!
 	std::string post_data = pText;
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -1208,9 +1176,7 @@ SATHTTP_API int SaveResultFile(std::string url, const SATHTTP::STSaveFileReq &st
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -1237,6 +1203,7 @@ SATHTTP_API int SaveResultFile(std::string url, const SATHTTP::STSaveFileReq &st
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }
 
@@ -1271,9 +1238,6 @@ SATHTTP_API int SaveResultImg(std::string url, const SATHTTP::STSaveImgReq &stSa
 	//std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
 	// POST表单提交,此处不需要转url格式,注意避坑!
 	std::string post_data = pText;
-#ifdef _DEBUG
-	//OutputDebugString(CString(pText)+"\n");
-#endif
 
 	// 释放堆内存;
 	if (pText)
@@ -1296,9 +1260,7 @@ SATHTTP_API int SaveResultImg(std::string url, const SATHTTP::STSaveImgReq &stSa
 		if ( curlCode == CURLE_OK )
 		{
 			reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
-#ifdef _DEBUG
-			//OutputDebugString(CString(reponse.c_str())+"\n");
-#endif
+
 			// 解析返回值;
 			pRoot = cJSON_Parse(reponse.c_str());
 			if (pRoot != NULL)
@@ -1325,5 +1287,6 @@ SATHTTP_API int SaveResultImg(std::string url, const SATHTTP::STSaveImgReq &stSa
 		}
 	}
 
+	SETLOG;
 	return FALSE;
 }