3. Implementation/COM & ActiveX

USES_CONVERSION : ATL and MFC String Conversion Macros

SSKK 2008. 8. 18. 22:38
USES_CONVERSION 은 ATL 3.0의 매크로로 다음과 같이 문자열 변환을 이용할 경우 미리 선언해 두는 매크로이다. (Visual C++ 6.0)

void func( LPSTR lpsz )
{
   USES_CONVERSION;
   ...
   LPWSTR x = A2W(lpsz)
   // Do something with x
   ...
}


ATL 7.0부터는 USES_CONVERSION 이라는 매크로를 사용할 필요가 없다. (.NET 이후)

아래 표는 ATL 3.0 과 ATL 7.0 의 비교하는 것이다.

 

Old ATL 3.0 Conversion Macros

New ATL 7.0 Conversion Classes

Allocates memory on the stack.

Uses stack memory for small strings. Uses the heap if the stack is not large enough.

The string is freed when the function is exited.

The string is freed when the variable goes out of scope.

Cannot be used in exception handlers.

Can be used in exception handlers.

Not suitable for use in loops. Memory use grows until the function is exited.

Supports use in loops. Loop scope ensures that memory is freed on each iteration.

Not good for large strings. Stack space is limited.

No problems with large strings. Strings will be allocated on the heap.

Usually require USES_CONVERSION to be defined.

Never require USES_CONVERSION to be defined.

Meaning of OLE depends on definition of OLE2ANSI.

OLE is always equivalent to W.

 
참고로 변환을 하드 코딩하는 API로 WideCharToMultiByte 와 MultiByteToWideChar 라는 변환 함수를 제공한다.

참고 : http://msdn.microsoft.com/ko-kr/library/87zae4a3(VS.80).aspx