Microsoft KB Archive/198009

= An access violation occurs when you try to call one of the string conversion macros in Visual C++ =

Article ID: 198009

Article Last Modified on 6/2/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li> Microsoft ActiveX Template Library 2.1, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q198009

<div class="symptoms_section">

SYMPTOMS
Calling one of the string conversion macros, such as OLE2T or T2OLE, inside a catch block of a try/catch exception handler causes an access violation.

<div class="cause_section">

CAUSE
Some of the string conversion macros will call _alloca. However, _alloca cannot be used inside an exception handler.

<div class="resolution_section">

RESOLUTION
Use MultiByteToWideChar or WideCharToMultiByte rather than string conversion macros inside an exception handler.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
Exception Handler (EH) routines that run on x86-class processors operate in their own memory "frame:" that is, they perform their tasks in memory space that is not based on the current location of the stack pointer of the enclosing function. Therefore, explicitly calling _alloca in any of the following scenarios results in program failure during the return to the calling EH routine:


 * Windows NT SEH exception filter expression: __except ( alloca )
 * Windows NT SEH final exception handler: __finally { alloca }
 * C++ EH catch clause expression

Steps to Reproduce Behavior
try {     throw (1); }  catch (...) {     USES_CONVERSION; LPTSTR str = OLE2T(L"Some String"); }

<div class="references_section">