Link to home
Start Free TrialLog in
Avatar of Dredwick
Dredwick

asked on

ATL COM Object GET property using BSTR

Is this code correct..IE will it product memory leaks?


STDMETHODIMP CUPS::get_m_strLastError(BSTR *pVal)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState())

    // TODO: Add your implementation code here
    SysFreeString(*pVal);
    CString strError;

    strError="<font style='font-size:10pt;font-family:Verdana,Arial;'>";
    strError+=m_strLastError+"</font>\0";

    int iSize=strError.GetLength();
    char* str = strError.GetBuffer(iSize);
    unsigned short *newstr= NULL;
   
    int iWideSize=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,str,-1,newstr,0);

    newstr = new unsigned short[iWideSize];
    memset(newstr,0,iWideSize);

    MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,str,-1,newstr,iWideSize);
    *pVal=SysAllocString(newstr);

    delete (unsigned short*)newstr;
    strError.ReleaseBuffer();
    return S_OK;
}
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dredwick
Dredwick

ASKER

Thanks Migel!