3D FPS

1234567890

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  57 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks

常用链接

留言簿(10)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

com安全数组类型

创建 复制数据给它 例如这样:

 1// set up safearray -  SAFEARRAY is defined OAIDL.H
 2 SAFEARRAY *psa;
 3
 4 // create a safe array to store the stream data
 5 psa = SafeArrayCreateVector( VT_UI1, 0, llen );
 6
 7 // pointers to byte arrays
 8 unsigned char *pData = NULL;
 9
10 // get a pointer to the safe array. Locks the array.
11 SafeArrayAccessData( psa, (void**)&pData );
12 
13 // copy the memory file into the safearray
14 memcpy( pData, pMemData, llen );
15
16 // clean up buffer
17 delete pMemData;
18 
19 // unlock access to safearray
20 SafeArrayUnaccessData(psa);
21
22 // return a pointer to a SAFEARRAY allocated here
23 return psa;
24
25



 接收 复制数据给别人 例如这样: 

 1 long lLength;   // number of bytes
 2 char *pBuffer;   // buffer pointer
 3 
 4 // lock access to array data
 5 SafeArrayAccessData( psa, (void**)&pBuffer  );
 6
 7 // get number of elements in array. This is the number of bytes
 8 lLength = psa->rgsabound->cElements;
 9
10 // attach the buffer to the memory file
11 memfile.Attach((unsigned char*)pBuffer, lLength);
12
13 // start at beginning of buffer
14 memfile.SeekToBegin();
15
16 // create an archive with the attached memory file
17 CArchive ar(&memfile, CArchive::load | CArchive::bNoFlushOnDelete);
18
19 // document pointer is not used
20 ar.m_pDocument = NULL;
21
22 // inflate the object and get the pointer
23 rpObj = ar.ReadObject(0);
24
25 // close the archive
26 ar.Close();
27
28 // Note: pBuffer is freed when the SAFEARRAY is destroyed
29 // Detach the buffer and close the file
30 pBuffer = (char*) memfile.Detach();
31
32
33 // release the safearray buffer
34 SafeArrayUnaccessData( psa );
35





posted on 2011-12-25 18:43 DK_jims 阅读(330) 评论(0)  编辑 收藏 引用 所属分类: C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理