SysLib.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. #include "stdafx.h"
  2. #include <tlhelp32.h>
  3. #include "SysLib.h"
  4. #include <io.h>
  5. #include <odbcinst.h>
  6. #include <afxdb.h>
  7. #include "resource.h"
  8. #include "SpreadSheet.h"
  9. #include <stdio.h>
  10. #include <windows.h>
  11. #include <sql.h>
  12. #include <sqlext.h>
  13. //增加自动启动注册表项
  14. INT AddAutoSysRun(CHAR *strExeFile, INT iAutoRunSystem)
  15. {
  16. HKEY hKey = NULL;
  17. DWORD dwErrorCode = 0;
  18. //创建注册表,有该键则读取,无则创建
  19. dwErrorCode = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  20. _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
  21. 0,
  22. NULL,
  23. REG_OPTION_NON_VOLATILE,
  24. KEY_ALL_ACCESS,
  25. NULL, //Security
  26. &hKey,
  27. NULL);
  28. if (dwErrorCode == ERROR_SUCCESS)
  29. {
  30. if (iAutoRunSystem)
  31. {
  32. dwErrorCode = RegSetValueEx(hKey, _T("lyfzAttendance"), NULL, REG_SZ, (BYTE*)strExeFile, strlen(strExeFile));
  33. }
  34. else
  35. {
  36. dwErrorCode = RegDeleteValue(hKey, _T("lyfzAttendance"));
  37. dwErrorCode = RegDeleteKey(hKey, _T("lyfzAttendance"));
  38. }
  39. }
  40. if (NULL != hKey)
  41. RegCloseKey(hKey);
  42. hKey = NULL;
  43. return 0;
  44. }
  45. //-------------------------------------------------------------------------------------
  46. //Description:
  47. // This function maps a character string to a wide-character (Unicode) string
  48. //
  49. //Parameters:
  50. // lpcszStr: [in] Pointer to the character string to be converted
  51. // lpwszStr: [out] Pointer to a buffer that receives the translated string.
  52. // dwSize: [in] Size of the buffer
  53. //
  54. //Return Values:
  55. // TRUE: Succeed
  56. // FALSE: Failed
  57. //
  58. //Example:
  59. // MByteToWChar(szA,szW,sizeof(szW)/sizeof(szW[0]));
  60. //---------------------------------------------------------------------------------------
  61. BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize)
  62. {
  63. // Get the required size of the buffer that receives the Unicode
  64. // string.
  65. DWORD dwMinSize;
  66. dwMinSize = MultiByteToWideChar(CP_ACP, 0, lpcszStr, -1, NULL, 0);
  67. if (dwSize < dwMinSize)
  68. {
  69. return FALSE;
  70. }
  71. // Convert headers from ASCII to Unicode.
  72. MultiByteToWideChar(CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize);
  73. return TRUE;
  74. }
  75. //-------------------------------------------------------------------------------------
  76. //Description:
  77. // This function maps a wide-character string to a new character string
  78. //
  79. //Parameters:
  80. // lpcwszStr: [in] Pointer to the character string to be converted
  81. // lpszStr: [out] Pointer to a buffer that receives the translated string.
  82. // dwSize: [in] Size of the buffer
  83. //
  84. //Return Values:
  85. // TRUE: Succeed
  86. // FALSE: Failed
  87. //
  88. //Example:
  89. // MByteToWChar(szW,szA,sizeof(szA)/sizeof(szA[0]));
  90. //---------------------------------------------------------------------------------------
  91. BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize)
  92. {
  93. DWORD dwMinSize;
  94. dwMinSize = WideCharToMultiByte(CP_OEMCP, NULL, lpcwszStr, -1, NULL, 0, NULL, FALSE);
  95. if (dwSize < dwMinSize)
  96. {
  97. return FALSE;
  98. }
  99. WideCharToMultiByte(CP_OEMCP, NULL, lpcwszStr, -1, lpszStr, dwSize, NULL, FALSE);
  100. return TRUE;
  101. }
  102. //////////////////////////////////////////////////////////////////////////////
  103. //名称:GetExcelDriver
  104. //功能:获取ODBC中Excel驱动
  105. //作者:徐景周(jingzhou_xu@163.net)
  106. //组织:未来工作室(Future Studio)
  107. //日期:2002.9.1
  108. /////////////////////////////////////////////////////////////////////////////
  109. int GetExcelDriver(CString& sDriver)
  110. {
  111. WCHAR wszBuf[1024] = {0};
  112. WORD cbBufMax = 2000;
  113. WORD cbBufOut;
  114. // 获取已安装驱动的名称(涵数在odbcinst.h里)
  115. if (!SQLGetInstalledDrivers(wszBuf, cbBufMax, &cbBufOut))
  116. {
  117. ::AfxMessageBox(_T("Failed!"));
  118. return 0;
  119. }
  120. // 检索已安装的驱动是否有Excel...
  121. int nlen = 0;
  122. int npos = 0;
  123. char szBuf[512] = {0};
  124. WCHAR* pBuf = wszBuf;
  125. CString strMsg;
  126. while(1)
  127. {
  128. memset(szBuf, 0, 512);
  129. nlen = WChar2Char(szBuf, pBuf + npos);
  130. if(nlen == 0)
  131. break;
  132. npos += (nlen + 1);
  133. printf("发现 %s\n", szBuf);
  134. if(strcmp(szBuf, "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)") == 0
  135. || strcmp(szBuf, "Microsoft Excel-Treiber (*.xls)") == 0
  136. || strcmp(szBuf, "Microsoft Excel Driver (*.xls)") == 0
  137. || strcmp(szBuf, "Driver do Microsoft Excel (*.xls)") == 0)
  138. {
  139. WCHAR wsztmp[512] = {0};
  140. Char2WChar(wsztmp, szBuf);
  141. sDriver = wsztmp;
  142. break;
  143. }
  144. }
  145. return 1;
  146. }
  147. ///////////////////////////////////////////////////////////////////////////////
  148. // BOOL MakeSurePathExists( CString &Path,bool FilenameIncluded)
  149. // 参数:
  150. // Path 路径
  151. // FilenameIncluded 路径是否包含文件名
  152. // 返回值:
  153. // 文件是否存在
  154. // 说明:
  155. // 判断Path文件(FilenameIncluded=true)是否存在,存在返回TURE,不存在返回FALSE
  156. // 自动创建目录
  157. //
  158. ///////////////////////////////////////////////////////////////////////////////
  159. BOOL MakeSurePathExists(CString &Path, bool FilenameIncluded)
  160. {
  161. int Pos = 0;
  162. while ((Pos = Path.Find(_T('\\'), Pos + 1)) != -1)
  163. CreateDirectory(Path.Left(Pos), NULL);
  164. if (!FilenameIncluded)
  165. CreateDirectory(Path, NULL);
  166. // return ((!FilenameIncluded)?!_access(Path,0):
  167. // !_access(Path.Left(Path.ReverseFind('\\')),0));
  168. char szPath[MAX_PATH+1] = {0};
  169. WChar2Char(szPath, Path);
  170. return !_access(szPath, 0);
  171. }
  172. //获得默认的文件名
  173. BOOL GetDefaultXlsFileName(CString& sExcelFile)
  174. {
  175. ///默认文件名:yyyymmddhhmmss.xls
  176. CString timeStr;
  177. CTime day;
  178. day = CTime::GetCurrentTime();
  179. int filenameday, filenamemonth, filenameyear, filehour, filemin, filesec;
  180. filenameday = day.GetDay();//dd
  181. filenamemonth = day.GetMonth();//mm月份
  182. filenameyear = day.GetYear();//yyyy
  183. filehour = day.GetHour();//hh
  184. filemin = day.GetMinute();//mm分钟
  185. filesec = day.GetSecond();//ss
  186. timeStr.Format(_T("%04d%02d%02d%02d%02d%02d"), filenameyear, filenamemonth, filenameday, filehour, filemin, filesec);
  187. sExcelFile = timeStr + _T(".xls");
  188. // prompt the user (with all document templates)
  189. CFileDialog dlgFile(FALSE, _T(".xls"), sExcelFile);
  190. CString title;
  191. CString strFilter;
  192. title = _T("指纹机数据");
  193. strFilter = _T("Excel文件(*.xls)");
  194. strFilter += (TCHAR)'\0'; // next string please
  195. strFilter += _T("*.xls");
  196. strFilter += (TCHAR)'\0'; // last string
  197. dlgFile.m_ofn.nMaxCustFilter++;
  198. dlgFile.m_ofn.nFilterIndex = 1;
  199. // append the "*.*" all files filter
  200. CString allFilter;
  201. VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
  202. strFilter += allFilter;
  203. strFilter += (TCHAR)'\0'; // next string please
  204. strFilter += _T("*.*");
  205. strFilter += (TCHAR)'\0'; // last string
  206. dlgFile.m_ofn.nMaxCustFilter++;
  207. dlgFile.m_ofn.lpstrFilter = strFilter;
  208. dlgFile.m_ofn.lpstrTitle = title;
  209. if (dlgFile.DoModal() == IDCANCEL)
  210. return FALSE; // open cancelled
  211. CString sn = dlgFile.GetPathName();
  212. sExcelFile = sn;
  213. if (MakeSurePathExists(sExcelFile, true))
  214. {
  215. if (!DeleteFile(sExcelFile))
  216. { // delete the file
  217. MessageBox(NULL, _T("覆盖文件时出错!"), _T("提示"), MB_ICONINFORMATION);
  218. return FALSE;
  219. }
  220. }
  221. return TRUE;
  222. }
  223. CString InterceptString(int qlen, CString strSource)
  224. {
  225. int len, i, y;
  226. CString sTemp, sreturn;
  227. strSource.TrimLeft();
  228. strSource.TrimRight();
  229. len = strSource.GetLength();
  230. y = 0;
  231. sTemp = strSource.Right(len - qlen);
  232. for (i = 0; i < len; i++)
  233. {
  234. //if(sTemp[y]<0 || sTemp[y]>255)
  235. //if(sTemp[i]<0 || sTemp[i]>=128)
  236. //if(sTemp.GetAt(y) & 0x80 )
  237. if (::IsDBCSLeadByte(sTemp.GetAt(y)))
  238. y = y + 2;
  239. else
  240. y = y + 1;
  241. if (y >= 70)
  242. break;
  243. }
  244. sreturn = sTemp.Left(y);
  245. return sreturn;
  246. }
  247. //显示选择文件夹窗口
  248. //参数 sFolderPath:用于返回用户选择的文件夹的路径
  249. //参数 sTitle:用于指定选择文件夹窗口的标题
  250. //返回值 :操作结果,用户取消选择或操作失败返回FALSE,否则TRUE
  251. BOOL BrowseForFolder(CString & sFolderPath, CString sTitle)
  252. {
  253. BROWSEINFO bi;
  254. WCHAR Buffer[_MAX_PATH];
  255. bi.hwndOwner = NULL;
  256. bi.pidlRoot = NULL;
  257. bi.pszDisplayName = Buffer;
  258. bi.lpszTitle = sTitle;
  259. bi.ulFlags = 0;
  260. bi.lpfn = NULL;
  261. LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);
  262. if (!pIDList)
  263. return FALSE;
  264. SHGetPathFromIDList(pIDList, Buffer);
  265. sFolderPath = Buffer;
  266. LPMALLOC lpMalloc;
  267. if (FAILED(SHGetMalloc(&lpMalloc)))
  268. return FALSE;
  269. //释放内存
  270. lpMalloc->Free(pIDList);
  271. lpMalloc->Release();
  272. return TRUE;
  273. }
  274. ///////////////////////////////////////////////////////////////////////////////
  275. // void ExportListToExcel(CListCtrl* pList, CString strTitle)
  276. // 参数:
  277. // pList 需要导出的List控件指针
  278. // strTitle 导出的数据表标题
  279. // 说明:
  280. // 导出CListCtrl控件的全部数据到Excel文件。Excel文件名由用户通过“另存为”
  281. // 对话框输入指定。创建名为strTitle的工作表,将List控件内的所有数据(包括
  282. // 列名和数据项)以文本的形式保存到Excel工作表中。保持行列关系。
  283. //
  284. // edit by [r]@dotlive.cnblogs.com
  285. ///////////////////////////////////////////////////////////////////////////////
  286. CString ExportListToExcel(CListCtrl* pList, CString strTitle)
  287. {
  288. CString warningStr;
  289. CString sExcelFile;
  290. if (pList->GetItemCount() > 0)
  291. {
  292. CDatabase database;
  293. CString sDriver;
  294. CString sSql;
  295. CString tableName = strTitle;
  296. // 检索是否安装有Excel驱动 "Microsoft Excel Driver (*.xls)"
  297. GetExcelDriver(sDriver);
  298. if (sDriver.IsEmpty())
  299. {
  300. // 没有发现Excel驱动
  301. AfxMessageBox(_T("没有安装Excel!"));
  302. return _T("");
  303. }
  304. ///默认文件名
  305. if (!GetDefaultXlsFileName(sExcelFile))
  306. {
  307. return _T("");
  308. }
  309. // 创建进行存取的字符串
  310. sSql.Format(_T("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s"), sDriver, sExcelFile, sExcelFile);
  311. // 创建数据库 (既Excel表格文件)
  312. if (database.OpenEx(sSql, CDatabase::noOdbcDialog))
  313. {
  314. // 创建表结构
  315. int i;
  316. LVCOLUMN columnData;
  317. CString columnName;
  318. int columnNum = 0;
  319. CString strH;
  320. CString strV;
  321. sSql = _T("");
  322. strH = _T("");
  323. columnData.mask = LVCF_TEXT;
  324. columnData.cchTextMax = 100;
  325. columnData.pszText = columnName.GetBuffer(100);
  326. for (i = 0; pList->GetColumn(i, &columnData); i++)
  327. {
  328. if (i != 0)
  329. {
  330. sSql = sSql + _T(", ");
  331. strH = strH + _T(", ");
  332. }
  333. sSql = sSql + _T(" ") + columnData.pszText + _T(" TEXT");
  334. strH = strH + _T(" ") + columnData.pszText + _T(" ");
  335. }
  336. columnName.ReleaseBuffer();
  337. columnNum = i;
  338. sSql = _T("CREATE TABLE ") + tableName + _T(" ( ") + sSql + _T(" ) ");
  339. database.ExecuteSQL(sSql);
  340. // 插入数据项
  341. int nItemIndex;
  342. for (nItemIndex = 0; nItemIndex < pList->GetItemCount(); nItemIndex++){
  343. strV = "";
  344. for (i = 0; i < columnNum; i++)
  345. {
  346. if (i != 0)
  347. {
  348. strV = strV + _T(", ");
  349. }
  350. strV = strV + _T(" '") + pList->GetItemText(nItemIndex, i) + _T("' ");
  351. }
  352. sSql = _T("INSERT INTO ") + tableName
  353. + _T(" (") + strH + _T(")")
  354. + _T(" VALUES(") + strV + _T(")");
  355. database.ExecuteSQL(sSql);
  356. }
  357. }
  358. // 关闭数据库
  359. database.Close();
  360. warningStr.Format(_T("Excel文件成功保存至%s"), sExcelFile);
  361. AfxMessageBox(warningStr);
  362. return sExcelFile;
  363. }
  364. return _T("");
  365. }
  366. void ReadExcelToList(CListCtrl* pList, CString strTitle, DWORD &dwListCount)
  367. {
  368. //strTitle+=".xls";
  369. CStringArray Rows, Column;
  370. CSpreadSheet varSheet(strTitle, _T("LoginData"));
  371. //pList->DeleteAllItems();//首先清空listview
  372. DWORD oldListCount = dwListCount;
  373. for (int i = 0; i < varSheet.GetTotalRows() - 1; i++)
  374. {
  375. // 读取一行
  376. varSheet.ReadRow(Rows, i + 2);
  377. CString strContents = _T("");
  378. pList->InsertItem(i + oldListCount, strContents);
  379. for (int j = 0; j < Rows.GetSize(); j++)
  380. {
  381. strContents = Rows.GetAt(j);
  382. pList->SetItemText(i + oldListCount, j, strContents);
  383. }
  384. dwListCount++;
  385. }
  386. }
  387. void TimeTicksToInt(CString strSrc, unsigned long &nDest)
  388. {
  389. CString strLeft;
  390. int nIndex = strSrc.Find(_T(":"));
  391. if (nIndex != -1)
  392. {
  393. strLeft = strSrc.Left(nIndex - 1);
  394. char szLeft[64] = {0};
  395. WChar2Char(szLeft, strLeft);
  396. nDest = atoi(szLeft);
  397. }
  398. }
  399. ///目录是否存在的检查:
  400. bool CheckFolderExist(CString strPath)
  401. {
  402. WIN32_FIND_DATA wfd;
  403. bool rValue = false;
  404. HANDLE hFind = FindFirstFile((LPCTSTR)strPath, &wfd);
  405. if ((hFind != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  406. {
  407. rValue = true;
  408. }
  409. FindClose(hFind);
  410. return rValue;
  411. }
  412. BOOL BrowseFile(CString strFile, CString strFilter,
  413. CStringList *pFileList,
  414. CStringList *pFileNameList,
  415. CStringList *pShowNameList) //查找文件函数
  416. {
  417. CFileFind FileFind;
  418. CString SearchTarget = strFile; // + "\\" +strFilter;
  419. if (SearchTarget.Right(1) != "\\")
  420. SearchTarget += "\\";
  421. SearchTarget += "*.*";
  422. BOOL res = FileFind.FindFile(SearchTarget);
  423. while (res)
  424. {
  425. res = FileFind.FindNextFile();
  426. if (FileFind.IsDirectory() && !FileFind.IsDots())
  427. {
  428. //如果是一个子目录,用递归继续往深一层找
  429. CString strPath = FileFind.GetFilePath();
  430. CString strTitle = FileFind.GetFileTitle();
  431. BrowseFile(strPath, strFilter, pFileList, pFileNameList, pShowNameList);
  432. }
  433. else if (!FileFind.IsDirectory() && !FileFind.IsDots())
  434. {
  435. //显示当前访问的文件
  436. CString strExtName;
  437. CString strName;
  438. strName = FileFind.GetFileName();
  439. strExtName = strName.Right(strName.GetLength() - strName.Find('.') - 1);
  440. strExtName.MakeUpper();
  441. if (!strExtName.CompareNoCase(strFilter))//扩展名正确
  442. {
  443. CString strPath = FileFind.GetFilePath();
  444. pFileList->AddTail(strPath);
  445. pFileNameList->AddTail(strName);
  446. strName = strName.Left(strName.Find('.'));
  447. pShowNameList->AddTail(strName);
  448. }
  449. }
  450. }
  451. FileFind.Close();//关闭
  452. return TRUE;
  453. }
  454. ///////////////////////////////////////////////////////////////////////////////////////////////
  455. ////// 函数名称:GetTokens ///////
  456. ////// 函数说明:根据sDelimiter变量的拆分规则,把sSource源字符串拆分成多个 ///////
  457. ////// 字符串,并传入pTokens变量 ///////
  458. ////// 参数列表:pTokens -- 目标字符串存放指针 ///////
  459. ////// sSource -- 源字符串 ///////
  460. ////// sDelimiter -- 指定的拆分字符 ///////
  461. ////// 作 者:sailing ///////
  462. ////// 创者时间:2008-11-24 ///////
  463. ///////////////////////////////////////////////////////////////////////////////////////////////
  464. void GetTokens(CStringArray * pTokens, CString sSource, CString sDelimiter)
  465. {
  466. pTokens->RemoveAll();
  467. //开始解析
  468. int nStart = 0;
  469. int nLen = sDelimiter.GetLength();
  470. while (true)
  471. {
  472. int i = sSource.Find(sDelimiter, nStart);
  473. if (i < 0)
  474. break;
  475. if (i >= nStart)
  476. {
  477. CString s = sSource.Mid(nStart, i - nStart);
  478. pTokens->Add(s);
  479. }
  480. nStart = i + nLen;
  481. }
  482. //剩下的字符串
  483. if (nStart <= sSource.GetLength())
  484. pTokens->Add(sSource.Mid(nStart));
  485. }
  486. int SplitStr(CHAR *strSource, CHAR cChar, int iItem, CHAR *strGet)
  487. {
  488. int iIndex = 0;
  489. int iIndexThis = -1;
  490. int iIndexNext = -1;
  491. int iLength = 0;
  492. int iItemThis = 0;
  493. CHAR strFileName[MAX_FILE_LENGTH + 1] = "";
  494. iLength = strlen(strSource);
  495. while (iIndex < iLength)
  496. {
  497. if (strSource[iIndex] == cChar)
  498. {
  499. iItemThis++;
  500. if (iItemThis == iItem)
  501. iIndexThis = iIndex;
  502. else if (iItemThis == iItem + 1)
  503. {
  504. iIndexNext = iIndex;
  505. break;
  506. }
  507. }
  508. iIndex++;
  509. }
  510. if (iIndexNext > 0 && iIndexNext > iIndexThis)
  511. {
  512. memcpy(strGet, strSource + iIndexThis + 1, iIndexNext - iIndexThis - 1);
  513. strGet[iIndexNext - iIndexThis - 1] = '\0';
  514. }
  515. else
  516. strcpy_s(strGet, strlen(strGet), "");
  517. return 0;
  518. }
  519. /*
  520. void GetSysInfo()
  521. {
  522. WCHAR szFile[MAX_PATH + 1] = _T("");
  523. // 1.
  524. wsprintf(szFile, _T("%s\\lyfzServiceInfo.ini"), g_ModulePath);
  525. GetPrivateProfileString(_T("ServerInfo"), _T("dbServer"), _T(""), g_szDBServer, MAX_PATH, szFile);
  526. g_dwDBServerPort = GetPrivateProfileInt(_T("ServerInfo"), _T("dbServerPort"), 0, szFile);
  527. GetPrivateProfileString(_T("ServerInfo"), _T("dbAccount"), _T(""), g_szDBAccount, MAX_PATH, szFile);
  528. GetPrivateProfileString(_T("ServerInfo"), _T("dbPassWord"), _T(""), g_szDBPassWord, MAX_PATH, szFile);
  529. GetPrivateProfileString(_T("ServerInfo"), _T("dbName"), _T(""), g_szDBName, MAX_PATH, szFile);
  530. // 2.
  531. wsprintf(szFile, _T("%s\\GC0307.ini"), g_ModulePath);
  532. // 1.公共信息;
  533. g_nType = GetPrivateProfileInt(_T("CommonInfo"), _T("ConnectType"), 0, szFile);
  534. WCHAR wszMachineNumber[MAX_PATH + 1] = { 0 };
  535. GetPrivateProfileString(_T("CommonInfo"), _T("MachineNumber"), _T(""), wszMachineNumber, MAX_PATH, szFile);
  536. char szMachineNumber[MAX_PATH + 1] = { 0 };
  537. WChar2Char(szMachineNumber, wszMachineNumber);
  538. g_nMachineNumber = atol(szMachineNumber);
  539. WCHAR wszLicense[MAX_PATH + 1] = { 0 };
  540. GetPrivateProfileString(_T("CommonInfo"), _T("License"), _T(""), wszLicense, MAX_PATH, szFile);
  541. char szLicense[MAX_PATH + 1] = { 0 };
  542. WChar2Char(szLicense, wszLicense);
  543. g_nLicense = atol(szLicense);
  544. // 2.串口信息;
  545. g_nComPort = GetPrivateProfileInt(_T("SerialInfo"), _T("SerialPort"), 0, szFile);
  546. g_nBaudRate = GetPrivateProfileInt(_T("SerialInfo"), _T("Rate"), 0, szFile);
  547. g_nWaitDialTime = GetPrivateProfileInt(_T("SerialInfo"), _T("WaitDialTime"), 0, szFile);
  548. GetPrivateProfileString(_T("SerialInfo"), _T("TelNumber"), _T(""), g_szTelNumber, MAX_PATH, szFile);
  549. // 3.网络信息;
  550. GetPrivateProfileString(_T("NetInfo"), _T("IP"), _T(""), g_szIpAddress, MAX_PATH, szFile);
  551. g_nPort = GetPrivateProfileInt(_T("NetInfo"), _T("Port"), 0, szFile);
  552. g_nTimeOut = GetPrivateProfileInt(_T("NetInfo"), _T("TimeOut"), 0, szFile);
  553. g_nProtocolType = GetPrivateProfileInt(_T("NetInfo"), _T("ProtocolType"), 0, szFile);
  554. g_nNetPassword = GetPrivateProfileInt(_T("NetInfo"), _T("NetPassword"), 0, szFile);
  555. }
  556. */