I am very new to C++ so the more comments the code has the better.
Yours
Paul Felce
--
Dan Evens
Standard disclaimers etc. No spam please.
Paul Felce <Pa...@pfelce.freeserve.net> wrote in article
<7piskl$h81$1...@news7.svr.pol.co.uk>...
Best Regards,
Marc Bonet
marc....@eniac.com
--
Is better to know useless things than
don't know anything at all
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
#include <algorithm>
#include <functional>
// predicate to compare two BSTRs
class BSTRCompare : public std::binary_function<BSTR,BSTR,bool>
{
public:
bool operator()(const BSTR& lhs,const BSTR& rhs) const
{
return CComBSTR(lhs) < CComBSTR(rhs);
}
};
const STRINGARRAY = VT_ARRAY | VT_BSTR;
STMETHODIMP ATLClass::Sort(VARIANT pArray)
{
// make sure pArray contains a string array
if ( (pArray.vt & STRINGARRAY) != STRINGARRAY)
return E_INVALIDARG;
// Get the bounds of the array
long lBound,uBound;
SafeArrayGetLBound( pArray.parray, &lBound);
SafeArrayGetUBound( pArray.parray, &uBound);
// get pointer to data stored in array
BSTR* pbstr;
SafeArrayAccessData( pArray.parray, (void**)&pbstr);
// use standard algorithm to sort array
std::sort( pbstr + lBound, pbstr + uBound, BSTRCompare() );
// release array data pointer
SafeArrayUnaccessData( pArray.parray);
return S_OK;
}
-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/ The website for Visual C++ programmers.
Paul Felce <Pa...@pfelce.freeserve.net> wrote in message
news:7piskl$h81$1...@news7.svr.pol.co.uk...