00001
00002 #include "stdafx.h"
00003 #include "ComHelp.h"
00004
00005 void CIUnknownPtrList::Load(SAFEARRAY** ppsa)
00006 {
00007 ASSERT(ppsa && *ppsa);
00008 ASSERT(IsEmpty());
00009
00010 INTERFACE* *p;
00011 COMVERIFY(SafeArrayAccessData(*ppsa, (void**)&p));
00012 ASSERT(p);
00013
00014 long bound;
00015
00016 ASSERT( (*ppsa)->fFeatures | FADF_UNKNOWN );
00017 ASSERT( (*ppsa)->cbElements == sizeof(IUnknown*) );
00018 ASSERT( SafeArrayGetDim(*ppsa) == 1 );
00019 COMASSERT(SafeArrayGetLBound(*ppsa, 1, &bound));
00020 ASSERT( bound == 0 );
00021
00022 COMVERIFY(SafeArrayGetUBound(*ppsa, 1, &bound));
00023 ASSERT( bound >= -1 );
00024
00025 while( bound-- >= 0 )
00026 AddTail(*(p++));
00027
00028 COMVERIFY(SafeArrayUnaccessData(*ppsa));
00029 COMVERIFY(SafeArrayDestroyNoRelease(*ppsa));
00030 *ppsa = NULL;
00031 }
00032
00033 void CIUnknownPtrList::Copy(SAFEARRAY* psa)
00034 {
00035 ASSERT(psa);
00036 ASSERT(IsEmpty());
00037
00038 INTERFACE* *p;
00039 COMVERIFY(SafeArrayAccessData(psa, (void**)&p));
00040 ASSERT(p);
00041
00042 long bound;
00043
00044 ASSERT( SafeArrayGetDim(psa) == 1 );
00045 COMASSERT(SafeArrayGetLBound(psa, 1, &bound));
00046 ASSERT( bound == 0 );
00047
00048 COMVERIFY(SafeArrayGetUBound(psa, 1, &bound));
00049 ASSERT( bound >= -1 );
00050
00051 while( bound-- >= 0 )
00052 AddTail(*(p++));
00053
00054 COMVERIFY(SafeArrayUnaccessData(psa));
00055 }
00056
00057 SAFEARRAY* CIUnknownPtrList::Store()
00058 {
00059 SAFEARRAY *psa;
00060
00061 psa = SafeArrayCreateVector(VT_UNKNOWN, 0, GetCount());
00062 ASSERT(psa);
00063
00064 IUnknown* *p;
00065 COMVERIFY(SafeArrayAccessData(psa,(void**)&p));
00066
00067 POSITION pos = GetHeadPosition();
00068 while(pos)
00069 *(p++) = GetNext(pos);
00070
00071 COMVERIFY(SafeArrayUnaccessData(psa));
00072
00073 RemoveAll();
00074 return psa;
00075 }
00076
00077 void CIUnknownPtrList::AddRefAll()
00078 {
00079 POSITION pos = GetHeadPosition();
00080 while(pos)
00081 GetNext(pos)->AddRef();
00082 }
00083
00084 void CIUnknownPtrList::ReleaseAll()
00085 {
00086 POSITION pos = GetHeadPosition();
00087 while(pos)
00088 GetNext(pos)->Release();
00089 }
00090
00091
00092
00093 HRESULT SafeArrayDestroyNoRelease(SAFEARRAY* psa)
00094 {
00095 ASSERT(psa);
00096
00097 ASSERT( psa->fFeatures | FADF_UNKNOWN );
00098 ASSERT( psa->cbElements == sizeof(IUnknown*) );
00099
00100 psa->fFeatures &= ~FADF_UNKNOWN;
00101
00102 return SafeArrayDestroy(psa);
00103 }
00104
00105 void LoadBstrSafeArray(CStringList& dest, SAFEARRAY** ppsa)
00106 {
00107 ASSERT(ppsa && *ppsa);
00108 ASSERT(dest.IsEmpty());
00109
00110 BSTR *p;
00111 COMVERIFY(SafeArrayAccessData(*ppsa,(void**)&p));
00112 ASSERT(p);
00113
00114 long bound;
00115
00116 ASSERT( SafeArrayGetDim(*ppsa) == 1 );
00117 COMASSERT(SafeArrayGetLBound(*ppsa, 1, &bound));
00118 ASSERT( bound == 0 );
00119
00120 COMVERIFY(SafeArrayGetUBound(*ppsa, 1, &bound));
00121 ASSERT( bound >= -1 );
00122
00123 while( bound-- >= 0 )
00124 dest.AddTail(CString(*(p++)));
00125
00126 COMVERIFY(SafeArrayUnaccessData(*ppsa));
00127 COMVERIFY(SafeArrayDestroy(*ppsa));
00128 *ppsa = NULL;
00129 }
00130
00131 SAFEARRAY* StoreBstrSafeArray(CStringList& source)
00132 {
00133 SAFEARRAY *psa;
00134
00135 psa = SafeArrayCreateVector(VT_BSTR, 0, source.GetCount());
00136 ASSERT(psa);
00137
00138 BSTR *p;
00139 COMVERIFY(SafeArrayAccessData(psa,(void**)&p));
00140
00141 POSITION pos = source.GetHeadPosition();
00142 while(pos)
00143 {
00144 BSTR s = source.GetNext(pos).AllocSysString();
00145 ASSERT(s);
00146 *(p++) = s;
00147 }
00148
00149 COMVERIFY(SafeArrayUnaccessData(psa));
00150
00151 source.RemoveAll();
00152 return psa;
00153 }
00154