Microsoft KB Archive/310827

= A Probe function that is injected by profiler may cause unhandled exception in Visual C++ =

Article ID: 310827

Article Last Modified on 1/18/2006

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ 2005 Express Edition

-



This article was previously published under Q310827



SYMPTOMS
If the injection probe function's metadata does not set the miPreserveSig flag through IMetaDataEmit::DefineMethod, the profiled application might throw unhandled exceptions.



CAUSE
By default, the DefineMethod call &quot;mangles&quot; the function signature to do the HRESULT conversion. If the probe function does not return &quot;HRESULT&quot;, the resulting mismatch may cause the application that is being profiled to fail.



RESOLUTION
To avoid this problem, use the miPreserveSig flag when you use IMetaDataEmit::DefineMethod to inject a probe function. For example: (pModuleInfo->m_pEmit)->DefineMethod( mdTokenNil,          L&quot;ILCoverFunc&quot;,           mdPublic|mdStatic|mdPinvokeImpl,           rgSig,           sizeof( rgSig ),           0,           miIL | miPreserveSig,  // NOTE THE miPreserveSig.           &(pModuleInfo->m_tkProbe) )



STATUS
This behavior is by design.

