Unmanaged code Debugger problem

P

Paolo Pagano

I have a VS2005 solution with two projects:



1) a .net windows forms application (which references)

2) a managed C++ CLR library (using MFC ia a Shared DLL) .



In one C++ managed class, calling unmanaged code like the one below, the
debugger jumps back an forward

on wrong source lines, making the debug impossible! Having a lot of legacy
code like this, it's a big problem.



This crazy behaviour arise instantiating a 'COleVariant' on the stack!

(ok, this old macro-based error managenment has it's role..)



Any workaround (noting that you can only slightly modify the unmanaged
code)?







// ManagedClass.cpp
....

#define CHECK_FAIL(stmt) if( FAILED(hr = (stmt)) ) return hr; else



long funct( long p ) { return 0; }





HRESULT RunTest( COleVariant& v )
{
HRESULT hr = S_OK;
COleVariant ole; // remove this line to solve!



if( v.lVal == 0 ) // put here a breakpoint, then step over

CHECK_FAIL( funct( 1 ) );
else
CHECK_FAIL( funct( 10 ) );



CHECK_FAIL( funct( 0 ) );



return hr;



} //







void ManagedClass::Run()
{
COleVariant ole( 0l );
RunTest( ole );



} //
 
B

Ben Voigt

Paolo Pagano said:
I have a VS2005 solution with two projects:



1) a .net windows forms application (which references)

2) a managed C++ CLR library (using MFC ia a Shared DLL) .



In one C++ managed class, calling unmanaged code like the one below, the
debugger jumps back an forward

on wrong source lines, making the debug impossible! Having a lot of legacy
code like this, it's a big problem.



This crazy behaviour arise instantiating a 'COleVariant' on the stack!

(ok, this old macro-based error managenment has it's role..)



Any workaround (noting that you can only slightly modify the unmanaged
code)?







// ManagedClass.cpp
...

#define CHECK_FAIL(stmt) if( FAILED(hr = (stmt)) ) return hr; else

"else" is useless

Note that return statement can cause destructors to run...
long funct( long p ) { return 0; }





HRESULT RunTest( COleVariant& v )
{
HRESULT hr = S_OK;
COleVariant ole; // remove this line to solve!

and I think COleVariant has a destructor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top