cstring源码
Ⅰ 有框架的网页,如何读取框架里的源码
用chtmlview打带框架网页写面函数
 BOOL CHtmlView::GetFrameSource( IDispatch *pDisp, CString& refString )
 {
     BOOL bRetVal = FALSE;
     HRESULT hr = S_OK;
     if ( pDisp != NULL )
     {
         CComQIPtr pBrowser = pDisp;
         if ( pBrowser != NULL )
         {
             IDispatch *pDispDoc = NULL;
             hr = pBrowser->get_Document(&pDispDoc);
             if ( !( FAILED(hr) || !pDisp ) ) 
             {
                 CComQIPtr pStmInit = pDisp;
                 if ( !pStmInit )
                 {
                     HGLOBAL hMemory;
                     hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
                     if (hMemory != NULL)
                     {
                         CComQIPtr spPSI = pDispDoc;
                         if( spPSI != NULL)
                         {
                             CComPtr spStream;
                             if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
                             {
                                 spPSI->Save(spStream, FALSE);
                                 LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
                                 if (pstr != NULL)
                                 {
                                     // Stream is always ANSI, but CString
                                     // assignment operator will convert implicitly.
                                     bRetVal = TRUE;
                                     TRY
                                     {                       
                                         refString = pstr;
                                     }
                                     CATCH_ALL(e)
                                     {
                                         bRetVal = FALSE;
                                         DELETE_EXCEPTION(e);
                                     }
                                     END_CATCH_ALL
 
                                        if(bRetVal == FALSE)
                                             GlobalFree(hMemory);
                                         else
                                             GlobalUnlock(hMemory);
                                 }
                             }
                         }
                     }
                 }
             }
             RELEASE(pDispDoc);
         }
     }
     return bRetVal;
 }
 
能用DocumentComplete我知道获pDisp像DocumentComplete才能获框架各页pDisp没通用性我想要实现像GetSource功能要网页载完毕任意刻获框架html源文件!
Ⅱ C++如何调用vb写的COM组件要附源码【不是vb调c++ 而是c++调vb】
1.我的VB工程代码如下:
1)新建工程名为Project1的VB工程,接口为Class1,定义两个成员变量a和b
2)在Class1中添加代码
Public a As Integer
Public b As Integer
Private Sub Class_Initialize()
    a = 5
    b = 9
