///////////////////////////////////////////////////////////////////// // StringArrays.cpp - Implements ATL-based CStringArrays class // // for ATL_OutProcST project // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2007 // ///////////////////////////////////////////////////////////////////// /* * NOTE: * - Do not include this file in client's project * - Instead, include ATL_OutProcST_i.c, which provides GUID * definitions */ // StringArrays.cpp : Implementation of CStringArrays #include "stdafx.h" #include "StringArrays.h" #include #include #include // CStringArrays STDMETHODIMP CStringArrays::PutStrings(SAFEARRAY* strings) { CComSafeArray arrayOfStrings; arrayOfStrings.Attach(strings); // Since this is a Windows application, we don't have // a console. We'll display output in a MessageBox // instead. std::wostringstream temp; temp << L"Server received SafeArray of " << arrayOfStrings.GetCount() << L" BSTRs: "; for(int i=0; i<(int)arrayOfStrings.GetCount(); ++i) temp << L"\n " << arrayOfStrings[i].Copy(); temp << L"\n\n"; arrayOfStrings.Detach(); MessageBox(NULL,temp.str().c_str(),L"arrayOfStrings",MB_OK); return S_OK; } STDMETHODIMP CStringArrays::GetStrings(SAFEARRAY** strings) { CComSafeArray arrayOfStrings; CComBSTR bstr0(L"The Marx brothers:"); CComBSTR bstr1(L" Harpo"); CComBSTR bstr2(L" Zeppo"); CComBSTR bstr3(L" Groucho"); arrayOfStrings.Add(bstr0); arrayOfStrings.Add(bstr1); arrayOfStrings.Add(bstr2); arrayOfStrings.Add(bstr3); *strings = arrayOfStrings.Detach(); return S_OK; }