MyStruct.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:1k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // MyStruct.cpp : Implementation of CMyStruct
- #include "stdafx.h"
- #include "StructDemo.h"
- #include "MyStruct.h"
- /////////////////////////////////////////////////////////////////////////////
- // CMyStruct
- STDMETHODIMP CMyStruct::GetPersonById(UINT id,StPerson** Result)
- {
- StPerson* p=(StPerson*)::CoTaskMemAlloc(sizeof(StPerson));
- p->age=23;
- p->name=::SysAllocString(L"zhangsan");
- p->sex=::SysAllocString(L"male");
- *Result=p;
- return S_OK;
- }
- STDMETHODIMP CMyStruct::GetAllPerson(UINT* number,StPerson** Result)
- {
- StPerson* p=(StPerson*)::CoTaskMemAlloc(2*sizeof(StPerson));
- ZeroMemory(p,2*sizeof(StPerson));
- p->age=23;
- p->name=::SysAllocString(L"zhangsan");
- p->sex=::SysAllocString(L"male");
- (p+1)->age=23;
- (p+1)->name=::SysAllocString(L"zhangsan1");
- (p+1)->sex=::SysAllocString(L"male");
- *Result=p;
- *number=2;
- return S_OK;
- }
- STDMETHODIMP CMyStruct::SavePerson(UINT number,StPerson* Result, UINT* pResult)
- {
- int iResult=0;
- for(int i=0;i<number;i++)
- {
- iResult+=(Result+i)->age;
- }
- *pResult=iResult;
- return S_OK;
- }