How to read the buffer from the SQL's image field type ? [modified]
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
:) I use this way to read the binary buffers from the SQL's image field type. the m_pBuffer's value is 0xFF all the same int the Debug Mode / Watch. But I use the SQL Query Analyzer, it can be found. why is it ? the filed info: Version varchar(100) Buffer image(16) the code fragment:
BOOL CTestDlg::ReadBinary()
{
try
{
OleInitialize(NULL);
CString strTemp = _T("");
CString strDat = _T("");
CString strVer = _T("");
char *pBuf = NULL;
_bstr_t bstrsource = "select * from db_somedatease";m\_pRecordset.CreateInstance("ADODB.Recordset"); m\_pRecordset->Open(bstrsource,\_variant\_t((IDispatch\*)m\_pConnection,TRUE),adOpenStatic,adLockOptimistic,adCmdText); m\_pRecordset->MoveFirst(); while(VARIANT\_FALSE == m\_pRecordset->adoEOF) { HANDLE m\_hFile = INVALID\_HANDLE\_VALUE; HANDLE m\_hMapping = INVALID\_HANDLE\_VALUE; DWORD m\_dwSize = 0; char \*m\_pSrc = NULL; char \*m\_pBuffer = NULL; \_variant\_t vtVer = m\_pRecordset->GetCollect("Version"); VARIANT varBLOB; // get the file path by version field. strVer = VariantToCString(vtVer); strTemp.Format(\_T("%s\\\\Dat\\\\%s.tmp"),GetExePath(),strVer); // get the file size, and then use file mapping. m\_dwSize = m\_pRecordset->GetFields()->GetItem("Buffer")->ActualSize; if (m\_dwSize > 0) { m\_hFile = CreateFile(strTemp,GENERIC\_ALL,FILE\_SHARE\_READ | FILE\_SHARE\_WRITE,NULL, CREATE\_ALWAYS,FILE\_ATTRIBUTE\_NORMAL,NULL); if(m\_hFile == INVALID\_HANDLE\_VALUE) { CString strError = \_T(""); strError.Format(\_T("CreateFile Failed!Error Code: %d"),GetLastError()); ::MessageBox(NULL,strError,NULL,NULL); return FALSE; } m\_hMapping = CreateFileMapping(m\_hFile,NULL,PAGE\_READWRITE,0,m\_dwSize,NULL); if(m\_hMapping == NULL) { CString strError = \_T(""); strError.Format(\_T("CreateFileMapping Failed!Error Code: %d"),GetLastError()); ::MessageBox(NULL,strError,NULL,NULL); CloseHandle(m\_hFile); return FALSE; } m\_pSrc = (char \*)MapViewOfFile(m\_hMapping,FILE\_MAP\_ALL\_ACCESS,0,0,0); if(m\_pSrc == NULL) { CString strError = \_T(""); strError.Format(\_T("MapViewOfFile Failed!Error Code: %d"),GetLastError()); ::MessageBox(NULL,strError,NULL,NULL); CloseHandle(m\_hMapping); CloseHandle(m\_hFile); } memset(m\_pSrc,0xFF,m\_dwSize); VariantInit(&varBLOB); // get the binary file size. varBLOB = m\_pRecordset->GetFields()->Get