#include "StdAfx.h" #include "Global.h" TCHAR g_ModulePath[MAX_PATH] = _T(""); // 软件目录; TCHAR g_ModuleFileName[MAX_PATH] = _T(""); // 软件名称; TCHAR g_szConnectString[MAX_PATH] = _T(""); // DB连接串; // 服务器信息; TCHAR g_szDBSource[MAX_PATH] = _T(""); // 数据库源(服务所在IP或计算机名); TCHAR g_szDBSourcePort[MAX_PATH] = _T(""); // 数据库源端口; DWORD g_dwDBServerPort = 0; // 数据库源端口; TCHAR g_szDBAccount[MAX_PATH] = _T(""); // 数据库登录用户; TCHAR g_szDBPassWord[MAX_PATH] = _T(""); // 数据库登录密码; TCHAR g_szDBName[MAX_PATH] = _T(""); // 数据库名称; // start+------------------------------------------------------------------ // Jeff:以下为原本程序全局变量; #if THE_PRIMARY_GLOBAL_VARIABLE int g_port = 5678; // Jeff.通信端口; BOOL g_bReg = 0; CString g_strdbpsw; // 数据库账号、密码; CString g_strdbServrename; // 数据库服务名(地址) CString g_bakinfo; CString g_bakphoto; CString g_mainpath; SoftKey ytSoftKey; CString g_localname; // 本地计算机名; CDatabase g_db; // 名为"db"的数据库,本年度使用的数据库; CArray g_nYearArray; // 年份(用于命名历史数据库) //CArrayg_dbArray; // 历史数据库; CArrayg_dbHistoryArray; // 历史数据库; CArrayg_branchdbarray; CArrayg_branchdb2array;//除历史年度的分店DB CStringArray g_branchnamearray; CStringArray g_branchname2array; CStringArray g_branchiparray; CStringArray g_branchdomainarray; CDatabase *g_curdb = NULL; int g_conncount = -1; // Jeff.加密狗中的座席版数量; CString g_sdomain; CStringArray g_conniparray; CStringArray g_connidarray; BOOL g_bCheckAll = 0; BYTE *g_pSkinData = NULL; DWORD g_SkinLeng; BOOL g_bAutoRun = 0; CStringArray g_filedatearray; CStringArray g_filedatearraynew; CString g_bakdate; CString g_localip; BOOL g_bSteal = 0; CString g_bakserver1; CString g_bakserver2; CString g_bakserver3; CString g_bakserver4; DWORD g_tisks = 0; #endif // endof+------------------------------------------------------------------ //************************************// // 数据库地址; // 数据库端口; // 数据库管理员账号; // 数据库管理员密码; // 数据库名称; // // [函数]:GetIniInfo // [描述]:获取指定ini信息; // [参数]: // szPath:ini所在目录; // szIniName:ini名; // [返回]:void // //************************************// int GetIniInfo(const char *szPath, const char *szIniName) { TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; ::GetModuleFileName(NULL, g_ModulePath, sizeof(g_ModulePath) / sizeof(TCHAR)); sprintf(g_ModuleFileName, "%s", g_ModulePath); _tsplitpath(g_ModulePath, szDrive, szDir, NULL, NULL); _tcscpy(g_ModulePath, szDrive); _tcscat(g_ModulePath, szDir); // -----------------------------------------------------// CHAR szFile[MAX_PATH + 1] = ""; if (szPath != NULL && szIniName != NULL) wsprintf(szFile, "%s\\%s", szPath, szIniName); else wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath); TRACE("szFile =%s\n", szFile); OFSTRUCT ofStruct; OpenFile(szFile, &ofStruct, OF_EXIST); if (ERROR_FILE_NOT_FOUND == GetLastError()) { return -1; } // 获取服务器端信息; GetPrivateProfileString("DatabaseInfo", "dbSource", "", g_szDBSource, MAX_PATH, szFile); g_dwDBServerPort = GetPrivateProfileInt("DatabaseInfo", "dbServerPort", 0, szFile); GetPrivateProfileString("DatabaseInfo", "dbAccount", "", g_szDBAccount, MAX_PATH, szFile); GetPrivateProfileString("DatabaseInfo", "dbPassWord", "", g_szDBPassWord, MAX_PATH, szFile); GetPrivateProfileString("DatabaseInfo", "dbName", "", g_szDBName, MAX_PATH, szFile); if (g_dwDBServerPort != 0) sprintf(g_szConnectString, "driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s", g_szDBSource, g_dwDBServerPort, g_szDBName, g_szDBAccount, g_szDBPassWord); else sprintf(g_szConnectString, "driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s", g_szDBSource, g_szDBName, g_szDBAccount, g_szDBPassWord); return 0; } //------------------------------------------------------------ // 以下全局函数为原程序所有; #if THE_PRIMARY_GLOBAL_FUNCTION BOOL AddConn(CDatabase *m_conndb, CString dbname) { try { CString strCon; strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%s;%s"), g_strdbServrename, dbname, g_strdbpsw); m_conndb->OpenEx(strCon, CDatabase::noOdbcDialog); } catch (CDBException * e) { WriteLogin("新建连接时出错:" + e->m_strError); e->Delete(); return 0; } return 1; } void WriteError(CString str) { MyLock lock("DBServerWriteError"); CStdioFile fp; CString path = g_mainpath + "\\MsgError.txt"; if (::PathFileExists(path)) { fp.Open(path, CFile::modeWrite); int length = fp.GetLength(); if (length > 1024 * 1024) { fp.Close(); ::DeleteFile(path); // 删除MsgError.txt return; } fp.SeekToEnd(); } else fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n"); fp.Close(); } void WritePswWrong(CString str) { MyLock lock("DBServerWritePswWrong"); CStdioFile fp; CString path = g_mainpath + "\\PswWrong.txt"; if (::PathFileExists(path)) { fp.Open(path, CFile::modeWrite); int length = fp.GetLength(); if (length > 1024 * 1024) { fp.Close(); ::DeleteFile(path); // 删除PswWrong.txt return; } fp.SeekToEnd(); } else fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n"); fp.Close(); } void WriteNullBalance(CString str) { MyLock lock("DBServerWriteNullBalance"); CStdioFile fp; CString path = g_mainpath + "\\NullBalance.txt"; if (::PathFileExists(path)) { fp.Open(path, CFile::modeWrite); int length = fp.GetLength(); if (length > 1024 * 1024) { fp.Close(); ::DeleteFile(path); // 删除NullBalance.txt return; } fp.SeekToEnd(); } else fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n"); fp.Close(); } void WriteUnallowIP(CString str) { CStdioFile fp; CString path = g_mainpath + "\\UnallowIP.txt"; if (::PathFileExists(path)) { fp.Open(path, CFile::modeWrite); int length = fp.GetLength(); if (length > 1024 * 1024) { fp.Close(); ::DeleteFile(path); // 删除UnallowIP.txt return; } fp.SeekToEnd(); } else fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n"); fp.Close(); } int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes CheckFolderFileExist ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if (size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if (pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for (UINT j = 0; j < num; ++j) { if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure } void SaveImageToFile(Image *img, CString path) { try { if (img == NULL)return; CLSID encoderClsid; BSTR bstr = path.AllocSysString(); path.MakeLower(); if (path.Right(3) == "bmp") { GetEncoderClsid(L"image/bmp", &encoderClsid); img->Save(bstr, &encoderClsid, NULL); } else if (path.Right(3) == "png") { GetEncoderClsid(L"image/png", &encoderClsid); img->Save(bstr, &encoderClsid, NULL); } else// if(path.Right (3)=="jpg") { GetEncoderClsid(L"image/jpeg", &encoderClsid); EncoderParameters encoderParameters; ULONG quality; encoderParameters.Count = 1; encoderParameters.Parameter[0].Guid = EncoderQuality; encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong; encoderParameters.Parameter[0].NumberOfValues = 1; // Save the image as a JPEG with quality level 100. quality = 100; encoderParameters.Parameter[0].Value = &quality; img->Save(bstr, &encoderClsid, &encoderParameters); } SysFreeString(bstr); } catch (...) { } } void SaveImageToFile2(Image *img, CString path, ULONG quality) { try { if (img == NULL)return; CLSID encoderClsid; BSTR bstr = path.AllocSysString(); path.MakeLower(); if (path.Right(3) == "bmp") { GetEncoderClsid(L"image/bmp", &encoderClsid); img->Save(bstr, &encoderClsid, NULL); } else if (path.Right(3) == "png") { GetEncoderClsid(L"image/png", &encoderClsid); img->Save(bstr, &encoderClsid, NULL); } else// if(path.Right (3)=="jpg") { GetEncoderClsid(L"image/jpeg", &encoderClsid); EncoderParameters encoderParameters; encoderParameters.Count = 1; encoderParameters.Parameter[0].Guid = EncoderQuality; encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong; encoderParameters.Parameter[0].NumberOfValues = 1; // Save the image as a JPEG with quality level 100. encoderParameters.Parameter[0].Value = &quality; img->Save(bstr, &encoderClsid, &encoderParameters); } SysFreeString(bstr); } catch (...) { } } void RectFitDes(int width, int height, CRect &rc) { float fscale = (float)width / (float)height; float rcscale = ((float)rc.Width()) / ((float)rc.Height()); int rcwid = rc.Width(); int rchei = rc.Height(); int dt = 0; if (rcscale < fscale) { dt = (rchei - rcwid / fscale) / 2; rc.top += dt; rc.bottom -= dt; } else { dt = (rcwid - rchei*fscale) / 2; rc.left += dt; rc.right -= dt; } } ///目录是否存在的检查: 支持网络文件,判断文件时有漏洞 bool CheckFolderFileExist(CString &strPath) { strPath.MakeLower(); if (strPath.Find("c:\\") != -1 || strPath.Find("d:\\") != -1 || strPath.Find("e:\\") != -1 || strPath.Find("f:\\") != -1 || strPath.Find("g:\\") != -1 || strPath.Find("h:\\") != -1 || strPath.Find("i:\\") != -1 || strPath.Find("j:\\") != -1 || strPath.Find("k:\\") != -1 || strPath.Find("l:\\") != -1 || strPath.Find("m:\\") != -1) { return ::PathFileExists(strPath); } CString path = strPath; CFile fp; if (fp.Open(path, CFile::modeRead)) { fp.Close(); return 1; } if (strPath.Right(1) != "\\") path += "\\"; path += "zaqw1234.dat"; ::DeleteFile(path);// 删除zaqw1234.dat文件; if (fp.Open(path, CFile::modeCreate) == 0) return 0; fp.Close(); ::DeleteFile(path); // 删除zaqw1234.dat文件; return 1; } bool CheckFileExist(CString &strPath) { strPath.MakeLower(); if (strPath.Find("c:\\") != -1 || strPath.Find("d:\\") != -1 || strPath.Find("e:\\") != -1 || strPath.Find("f:\\") != -1 || strPath.Find("g:\\") != -1 || strPath.Find("h:\\") != -1 || strPath.Find("i:\\") != -1 || strPath.Find("j:\\") != -1 || strPath.Find("k:\\") != -1 || strPath.Find("l:\\") != -1 || strPath.Find("m:\\") != -1) { return ::PathFileExists(strPath); } CString path = strPath; CFile fp; if (fp.Open(path, CFile::modeRead)) { fp.Close(); return 1; } return 0; } BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword) { try { HCRYPTPROV hCryptProv; HCRYPTKEY hKey; HCRYPTHASH hHash; PBYTE pbBuffer; DWORD dwBlockLen; DWORD dwBufferLen; DWORD dwCount; //以下获得一个CSP句柄 if (CryptAcquireContext( &hCryptProv, NULL, //NULL表示使用默认密钥容器,默认密钥容器名为用户登陆名 NULL, PROV_RSA_FULL, 0)) { printf("A cryptographic provider has been acquired. \n"); } else//密钥容器不存在 { if (CryptAcquireContext( &hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))//创建密钥容器 { //创建密钥容器成功,并得到CSP句柄 printf("A new key container has been created.\n"); } else { return 0; } } //-------------------------------------------------------------------- // 创建一个会话密钥(session key) // 会话密钥也叫对称密钥,用于对称加密算法。 // (注: 一个Session是指从调用函数CryptAcquireContext到调用函数 // CryptReleaseContext 期间的阶段。) //-------------------------------------------------------------------- // Create a hash object. if (CryptCreateHash( hCryptProv, CALG_MD5, 0, 0, &hHash)) { printf("A hash object has been created. \n"); } else { return 0; } //-------------------------------------------------------------------- // 用输入的密码产生一个散列 if (CryptHashData( hHash, (BYTE *)szPassword, strlen(szPassword), 0)) { printf("The password has been added to the hash. \n"); } else { return 0; } //-------------------------------------------------------------------- // 通过散列生成会话密钥(session key) if (CryptDeriveKey( hCryptProv, ENCRYPT_ALGORITHM, hHash, KEYLENGTH, &hKey)) { printf("An encryption key is derived from the password hash. \n"); } else { return 0; } //-------------------------------------------------------------------- // Destroy the hash object. CryptDestroyHash(hHash); hHash = NULL; //-------------------------------------------------------------------- // The session key is now ready. //-------------------------------------------------------------------- // 因为加密算法是按ENCRYPT_BLOCK_SIZE 大小的块加密的,所以被加密的 // 数据长度必须是ENCRYPT_BLOCK_SIZE 的整数倍。下面计算一次加密的 // 数据长度。 dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE; //-------------------------------------------------------------------- // Determine the block size. If a block cipher is used, // it must have room for an extra block. if (ENCRYPT_BLOCK_SIZE > 1) dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE; else dwBufferLen = dwBlockLen; dwCount = dwBufferLen; //-------------------------------------------------------------------- // In a do loop, encrypt the source file and write to the source file. int count; // if(leng%dwBlockLen==0) count = leng / dwBufferLen; // else // count=leng/dwBlockLen+1; for (int i = 0; i < count; i++) { pbBuffer = buffer + i*dwBufferLen; // 加密数据 if (!CryptEncrypt( hKey, //密钥 0, //如果数据同时进行散列和加密,这里传入一个散列对象 0, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE. //这里通过判断是否到文件尾来决定是否为最后一块。 0, //保留 pbBuffer, //输入被加密数据,输出加密后的数据 &dwCount, //输入被加密数据实际长度,输出加密后数据长度 dwBufferLen)) //pbBuffer的大小。 { return 0; } } if (leng%dwBlockLen) { pbBuffer = buffer + i*dwBufferLen; dwCount = leng - i*dwBufferLen; if (!CryptEncrypt( hKey, //密钥 0, //如果数据同时进行散列和加密,这里传入一个散列对象 TRUE, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE. //这里通过判断是否到文件尾来决定是否为最后一块。 0, //保留 pbBuffer, //输入被加密数据,输出加密后的数据 &dwCount, //输入被加密数据实际长度,输出加密后数据长度 dwBufferLen)) //pbBuffer的大小。 { return 0; } } //-------------------------------------------------------------------- // Destroy session key. if (hKey) CryptDestroyKey(hKey); //-------------------------------------------------------------------- // Destroy hash object. if (hHash) CryptDestroyHash(hHash); //-------------------------------------------------------------------- // Release provider handle. if (hCryptProv) CryptReleaseContext(hCryptProv, 0); return(TRUE); } catch (...) { } } //------------------------------------------------------------------------------- // Remark by Jeff // 函数:BakData2 // 描述: // 参数: // savedir : 存储备份数据库文件的目录; // bToday : 是否备份今天的数据库; // bBakHis : 是否备份历史数据库; // // 返回:无; //------------------------------------------------------------------------------- void BakData2(CString savedir, BOOL bToday, BOOL bBakHis) { // 1.使用master系统数据库来备份; CDatabase g_masterdb; try { #if 0 CString strCon; strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=master;%s"), g_strdbServrename, g_strdbpsw); g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog); #else TCHAR szConnectString[MAX_PATH] = _T(""); if (g_dwDBServerPort != 0) sprintf(szConnectString, "driver={SQL Server};Server=%s,%d;database=master;uid=%s;pwd=%s", g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord); else sprintf(szConnectString, "driver={SQL Server};Server=%s;database=master;uid=%s;pwd=%s", g_szDBSource, g_szDBAccount, g_szDBPassWord); g_masterdb.OpenEx(szConnectString, CDatabase::noOdbcDialog); #endif } catch (CDBException *e) { e->Delete(); } try { // 2.获取昨天的日期tm2; CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(1, 0, 0, 0); CTime tm2; if (bToday) tm2 = tm; else tm2 = tm - dt; CString savepath; savepath.Format("%s\\%s(sql).bak", savedir, tm2.Format("%Y%m%d")); BOOL bBak = 0; // 是否备份成功; BOOL bBak2 = 0; // 是否备份历史年限数据库成功; // 3.如果没找到<昨天>备份数据库,则进行备份; if (::PathFileExists(savepath) == 0) { g_masterdb.SetQueryTimeout(600); { CString sql; #if 0 // Jeff.deal; sql.Format("BACKUP DATABASE db TO DISK='%s' WITH FORMAT", savepath); #else sql.Format("BACKUP DATABASE %s TO DISK='%s' WITH FORMAT", g_szDBName, savepath); #endif try { g_masterdb.ExecuteSQL(sql); bBak = 1; g_bakinfo = "资料备份成功"; } catch (CDBException * e) { WriteLogin(e->m_strError); WriteLogin("备份失败!"); e->Delete(); } } g_masterdb.SetQueryTimeout(100); } // 4.Jeff.是否备份历史数据库; if (bBakHis) { for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--) { g_masterdb.SetQueryTimeout(600); { CString savepath2; savepath2.Format("%s\\%s-%d(sql).bak", savedir, tm2.Format("%Y%m%d"), i); CString sql; sql.Format("BACKUP DATABASE [%d] TO DISK='%s' WITH FORMAT", i, savepath2); try { g_masterdb.ExecuteSQL(sql); bBak2 = 1; } catch (CDBException * e) { e->Delete(); break; } } g_masterdb.SetQueryTimeout(100); } } // 5.昨天的数据库备份是否备份成功; if (bBak) { CTimeSpan dt2(31, 0, 0, 0); CTimeSpan dt3(365, 0, 0, 0); // tm:今天, tm3:1个月前, tm4:1年前; CTime tm3 = tm - dt2; CTime tm4 = tm - dt3; // 6.循环删除数据库备份; while (tm3 > tm4) { savepath.Format("%s\\%s.bak", savedir, tm3.Format("%Y%m%d")); #ifdef SQLSERVER_VERSION savepath.Format("%s\\%s(sql).bak", savedir, tm3.Format("%Y%m%d")); #endif // Jeff.删除一个月前的数据库备份; if (!CheckFileExist(savepath)) break; ::DeleteFile(savepath); // 删除备份的数据库文件*.bak; tm3 -= dt; // dt 1天的间隔; } } if (bBak2) { CTimeSpan dt2(15, 0, 0, 0); CTimeSpan dt3(365, 0, 0, 0); for (int i = tm.GetYear() - 1; i >= 2009; i--) { CTime tm3 = tm - dt2; CTime tm4 = tm - dt3; while (tm3 > tm4) { savepath.Format("%s\\%s-%d.bak", savedir, tm3.Format("%Y%m%d"), i); #ifdef SQLSERVER_VERSION savepath.Format("%s\\%s-%d(sql).bak", savedir, tm3.Format("%Y%m%d"), i); #endif if (!CheckFileExist(savepath)) break; ::DeleteFile(savepath); // 删除备份的数据库文件*.bak; tm3 -= dt; } } } } catch (...) { WriteLogin("出错在函数BakData2中"); } g_masterdb.Close(); } void BakData(CString savedir, BOOL bToday, BOOL bBakHis)// back data { #ifdef SQLSERVER_VERSION BakData2(savedir, bToday, bBakHis); return; #endif try { CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(1, 0, 0, 0); CTime tm2; if (bToday) tm2 = tm; else tm2 = tm - dt; CString savepath; savepath.Format("%s\\%s.bak", savedir, tm2.Format("%Y%m%d")); #ifdef SQLSERVER_VERSION savepath.Format("%s\\%s(sql).bak", savedir, tm2.Format("%Y%m%d")); #endif BOOL bBak = 0; BOOL bBak2 = 0; { TCHAR szDBFile[MAX_PATH] = _T(""); // Jeff.add #ifdef SQLSERVER_VERSION sprintf(szDBFile, "%s\\数据\\%s.mdf", g_ModulePath, g_szDBName); //if(::CopyFile (g_mainpath+"\\数据\\db.mdf", savepath, 0)) if (::CopyFile(szDBFile, savepath, 0)) #else sprintf(szDBFile, "%s\\数据\\%s.mdb", g_ModulePath, g_szDBName); //if(::CopyFile (g_mainpath+"\\数据\\db.mdb", savepath, 0)) if (::CopyFile(szDBFile, savepath, 0)) #endif { bBak = 1; g_bakinfo = "资料备份成功"; } } for (int i = tm.GetYear() - 1; i >= 1900; i--) { #ifdef SQLSERVER_VERSION savepath.Format("%s\\数据\\%d.mdf", g_mainpath, i); #else savepath.Format("%s\\数据\\%d.mdb", g_mainpath, i); #endif if (CheckFileExist(savepath) == 0)break; CString savepath2; savepath2.Format("%s\\%s-%d.bak", savedir, tm2.Format("%Y%m%d"), i); #ifdef SQLSERVER_VERSION savepath2.Format("%s\\%s-%d(sql).bak", savedir, tm2.Format("%Y%m%d"), i); #endif if (::CopyFile(savepath, savepath2, 0)) bBak2 = 1; } if (bBak) { CTimeSpan dt2(15, 0, 0, 0); CTimeSpan dt3(365, 0, 0, 0); CTime tm3 = tm - dt2; CTime tm4 = tm - dt3; while (tm3 > tm4) { savepath.Format("%s\\%s.bak", savedir, tm3.Format("%Y%m%d")); #ifdef SQLSERVER_VERSION savepath.Format("%s\\%s(sql).bak", savedir, tm3.Format("%Y%m%d")); #endif if (!CheckFileExist(savepath)) break; ::DeleteFile(savepath); // 删除备份的数据库文件*.bak; tm3 -= dt; } } if (bBak2) { CTimeSpan dt2(7, 0, 0, 0); CTimeSpan dt3(365, 0, 0, 0); for (int i = tm.GetYear() - 1; i >= 1900; i--) { #ifdef SQLSERVER_VERSION savepath.Format("%s\\数据\\%d.mdf", g_mainpath, i); #else savepath.Format("%s\\数据\\%d.mdb", g_mainpath, i); #endif if (CheckFileExist(savepath) == 0)break; CTime tm3 = tm - dt2; CTime tm4 = tm - dt3; while (tm3 > tm4) { savepath.Format("%s\\%s-%d.bak", savedir, tm3.Format("%Y%m%d"), i); #ifdef SQLSERVER_VERSION savepath.Format("%s\\%s-%d(sql).bak", savedir, tm3.Format("%Y%m%d"), i); #endif if (!CheckFileExist(savepath)) break; ::DeleteFile(savepath); // 删除备份的数据库文件*.bak; tm3 -= dt; } } } } catch (...) { WriteLogin("出错在函数BakData中"); } } DWORD FindAppProcessID(CString path) { try { HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); PROCESSENTRY32 Info; Info.dwSize = sizeof(PROCESSENTRY32); path.MakeLower(); if (::Process32First(handle, &Info)) { do { CString ss = Info.szExeFile; ss.MakeLower(); if (ss == path) { ::CloseHandle(handle); return Info.th32ProcessID; } } while (::Process32Next(handle, &Info)); ::CloseHandle(handle); } return -1; } catch (...) { } } void WriteLogin(CString str) { MyLock lock("CDBServerDlgWriteLogin"); try { CStdioFile fp; CString path = g_mainpath + "\\日志.txt"; if (CheckFileExist(path)) { fp.Open(path, CFile::modeWrite); int length = fp.GetLength(); if (length > 5 * 1024 * 1024) { fp.Close(); ::DeleteFile(path); // 删除备份的 日志.txt; return; } fp.SeekToEnd(); } else fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S") + " " + str + "\n"); fp.Close(); } catch (...) { } } void GetPathFromNetShareName(CString name, CString &sRet) { if (sRet.Find(":") != -1)return; NET_API_STATUS res; SHARE_INFO_502 * psi = NULL; WCHAR wszShareName[255]; TCHAR szPathName[255]; TCHAR path[255]; memset(path, 0, 255); //转换成宽字符 MultiByteToWideChar(CP_ACP, 0, name, -1, wszShareName, 255); res = NetShareGetInfo(NULL, (char *)wszShareName, 502, (LPBYTE *)&psi); if (res == NERR_Success) { wsprintf((char*)szPathName, "%S ", psi->shi502_path); sRet = szPathName; sRet.TrimRight(); } else { CString str; #if 0 // Jeff delete; str.Format("转换路径失败-%d", res); ::WriteLogin(str);//Jeff delete,此处使用了系统域符号,其实完全没作用. #else str.Format("转换路径失败(\"%s\"),", sRet); ErrorExit(str, res); #endif } //释放缓冲 NetApiBufferFree(psi); } CString GetModifyTime2(CString path) { try { CFileFind finder; BOOL bWorking = finder.FindFile(path); if (bWorking) { finder.FindNextFile(); CTime tm; finder.GetLastWriteTime(tm); CString stime; stime.Format("%d%02d%02d", tm.GetYear(), tm.GetMonth(), tm.GetDay()); return stime; } return ""; } #if JEFF_TEST_ON catch (CFileException *e) { CString strError; strError.Format("2.读文件[%s]修改时间出错:%d", e->m_strFileName, e->m_lOsError); WriteLogin(strError); e->Delete(); } #else catch (...) { WriteLogin("出错"); } #endif } CString GetModifyTime(CString path) { try { HANDLE hFile; WIN32_FIND_DATA wfd; // SYSTEMTIME systime; FILETIME localtime; CString stime; //输出时间 memset(&wfd, 0, sizeof(wfd)); if ((hFile = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE) return ""; //ok,转换时间 FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localtime); stime.Format("%16d%16d", localtime.dwHighDateTime, localtime.dwLowDateTime); return stime; } #if JEFF_TEST_ON catch (CFileException *e) { CString strError; strError.Format("读文件[%s]修改时间出错:%d", e->m_strFileName, e->m_lOsError); WriteLogin(strError); e->Delete(); } #else catch (...) { WriteLogin("出错"); } #endif } //-------------------------------------------------------------------------------- // Jeff add 2014.06.23; // 函数:ErrorExit // 描述: // 参数: // lpszFunction:函数名; // dwError:错误码; // //-------------------------------------------------------------------------------- void ErrorExit(CString strDescription, const DWORD &dwError) { #if 1 LPVOID lpMsgBuf; BOOL fOk = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); if (!fOk) { // Is it a network-related error? HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES); if (hDll != NULL) { FormatMessage( FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, hDll, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPTSTR)&lpMsgBuf, 0, NULL); FreeLibrary(hDll); } } if (lpMsgBuf != NULL) { CString strDisplay; strDisplay.Format("%s.错误码=%d,Windows描述:%s", strDescription, dwError, (LPCTSTR)LocalLock(lpMsgBuf)); WriteLogin(strDisplay); LocalFree(lpMsgBuf); } else { WriteLogin(strDescription); } #else HLOCAL hlocal = NULL; // Buffer that gets the error message string // Get the error code's textual description BOOL fOk = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (PTSTR)&hlocal, 0, NULL); if (!fOk) { // Is it a network-related error? HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES); if (hDll != NULL) { FormatMessage( FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, hDll, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (PTSTR)&hlocal, 0, NULL); FreeLibrary(hDll); } } if (hlocal != NULL) { CString strDisplay; strDisplay.Format("%s 失败错误码=%d,Windows系统描述:%s", strDescription, dwError, (PCTSTR)LocalLock(hlocal)); WriteLogin(strDisplay); LocalFree(hlocal); } else { WriteLogin("Error number not found."); } #endif } void MyGetIPByName(CString &name) { CString strIP = name; name.Empty(); DWORD dwServerIP = 0; HOSTENT *host = gethostbyname(strIP); struct in_addr addr; if (host != NULL) { for (int i = 0; host->h_addr_list[i] != NULL; i++) { memset(&addr, 0, sizeof(addr)); memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length); dwServerIP = ntohl(addr.S_un.S_addr); } BYTE* pIP = (BYTE*)&dwServerIP; name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]); } } void EncryptFile3(CString path) { CFile fp; if (fp.Open(path, CFile::modeRead) == 0)return; DWORD leng = fp.GetLength(); BYTE *pData = new BYTE[leng]; fp.Read(pData, leng); fp.Close(); EncryptFile2(pData, leng, "z9871234abcd"); fp.Open(path, CFile::modeWrite); fp.Write(pData, leng); fp.Close(); delete[]pData; } int FindArray(CStringArray *pArray, CString Str) { for (int i = 0; i < pArray->GetSize(); i++) { if (pArray->ElementAt(i) == Str) return i; } return -1; } BOOL isInnerIP(DWORD a_ip) { BOOL bValid = 0; if ((a_ip >> 24 == 0xa) || (a_ip >> 16 == 0xc0a8) || (a_ip >> 22 == 0x2b0)) { bValid = 1; } return bValid; } BOOL CompareIP(CString name1, CString name2) { CStringArray g_serverarray1; CStringArray g_serverarray2; CString strIP = name1; DWORD dwServerIP = 0; HOSTENT *host = gethostbyname(strIP); struct in_addr addr; if (host != NULL) { for (int i = 0; host->h_addr_list[i] != NULL; i++) { memset(&addr, 0, sizeof(addr)); memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length); dwServerIP = ntohl(addr.S_un.S_addr); BYTE* pIP = (BYTE*)&dwServerIP; strIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]); g_serverarray1.Add(strIP); } } while (g_serverarray1.GetSize() > 1) { CString name; BOOL bFind = 0; for (int i = 0; i < g_serverarray1.GetSize(); i++) { DWORD dwServerIP = inet_addr(g_serverarray1.ElementAt(i)); dwServerIP = htonl(dwServerIP);//加了才正确 if (isInnerIP(dwServerIP) == 0) { g_serverarray1.RemoveAt(i); bFind = 1; break; } } if (bFind == 0) { break; } } ////////// { CString strIP = name2; DWORD dwServerIP = 0; HOSTENT *host = gethostbyname(strIP); struct in_addr addr; if (host != NULL) { for (int i = 0; host->h_addr_list[i] != NULL; i++) { memset(&addr, 0, sizeof(addr)); memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length); dwServerIP = ntohl(addr.S_un.S_addr); BYTE* pIP = (BYTE*)&dwServerIP; strIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]); g_serverarray2.Add(strIP); } } while (g_serverarray2.GetSize() > 1) { CString name; BOOL bFind = 0; for (int i = 0; i < g_serverarray2.GetSize(); i++) { DWORD dwServerIP = inet_addr(g_serverarray2.ElementAt(i)); dwServerIP = htonl(dwServerIP);//加了才正确 if (isInnerIP(dwServerIP) == 0) { g_serverarray2.RemoveAt(i); bFind = 1; break; } } if (bFind == 0) { break; } } } if (g_serverarray1.GetSize() == 0 || g_serverarray2.GetSize() == 0)return 1; for (int i = 0; i < g_serverarray1.GetSize(); i++) { for (int j = 0; j < g_serverarray2.GetSize(); j++) { if (g_serverarray1.ElementAt(i) == g_serverarray2.ElementAt(j))return 0; } } return 1; } void DeleteDirectory(CString strDir) { try { // 首先删除文件及子文件夹 CFileFind ff; BOOL bFound = ff.FindFile(strDir + "\\*", 0); while (bFound) { bFound = ff.FindNextFile(); if (ff.GetFileName() == "." || ff.GetFileName() == "..") continue; // 去掉文件(夹)只读等属性 SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL); if (ff.IsDirectory()) { // 递归删除子文件夹 DeleteDirectory(ff.GetFilePath()); RemoveDirectory(ff.GetFilePath()); } else { DeleteFile(ff.GetFilePath()); // Jeff:删除某文件夹下的所有子文件; #if JEFF_TEST_ON // 输出删除日志; WriteLogin(ff.GetFilePath()); #endif } } ff.Close(); // 然后删除该文件夹 RemoveDirectory(strDir); } catch (...) { WriteLogin("出错在函数deldir中"); } // int SHFileOperation( LPSHFILEOPSTRUCT lpFileOp ); } int GetLengthEx(CString str) { wchar_t wstr[500]; int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500); return k; } CString GetFileSize(CString path) { CString str = "0"; try { CFile fp; fp.Open(path, CFile::modeRead); str.Format("%d", fp.GetLength()); fp.Close(); } catch (...) { } return str; } void SortArray(CStringArray &datearray) { try { CString strtemp; float ftemp; int last = datearray.GetSize() - 1; bool sorted = true; do { sorted = true; for (int i = 0; i < last; i++) { if (datearray[i] < datearray[i + 1]) { strtemp = datearray[i]; datearray[i] = datearray[i + 1]; datearray[i + 1] = strtemp; sorted = false; } } last--; } while (!sorted); } catch (...) { WriteLogin("SortArray出错"); } } int CheckPhoneType(CString phoneno)//移动:0 联通:1 电信:2 小灵通:3 未知:-1 { if (phoneno.IsEmpty())return -1; for (int i = 0; i < phoneno.GetLength(); i++) { if (phoneno.GetAt(i) < '0' || phoneno.GetAt(i) > '9')return -1; } if (phoneno.GetAt(0) == '1') { if (phoneno.GetLength() != 11) return -1; int mobile[] = { 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144, 182, 147, 183, 184 }; int unicom[] = { 130, 131, 132, 155, 156, 186, 185 }; int telecom[] = { 133, 153, 189, 180, 181 }; for (i = 0; i < sizeof(mobile) / sizeof(int); i++) { if (mobile[i] == atoi(phoneno.Left(3))) { return 0; } } for (i = 0; i < sizeof(unicom) / sizeof(int); i++) { if (unicom[i] == atoi(phoneno.Left(3))) { return 1; } } for (i = 0; i < sizeof(telecom) / sizeof(int); i++) { if (telecom[i] == atoi(phoneno.Left(3))) { return 2; } } return -1; } /* else if(phoneno.GetAt (0)=='0') { if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12) { return 3; } }*/ return -1; } CTime GetTmFromStr(CString date) { try { CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0); CString ss; ss.Format("%d-%d-%d", tm.GetYear(), tm.GetMonth(), tm.GetDay()); return tm; } catch (...) { date = "1980-01-01"; CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0); return tm; } } void ConvertToPrice(CString &str) { if (str.Find('.') == -1)return; str.TrimRight('0'); str.TrimRight('.'); } void SortArray(CArray*List1array, int pos) { CString stemp; int last = List1array->GetSize() - 1; int ret = last; bool sorted = true; do { sorted = true; for (int i = 0; i < last; i++) { if (List1array->ElementAt(i).ElementAt(pos) < List1array->ElementAt(i + 1).ElementAt(pos)) { for (int a = 0; a < List1array->ElementAt(i).GetSize(); a++) { stemp = List1array->ElementAt(i).ElementAt(a); List1array->ElementAt(i).SetAt(a, List1array->ElementAt(i + 1).ElementAt(a)); List1array->ElementAt(i + 1).SetAt(a, stemp); } sorted = false; } } last--; } while (!sorted); } void DeCodePicCount(long &value1, long &value2) { // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { return; } long d[8]; double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 ret = ytSoftKey.decryptpiccount(&value1, &value2, &d[2], &d[3], &d[4], &d[5], &d[6], &d[7], &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { exit(0); } } void DeCodelong1(long &value1, long &value2, long &value3, long &value4, long &value5, long &value6, long &value7, long &value8) { // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { return; } double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 ret = ytSoftKey.decryptlong1(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8, &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { exit(0); } } void DeCodelong2(long &value1, long &value2, long &value3, long &value4, long &value5, long &value6, long &value7, long &value8) { // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { return; } double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 ret = ytSoftKey.decryptlong2(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8, &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { exit(0); } } void DeCodelong3(long &value1, long &value2, long &value3, long &value4, long &value5, long &value6, long &value7, long &value8) { // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { return; } double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 ret = ytSoftKey.decryptlong3(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8, &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { exit(0); } } void DeCodelong4(long &value1, long &value2, long &value3, long &value4, long &value5, long &value6, long &value7, long &value8) { // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { exit(0); } double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 ret = ytSoftKey.decryptlong4(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8, &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { exit(0); } } #endif ////////////////////////////////////////////////////////////////////////// /************************************************************************/ /* 函数:GetDiskSpaceInfo 描述:获取指定目录或盘符的容量信息; 参数: IN: lpRootPathName 根目录名称; INOUT: dTotalNum 总容量; INOUT: dFreeNum 可用容量; 返回: 注意: GetDiskFreeSpace函数不能满足当前超过2T的硬盘容量,因为里面的数据类型是UINT,最大支持32位(4G); GetDiskFreeSpaceEx支持64位(16384P=1024*16384T) 只能获取本机硬盘信息,且路径必须包含":"冒号; 调用约定: */ /************************************************************************/ BOOL GetDiskSpaceInfo(IN LPCTSTR lpRootPathName,IN OUT double &dTotalNum, IN OUT double &dFreeNum) { // 校验参数有效性; if(lpRootPathName == NULL || _tcscmp(lpRootPathName,_T("")) == 0) { //_tprintf_s(_T("根目录为空!")); return FALSE; } // 如果长度==1; int nlen = _tcslen(lpRootPathName); if((1 == nlen) || ( 2 == nlen && lpRootPathName[nlen-1] != _T(':'))) { //_tprintf_s(_T("根目录无效!\n")); return FALSE; } if ( !PathFileExists(lpRootPathName)) { //_tprintf_s(_T("根目录不存在!\n")); return FALSE; } BOOL fResult = FALSE; DWORD dwSectPerClust; // 每簇的扇区数; DWORD dwBytesPerSect; // 每个扇区的字节数; DWORD dwFreeClusters; // 可用簇数; DWORD dwTotalClusters; // 总簇数; typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER,PULARGE_INTEGER, PULARGE_INTEGER); P_GDFSE pGetDiskFreeSpaceEx = NULL; /*unsigned*/ __int64 i64FreeBytesToCaller; /*unsigned*/ __int64 i64TotalBytes; /*unsigned*/ __int64 i64FreeBytes; // 调用GetDiskFreeSpaceEx失败则调用GetDiskSpace; #ifdef UNICODE pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"GetDiskFreeSpaceExW"); #else pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle("kernel32.dll"),"GetDiskFreeSpaceExA"); #endif if ( pGetDiskFreeSpaceEx ) { fResult = pGetDiskFreeSpaceEx(lpRootPathName, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); if ( fResult ) { // 将单位由byte转为G byte; dTotalNum = (double)i64TotalBytes/1024/1024/1024; dFreeNum = (double)i64FreeBytes/1024/1024/1024; } } else { fResult = GetDiskFreeSpace(lpRootPathName, &dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters); if ( fResult ) { // 成功获得容量信息; i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust * dwBytesPerSect; i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust * dwBytesPerSect; // 将单位由byte转为G byte; dTotalNum = (double)i64TotalBytes/1024/1024/1024; dFreeNum = (double)i64FreeBytes/1024/1024/1024; } } return fResult; } /************************************************************************/ /* 函数:GetNetShareInfo 描述:获取指定目录或盘符的容量信息; 参数: IN: lpszServer DNS或NETBOIS远程计算机名,NULL时表示本机;This string must begin with \\. IN: lpszShare 要获取信息的共享名称(可以是共享文件夹、打印机等任何设备); 返回:成功返回TRUE; 注意:非本机的网络设备访问需要权限,否则res返回ERROR_ACCESS_DENIED; 调用约定: */ /************************************************************************/ BOOL GetNetShareInfo(IN LPCTSTR lpszServer, IN LPCTSTR lpszShare, OUT LPTSTR lpPath) { PSHARE_INFO_502 psi502 = NULL; NET_API_STATUS res; WCHAR szServer[MAX_PATH] = {0}; WCHAR szShare[MAX_PATH] = {0}; MultiByteToWideChar(CP_ACP, 0, lpszServer, -1, szServer, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, lpszShare, -1, szShare, MAX_PATH); if ((res = NetShareGetInfo((char*)szServer,(char*)szShare,502,(LPBYTE*)&psi502)) == ERROR_SUCCESS) wsprintf((char*)lpPath,"%S",psi502->shi502_path); // 释放资源; NetApiBufferFree(psi502); return (res==ERROR_SUCCESS)?TRUE:FALSE; }