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"芙蓉");//复制...
- p->sex=::SysAllocString(L"male");
- (p+1)->age=32;
- (p+1)->name=::SysAllocString(L"李松涛");
- (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;
- }
- STDMETHODIMP CMyStruct::get_UID(BSTR *pVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- *pVal=::SysAllocString(this->m_uid);
- return S_OK;
- }
- STDMETHODIMP CMyStruct::put_UID(BSTR newVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- this->m_uid=::SysAllocString(newVal);
- ::SysFreeString(newVal);
- return S_OK;
- }