473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unmanaged code Debugger problem

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 );

} //

Apr 27 '07 #1
1 1181

"Paolo Pagano" <pp*****@userportal.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>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.
>
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 );

} //

May 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | ov | last post by:
Hi, My application includes a class library which has both managed C++ and unmanaged C++ code. The unmanaged C++ code includes only one class with both virtual methods and non-virtual methods....
2
by: Ken Allen | last post by:
I have a managed .Net assembly (C#) that invokes code in an unmanaged DLL written in C++ 6 via an unsafe assembly that invokes the C++ routines and marshals the data. The interface is not working...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
0
by: Yanick Masse | last post by:
I'm writing an MFC ActiveX control and some C function expose in a DLL that will be used in Visual Basic .NET and Visual C#. I want to detect in my code if we are currently beeing debugged by any...
2
by: asanford | last post by:
We use StackWalk(StackWalk64) from dbghelp.dll to walk our callstacksas needed, using the various Sym* methods (SymGetSymFromAddr, SymGetLineFromAddr) to resolve source file, function name, and...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
0
by: Frank Lopez | last post by:
My program structure is: 1. 2. 3. => manually does the crt-init and crt-terminate calls 4. -- this is accessed by the unmanaged C++ classes in (3) using LoadLibrary and FreeLibrary
7
by: Lev | last post by:
Hi, I have an unmanaged pointer to a class that I want to hold in a managed class. I pass the pointer (from unmanaged code) in the constructor of the managed class, and at that point it has...
3
by: dvestal | last post by:
Sorry if this double-posts, google just crashed on me. I'm trying to debug an unmanaged C++ DLL from a C# application. The C# app references the DLL using DLLImport attributes. They are in the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.