ATL COM Object GET property using BSTR

Posted on 2002-07-26
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Accepted Solution

migel earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

801 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