End Sub
2.我的VC工程代码如没伏下:
1)在stdafx.h文件中写如下代码
#include <comdef.h>
#import "C:\\Documents and Settings\\user\\桌面卜慎\\VB\型察敬\Project1.dll"
using namespace Project1;
2)在CPP源文件中写如下调用COM代码
::CoInitialize(NULL);
_Class1Ptr c1 = NULL;
c1.CreateInstance("Project1.Class1");
short sA = c1->a;
short sB = c1->b;
CString str = _T("");
str.Format(_T("a=%d, b=%d"),sA,sB);
::CoUninitialize();
Ⅲ MFC的CString的数据结构
跟java里面的StringBuilder更类似,不是java里String那样的不变对象。CString采用的是顺序存储。源代码用了条件编译,可读性不好。 
class CString
{
public:
// Constructors
 // constructs empty CString
 CString();
 //  constructor
 CString(const CString& stringSrc);
 // from a single character
 CString(TCHAR ch, int nRepeat = 1);
 // from an ANSI string (converts to TCHAR)
 CString(LPCSTR lpsz);
 // from a UNICODE string (converts to TCHAR)
 CString(LPCWSTR lpsz);
 // subset of characters from an ANSI string (converts to TCHAR)
 CString(LPCSTR lpch, int nLength);
 // subset of characters from a UNICODE string (converts to TCHAR)
 CString(LPCWSTR lpch, int nLength);
 // from unsigned characters
 CString(const unsigned char* psz);
// Attributes & Operations
 // get data length
 int GetLength() const;
 // TRUE if zero length
 BOOL IsEmpty() const;
 // clear contents to empty
 void Empty();
 // return single character at zero-based index
 TCHAR GetAt(int nIndex) const;
 // return single character at zero-based index
 TCHAR operator[](int nIndex) const;
 // set a single character at zero-based index
 void SetAt(int nIndex, TCHAR ch);
 // return pointer to const string
 operator LPCTSTR() const;
 // overloaded assignment
 // ref-counted  from another CString
 const CString& operator=(const CString& stringSrc);
 // set string content to single character
 const CString& operator=(TCHAR ch);
#ifdef _UNICODE
 const CString& operator=(char ch);
#endif
 //  string content from ANSI string (converts to TCHAR)
 const CString& operator=(LPCSTR lpsz);
 //  string content from UNICODE string (converts to TCHAR)
 const CString& operator=(LPCWSTR lpsz);
 //  string content from unsigned chars
 const CString& operator=(const unsigned char* psz);
 // string concatenation
 // concatenate from another CString
 const CString& operator+=(const CString& string);
 // concatenate a single character
 const CString& operator+=(TCHAR ch);
#ifdef _UNICODE
 // concatenate an ANSI character after converting it to TCHAR
 const CString& operator+=(char ch);
#endif
 // concatenate a UNICODE character after converting it to TCHAR
 const CString& operator+=(LPCTSTR lpsz);
 friend CString AFXAPI operator+(const CString& string1,
   const CString& string2);
 friend CString AFXAPI operator+(const CString& string, TCHAR ch);
 friend CString AFXAPI operator+(TCHAR ch, const CString& string);
#ifdef _UNICODE
 friend CString AFXAPI operator+(const CString& string, char ch);
 friend CString AFXAPI operator+(char ch, const CString& string);
#endif
 friend CString AFXAPI operator+(const CString& string, LPCTSTR lpsz);
 friend CString AFXAPI operator+(LPCTSTR lpsz, const CString& string);
 // string comparison
 // straight character comparison
 int Compare(LPCTSTR lpsz) const;
 // compare ignoring case
 int CompareNoCase(LPCTSTR lpsz) const;
 // NLS aware comparison, case sensitive
 int Collate(LPCTSTR lpsz) const;
 // NLS aware comparison, case insensitive
 int CollateNoCase(LPCTSTR lpsz) const;
 // simple sub-string extraction
 // return nCount characters starting at zero-based nFirst
 CString Mid(int nFirst, int nCount) const;
 // return all characters starting at zero-based nFirst
 CString Mid(int nFirst) const;
 // return first nCount characters in string
 CString Left(int nCount) const;
 // return nCount characters from end of string
 CString Right(int nCount) const;
 //  characters from beginning that are also in passed string
 CString SpanIncluding(LPCTSTR lpszCharSet) const;
 // characters from beginning that are not also in passed string
 CString SpanExcluding(LPCTSTR lpszCharSet) const;
 // upper/lower/reverse conversion
 // NLS aware conversion to uppercase
 void MakeUpper();
 // NLS aware conversion to lowercase
 void MakeLower();
 // reverse string right-to-left
 void MakeReverse();
 // trimming whitespace (either side)
 // remove whitespace starting from right edge
 void TrimRight();
 // remove whitespace starting from left side
 void TrimLeft();
 // trimming anything (either side)
 // remove continuous occurrences of chTarget starting from right
 void TrimRight(TCHAR chTarget);
 // remove continuous occcurrences of characters in passed string,
 // starting from right
 void TrimRight(LPCTSTR lpszTargets);
 // remove continuous occurrences of chTarget starting from left
 void TrimLeft(TCHAR chTarget);
 // remove continuous occcurrences of characters in
 // passed string, starting from left
 void TrimLeft(LPCTSTR lpszTargets);
 // advanced manipulation
 // replace occurrences of chOld with chNew
 int Replace(TCHAR chOld, TCHAR chNew);
 // replace occurrences of substring lpszOld with lpszNew;
 // empty lpszNew removes instances of lpszOld
 int Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
 // remove occurrences of chRemove
 int Remove(TCHAR chRemove);
 // insert character at zero-based index; concatenates
 // if index is past end of string
 int Insert(int nIndex, TCHAR ch);
 // insert substring at zero-based index; concatenates
 // if index is past end of string
 int Insert(int nIndex, LPCTSTR pstr);
 // delete nCount characters starting at zero-based index
 int Delete(int nIndex, int nCount = 1);
 // searching
 // find character starting at left, -1 if not found
 int Find(TCHAR ch) const;
 // find character starting at right
 int ReverseFind(TCHAR ch) const;
 // find character starting at zero-based index and going right
 int Find(TCHAR ch, int nStart) const;
 // find first instance of any character in passed string
 int FindOneOf(LPCTSTR lpszCharSet) const;
 // find first instance of substring
 int Find(LPCTSTR lpszSub) const;
 // find first instance of substring starting at zero-based index
 int Find(LPCTSTR lpszSub, int nStart) const;
 // simple formatting
 // printf-like formatting using passed string
 void AFX_CDECL Format(LPCTSTR lpszFormat, ...);
 // printf-like formatting using referenced string resource
 void AFX_CDECL Format(UINT nFormatID, ...);
 // printf-like formatting using variable arguments parameter
 void FormatV(LPCTSTR lpszFormat, va_list argList);
 // formatting for localization (uses FormatMessage API)
 // format using FormatMessage API on passed string
 void AFX_CDECL FormatMessage(LPCTSTR lpszFormat, ...);
 // format using FormatMessage API on referenced string resource
 void AFX_CDECL FormatMessage(UINT nFormatID, ...);
 // input and output
#ifdef _DEBUG
 friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,
    const CString& string);
