GetDlgItemText(pInfo->hDbgDlg, IDC_EDIT_CONFIG_FILE, swBuf, MAX_PATH);
LogOut(LEVEL_MSG, swBuf);
ReadBinFile(swBuf, outData, 256); //read data from bin file
int ReadBinFile(TCHAR *pfilename, CHAR *pData, ULONGLONG fileSize)
{
INT iRet = 0;
CFile BinFile;
CString strFilename;
ULONGLONG TotalFileSize;
CString strTemp;
TCHAR cTemp[MAX_TEMP];
strFilename.Format(L"%s", pfilename);
if (!BinFile.Open(strFilename, CFile::modeRead))
{
strTemp.Format(_T("Failed to open file %s"), strFilename);
_tcscpy(cTemp, strTemp);
LogOut(LEVEL_MSG, cTemp);
}
TotalFileSize = BinFile.GetLength();
if (fileSize > TotalFileSize)
{
strTemp = _T("The read data size is over the total size");
_tcscpy(cTemp, strTemp);
LogOut(LEVEL_MSG, cTemp);
}
BinFile.Read(pData, fileSize);
BinFile.Close();
return iRet;
}
int ReadBinFile(TCHAR *ptcFileName, UCHAR *pData, ULONGLONG fileSize)
{
INT iRet = 0;
FILE *pReadFile;
char *pcFileName;
ULONGLONG TotalFileSize;
CString strTemp;
TCHAR cTemp[MAX_TEMP];
USES_CONVERSION;
pcFileName = W2A(ptcFileName);
pReadFile = fopen(pcFileName, "rb");
if (pReadFile == NULL)
{
strTemp.Format(_T("Failed to open file %s"), pcFileName);
_tcscpy(cTemp, strTemp);
LogOut(LEVEL_MSG, cTemp);
}
fseek(pReadFile, 0, SEEK_END);
TotalFileSize = ftell(pReadFile);
if (fileSize > TotalFileSize)
{
strTemp = _T("The read data size is over the total size");
_tcscpy(cTemp, strTemp);
LogOut(LEVEL_MSG, cTemp);
}
rewind(pReadFile);
fread(pData, sizeof(unsigned char), fileSize, pReadFile);
fclose(pReadFile);
pReadFile = NULL;
return iRet;
}