OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: Mike Caito (249507NKNOTES.KODAK.COM)
Date: Fri Mar 22 2002 - 07:36:05 CST

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    Your CString buffer has no length prior to calling GetLBText. The passed
    in buffer must be sufficient size to hold the return string and null
    character. Try adding:

          n = m_Drive1.GetLBTextLen(nIndex);
          m_Drive1.GetLBText(nIndex , buffer.GetBuffer(n)); // allocates buffer
          buffer.ReleaseBuffer(); // need to call Release after GetBuffer
          FindFileExample((LPCTSTR)buffer);

    -Mike

    On Thu, 21 Mar 2002 19:21:47 +0200, diaconu ionut
    <diaconuMARCONI.UNITBV.RO> wrote:

    >what`s wrong with this code?
    >
    >
    >void CManagerDlg::OnFindFiles()
    >{
    >CString buffer;
    >char* dd;
    >
    >int nIndex = m_Drive1.GetCurSel();
    >if(nIndex != CB_ERR)
    >{
    >m_Drive1.GetLBText(nIndex,buffer);
    >dd=buffer.GetBuffer(1);
    >FindFileExample(dd); //dd must be char*
    >}
    >
    >Johnny
    >----- Original Message -----
    >From: "Hans Ellsater" <hans.ellsaterINTENTIA.SE>
    >To: <DCOMDISCUSS.MICROSOFT.COM>
    >Sent: Thursday, March 21, 2002 3:13 PM
    >Subject: Re: (OT)Stupid get text from ComboBox question
    >
    >
    >> The implementation of GetLBTextBSTR in AtlCtrls.h will alloc to the
    passed
    >> BSTR ref, when the method goes out of scope, the CComBSTR will free the
    >> string in the destructor, is this wrong?, it does not crash for me.
    >>
    >> BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
    >> {
    >> USES_CONVERSION;
    >> ATLASSERT(::IsWindow(m_hWnd));
    >> ATLASSERT(bstrText == NULL);
    >>
    >> int nLen = GetLBTextLen(nIndex);
    >> if(nLen == CB_ERR)
    >> return FALSE;
    >>
    >> LPTSTR lpszText = (LPTSTR)_alloca((nLen + 1) * sizeof
    (TCHAR));
    >>
    >> if(GetLBText(nIndex, lpszText) == CB_ERR)
    >> return FALSE;
    >>
    >> bstrText = ::SysAllocString(T2OLE(lpszText));
    >> return (bstrText != NULL) ? TRUE : FALSE;
    >> }
    >>
    >> /Hasse
    >>
    >> ----------------------------------------------------------------
    >> Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    >> contains important info. Save time, search the archives at
    >> http://discuss.microsoft.com/archives/index.html .
    >> To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM
    >>
    >
    >----------------------------------------------------------------
    >Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    >contains important info. Save time, search the archives at
    >http://discuss.microsoft.com/archives/index.html .
    >To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM

    ----------------------------------------------------------------
    Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    contains important info. Save time, search the archives at
    http://discuss.microsoft.com/archives/index.html .
    To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM