ATL COM Object GET property using BSTR

Posted on 2002-07-26
Last Modified: 2013-11-25
Is this code correct..IE will it product memory leaks?

STDMETHODIMP CUPS::get_m_strLastError(BSTR *pVal)

    // TODO: Add your implementation code here
    CString strError;

    strError="<font style='font-size:10pt;font-family:Verdana,Arial;'>";

    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];


    delete (unsigned short*)newstr;
    return S_OK;
Question by:Dredwick
LVL 12

Accepted Solution

migel earned 50 total points
ID: 7183276
no your code will not lead to memory leak
but some additions:

// here you jave to use WCHAR
 newstr = new WCHAR[iWideSize]; //<<


   delete[] newstr; //<<<

Author Comment

ID: 7183553
Thanks Migel!

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 96
ffmpeg - "rtsp://...... Operation not permitted" 4 68
Doc'in system (example?) BA 7 78
lucky13 challenge 11 111
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now