大侠请帮调程序 (CArchive)在线

flyingjust 2002-07-25 05:49:27
void CDdtView::OnDraw(CDC* pDC)
{
CDdtDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CString* str=new CString();
*str=_T("a_B_C_D");
CObject* pob;
SAFEARRAY * psf=NULL;
CStrand strand;
psf=strand.MakeBlock ((CObject*)str);
pob=strand.Expand (psf);
CString st2;
st2=*(CString*)pob;
pDC->TextOut (100,299,st2);
delete str;
}


SAFEARRAY * CStrand::MakeBlock(CObject *pObject)//将pObject串行化成连续的内存块并放入SAFEARRAY
{
CMemFile memfile;
long lMode = CArchive::store
| CArchive::bNoFlushOnDelete;
CArchive ar(&memfile, lMode ); ar.m_pDocument = NULL; 出错*ar.WriteObject(pObject); ar.Close();
long llen = memfile.GetLength(); unsigned char *pMemData = memfile.Detach(); SAFEARRAY *psa; psa = SafeArrayCreateVector( VT_UI1, 0, llen ); unsigned char *pData = NULL; SafeArrayAccessData( psa, (void**)&pData ); memcpy( pData, pMemData, llen ); SafeArrayUnaccessData(psa);
return psa;
}
...全文
3 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2002-07-27
1 CObArray::Add不是静态的方法,你不能这么调用
2 参数类型错误
回复
flyingjust 2002-07-26
pOb=CObArray::Add(CString)
then pOb is a CObject Class?????
回复
flyingjust 2002-07-26
3x I will try again
回复
蒋晟 2002-07-26
CString不是CObject派生类,所以你不能把一个CString指针当CObject指针来用
你可以自己写一个SAFEARRAY * CStrand::MakeBlock(LPCTSTR lpszString)
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告