[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Release Memory Allocated by A2W

Posted on 2009-02-11
4
Medium Priority
?
1,014 Views
Last Modified: 2013-12-14
Im using A2W to convert from char* to LPCWSTR.
What must I do to release the memory used by A2W before returning?

LPCWSTR foo;
char* bar;
foo = A2W(bar);
...
return 0;

Open in new window

0
Comment
Question by:Dannen
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 23618752
Add USES_CONVERSION to your funtion/method and that wil be taken care of automatically, e.g.
USES_CONVERSION;
LPCWSTR foo;
char* bar;
foo = A2W(bar);
...
return 0;

Open in new window

0
 

Author Comment

by:Dannen
ID: 23618904
I use USES_CONVERSION yet, the memory seems to still be unallocated.
Any other suggestions?
0
 
LVL 6

Accepted Solution

by:
Mushq earned 500 total points
ID: 23619957
A2W allocates memory on stack based.
you can write that function in a separate function when that function ends memory will be automatically released.

Please check http://untidy.net/blog/2004/12/17/uses_conversion/ for detailed description.
0
 

Author Comment

by:Dannen
ID: 23625659
#include <atlconv.h>
#include <tchar.h>
...
CA2W mywide ( mychar );
...
error C3861: 'CA2W': identifier not found

Seriously, how comes it doesn't recognize it, even if it Visual Studio shows me the valid syntax?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

825 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