Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionproblem to draw line in list control Pin
shashankacharya8-Apr-11 19:30
shashankacharya8-Apr-11 19:30 
AnswerRe: problem to draw line in list control Pin
Nitheesh George8-Apr-11 20:18
Nitheesh George8-Apr-11 20:18 
GeneralRe: problem to draw line in list control Pin
shashankacharya8-Apr-11 22:13
shashankacharya8-Apr-11 22:13 
GeneralRe: problem to draw line in list control Pin
Rotted Frog8-Apr-11 23:02
Rotted Frog8-Apr-11 23:02 
QuestionHow can find the text file encoded in other than ANSI format? Pin
Le@rner8-Apr-11 18:29
Le@rner8-Apr-11 18:29 
AnswerRe: How can find the text file encoded in other than ANSI format? Pin
Rotted Frog8-Apr-11 22:56
Rotted Frog8-Apr-11 22:56 
AnswerRe: How can find the text file encoded in other than ANSI format? Pin
Richard MacCutchan8-Apr-11 23:20
mveRichard MacCutchan8-Apr-11 23:20 
QuestionHow to read the buffer from the SQL's image field type ? [modified] Pin
wangningyu8-Apr-11 15:55
wangningyu8-Apr-11 15:55 
Smile | :) 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()->GetItem("Buffer")->GetChunk(m_dwSize);
				if(varBLOB.vt == (VT_ARRAY | VT_UI1))
				{
					if(m_pBuffer = new char[m_dwSize + 1])
					{
						// I use new char ,or the file mapping, is 0x00 all the same. 
						memset(m_pBuffer,0x00,m_dwSize);

						// Here the m_pBuffer is 0x00 all the same. why ?
						SafeArrayAccessData(varBLOB.parray,(void **)m_pBuffer);
						memcpy(m_pSrc,m_pBuffer,m_dwSize);

						// close handle
						UnmapViewOfFile(m_pSrc);
						CloseHandle(m_hMapping);
						CloseHandle(m_hFile);
						
						SafeArrayUnaccessData(varBLOB.parray);
						
						delete [] m_pBuffer;
						m_pBuffer = NULL;
					}
				}
			}
			m_pRecordset->MoveNext();
		}
	}
	catch (_com_error e)
	{
		CString errormessage;  
		errormessage.Format("read version error!\r\n\r\nerror code:『%s』",e.ErrorMessage());
		AfxMessageBox(errormessage);
		return FALSE;
	}
	return TRUE;
}


if I use this way to read ,it is normal.

if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
        memcpy(m_pSrc,varBLOB.parray->pvData,m_dwSize);
        UnmapViewOfFile(m_pSrc);
        CloseHandle(m_hMapping);
        CloseHandle(m_hFile);

        SafeArrayUnaccessData(varBLOB.parray);
        VariantClear(&varBLOB);
}


because it doesn't use the SafeArrayAccessData, but is this way safety ?




thansk for your reply !

Best Regards !

modified on Friday, April 8, 2011 10:46 PM

QuestionHow to partially map a shared memory Pin
pandit848-Apr-11 3:06
pandit848-Apr-11 3:06 
AnswerRe: How to partially map a shared memory Pin
Niklas L8-Apr-11 21:51
Niklas L8-Apr-11 21:51 
QuestionRegistry Settings For CoCreateInstanceAsAdmin Pin
vishalgpt8-Apr-11 3:05
vishalgpt8-Apr-11 3:05 
AnswerRe: Registry Settings For CoCreateInstanceAsAdmin Pin
_AnsHUMAN_ 8-Apr-11 3:34
_AnsHUMAN_ 8-Apr-11 3:34 
GeneralRe: Registry Settings For CoCreateInstanceAsAdmin Pin
vishalgpt8-Apr-11 4:58
vishalgpt8-Apr-11 4:58 
GeneralRe: Registry Settings For CoCreateInstanceAsAdmin Pin
Richard MacCutchan8-Apr-11 5:00
mveRichard MacCutchan8-Apr-11 5:00 
GeneralRe: Registry Settings For CoCreateInstanceAsAdmin Pin
vishalgpt8-Apr-11 6:32
vishalgpt8-Apr-11 6:32 
GeneralRe: Registry Settings For CoCreateInstanceAsAdmin Pin
Richard MacCutchan8-Apr-11 22:02
mveRichard MacCutchan8-Apr-11 22:02 
GeneralRe: Registry Settings For CoCreateInstanceAsAdmin Pin
vishalgpt20-Apr-11 4:34
vishalgpt20-Apr-11 4:34 
QuestionHow can I catch SetCurSel in ComboBox control ? Pin
_Flaviu8-Apr-11 0:50
_Flaviu8-Apr-11 0:50 
AnswerRe: How can I catch SetCurSel in ComboBox control ? Pin
_Flaviu8-Apr-11 1:11
_Flaviu8-Apr-11 1:11 
AnswerRe: How can I catch SetCurSel in ComboBox control ? Pin
Richard MacCutchan8-Apr-11 1:38
mveRichard MacCutchan8-Apr-11 1:38 
GeneralRe: How can I catch SetCurSel in ComboBox control ? Pin
_Flaviu8-Apr-11 1:47
_Flaviu8-Apr-11 1:47 
AnswerRe: How can I catch SetCurSel in ComboBox control ? Pin
వేంకటనారాయణ(venkatmakam)8-Apr-11 1:54
వేంకటనారాయణ(venkatmakam)8-Apr-11 1:54 
GeneralRe: How can I catch SetCurSel in ComboBox control ? Pin
_Flaviu8-Apr-11 2:06
_Flaviu8-Apr-11 2:06 
AnswerRe: How can I catch SetCurSel in ComboBox control ? Pin
వేంకటనారాయణ(venkatmakam)8-Apr-11 2:17
వేంకటనారాయణ(venkatmakam)8-Apr-11 2:17 
GeneralRe: How can I catch SetCurSel in ComboBox control ? Pin
_Flaviu8-Apr-11 3:12
_Flaviu8-Apr-11 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.