Browse Source

ReadKeyFromFile

sat23 4 năm trước cách đây
mục cha
commit
2704e442b7
1 tập tin đã thay đổi với 29 bổ sung0 xóa
  1. 29 0
      TCLTools/TCLTools/TCLToolsDlg.cpp

+ 29 - 0
TCLTools/TCLTools/TCLToolsDlg.cpp

@@ -63,6 +63,35 @@ BOOL GetSysSerialPort(std::vector<std::string>& vtports)
     return TRUE;
 }
 
+bool ReadKeyFromFile(std::string file, std::string &data)
+{
+    FILE* pf = NULL;
+    if (fopen_s(&pf, file.c_str(), _T("rb")) == 0)
+    {
+        if (pf)
+        {
+            fseek(pf, 0, SEEK_END);
+            size_t fs = ftell(pf);
+            fseek(pf, 0, SEEK_SET);
+
+            byte* pdata = (byte*)malloc(fs);
+            if (pdata)
+            {
+                fread(pdata, fs, 1, pf);
+                fclose(pf);
+
+                data.append((char*)pdata, fs);
+                free(pdata);
+
+                return true;
+            }
+            fclose(pf);
+        }
+    }
+
+    return false;
+}
+
 
 CTCLToolsDlg::CTCLToolsDlg(CWnd* pParent /*=NULL*/)
 	: CDialog(CTCLToolsDlg::IDD, pParent)