#endif
 friend CArchive& AFXAPI operator<<(CArchive& ar, const CString& string);
 friend CArchive& AFXAPI operator>>(CArchive& ar, CString& string);
 // load from string resource
 BOOL LoadString(UINT nID);
#ifndef _UNICODE
 // ANSI <-> OEM support (convert string in place)
 // convert string from ANSI to OEM in-place
 void AnsiToOem();
 // convert string from OEM to ANSI in-place
 void OemToAnsi();
#endif
#ifndef _AFX_NO_BSTR_SUPPORT
 // OLE BSTR support (use for OLE automation)
 // return a BSTR initialized with this CString's data
 BSTR AllocSysString() const;
 // reallocates the passed BSTR, copies content of this CString to it
 BSTR SetSysString(BSTR* pbstr) const;
#endif
 // Access to string implementation buffer as "C" character array
 // get pointer to modifiable buffer at least as long as nMinBufLength
 LPTSTR GetBuffer(int nMinBufLength);
 // release buffer, setting length to nNewLength (or to first nul if -1)
 void ReleaseBuffer(int nNewLength = -1);
 // get pointer to modifiable buffer exactly as long as nNewLength
 LPTSTR GetBufferSetLength(int nNewLength);
 // release memory allocated to but unused by string
 void FreeExtra();
 // Use LockBuffer/UnlockBuffer to turn refcounting off
 // turn refcounting back on
 LPTSTR LockBuffer();
 // turn refcounting off
 void UnlockBuffer();
// Implementation
public:
 ~CString();
 int GetAllocLength() const;
protected:
 LPTSTR m_pchData;   // pointer to ref counted string data
 // implementation helpers
 CStringData* GetData() const;
 void Init();
 void AllocCopy(CString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
 void AllocBuffer(int nLen);
 void AssignCopy(int nSrcLen, LPCTSTR lpszSrcData);
 void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data, int nSrc2Len, LPCTSTR lpszSrc2Data);
 void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
 void CopyBeforeWrite();
 void AllocBeforeWrite(int nLen);
 void Release();
 static void PASCAL Release(CStringData* pData);
 static int PASCAL SafeStrlen(LPCTSTR lpsz);
 static void FASTCALL FreeData(CStringData* pData);
};
