473,662 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

debugging mixed mode assembly

hi,
I'm still in the process of transiting from MFC/VC6 to vs2005, and a
lot of things are very alien to me. So hope you could bear with me if my
question sounds stupid. Basically I have native codes written in VC6
which I want to encapsulate in a managed assembly using C++/CLI so that
I can use it in C# easily without all the interop codes. So, my question
is, what is the replacement for MFC's TRACE macro in VS2005's C++/CLI
in native(unmanage d) codes?

I tried to see what's inside a WCHAR buffer declared as

WCHAR Buffer[256];

in MFC, it's as simple as
TRACE1("\n Buffer=%s", Buffer);

I tried using
Debug::Write("\ n Buffer="+Buffer );
which failed spectacularly.

I also tried
String^ s;
s->format("\n Buffer=%s", Buffer);
Debug::Write(s) ;
which the IDE complained as parameter 2 of String::format is not Object,
which obviously is not since this is in native code. I also tried
ATLTRACE2(atlGe neral, 4, "\n Buffer=%s", Buffer);
but I was unable to see anything in the IDE's output window.,

when I used win32's OutputDebugStri ng directly, coupled with wcsprintf,
I was able to achieve something like the TRACE macro. However, I would
expect VS2005 to free me from this hassle. So, could someone please
enlighten me on this? thank yoy very much.
Jan 5 '06 #1
4 2233
Again why do you call this unmanaged code?
C++/CLI compiles to managed code,
String^ s; is a managed string reference.
this:
s->format("\n Buffer=%s", Buffer);
can't even compile, format is not a String method!

so what you should do is this (a copy of a reply to your other posting):

<
I guess you mean from managed code, here is how...

wchar_t *unm = L"Test";
String ^s = String::Format( "{0}", Marshal::PtrToS tringUni((IntPt r)unm));
Debug::Write(s) ;
But you should definitely read the MSDN docs about unmanaged/managed interop
and managed debugging before posting.

Willy.


"Lonewolf" <an*******@mozi lla.org> wrote in message
news:OY******** ******@TK2MSFTN GP11.phx.gbl... hi,
I'm still in the process of transiting from MFC/VC6 to vs2005, and a lot
of things are very alien to me. So hope you could bear with me if my
question sounds stupid. Basically I have native codes written in VC6 which
I want to encapsulate in a managed assembly using C++/CLI so that I can
use it in C# easily without all the interop codes. So, my question is,
what is the replacement for MFC's TRACE macro in VS2005's C++/CLI in
native(unmanage d) codes?

I tried to see what's inside a WCHAR buffer declared as

WCHAR Buffer[256];

in MFC, it's as simple as
TRACE1("\n Buffer=%s", Buffer);

I tried using
Debug::Write("\ n Buffer="+Buffer );
which failed spectacularly.

I also tried
String^ s;
s->format("\n Buffer=%s", Buffer);
Debug::Write(s) ;
which the IDE complained as parameter 2 of String::format is not Object,
which obviously is not since this is in native code. I also tried
ATLTRACE2(atlGe neral, 4, "\n Buffer=%s", Buffer);
but I was unable to see anything in the IDE's output window.,

when I used win32's OutputDebugStri ng directly, coupled with wcsprintf, I
was able to achieve something like the TRACE macro. However, I would
expect VS2005 to free me from this hassle. So, could someone please
enlighten me on this? thank yoy very much.

Jan 5 '06 #2
check out the Trace class of the system diagnostics namespace.
for example:

if you have a WCHAR string, you can simply create a managed string by
passing that WCHAR string to a managed string constructor. then you can pass
that managed string to Trace.

Trace::WriteLin e(L"Hello World");
will print Hello world as tracing output.
the neat thing is that you can enable or disable trace statements at runtime.

with TraceListeners you can even create your own handling of tracing output
(for example logging to disk etc).

kind regards,
Bruno.

"Lonewolf" wrote:
hi,
I'm still in the process of transiting from MFC/VC6 to vs2005, and a
lot of things are very alien to me. So hope you could bear with me if my
question sounds stupid. Basically I have native codes written in VC6
which I want to encapsulate in a managed assembly using C++/CLI so that
I can use it in C# easily without all the interop codes. So, my question
is, what is the replacement for MFC's TRACE macro in VS2005's C++/CLI
in native(unmanage d) codes?

I tried to see what's inside a WCHAR buffer declared as

WCHAR Buffer[256];

in MFC, it's as simple as
TRACE1("\n Buffer=%s", Buffer);

I tried using
Debug::Write("\ n Buffer="+Buffer );
which failed spectacularly.

I also tried
String^ s;
s->format("\n Buffer=%s", Buffer);
Debug::Write(s) ;
which the IDE complained as parameter 2 of String::format is not Object,
which obviously is not since this is in native code. I also tried
ATLTRACE2(atlGe neral, 4, "\n Buffer=%s", Buffer);
but I was unable to see anything in the IDE's output window.,

when I used win32's OutputDebugStri ng directly, coupled with wcsprintf,
I was able to achieve something like the TRACE macro. However, I would
expect VS2005 to free me from this hassle. So, could someone please
enlighten me on this? thank yoy very much.

Jan 5 '06 #3
Willy Denoyette [MVP] wrote:
Again why do you call this unmanaged code?
C++/CLI compiles to managed code,
String^ s; is a managed string reference.
this:
s->format("\n Buffer=%s", Buffer);
can't even compile, format is not a String method!

so what you should do is this (a copy of a reply to your other posting):

<
I guess you mean from managed code, here is how...

wchar_t *unm = L"Test";
String ^s = String::Format( "{0}", Marshal::PtrToS tringUni((IntPt r)unm));
Debug::Write(s) ;

OK, I understand now. But still, is there no C++/CLI substitute for the
MFC TRACE or the C "printf" which can be used conveniently? it's such a
bloody pain to write all the marshal code. right now, I'm using back the
old dprintf function which I used in the old days of Windows SDK
programming. it's declared as,

void cdecl dprintf(WCHAR* szFormat, ...)
{

static WCHAR Buffer[1024];
wvsprintf( Buffer, szFormat, (LPSTR)(&szForm at+1) );
OutputDebugStri ng(Buffer);
}
this fucntion behaves like printf, but outputs to the debug window. But
it will not be like MFC TRACE which expands to nothing in dbeug build.
so I have to put #ifdef_DEBUG everywhere I use it. Using this method, I
would be able to do

dprintf("this is string1, %s and this is string2, %s", pszStr1, pszStr2);

using the Debug::Write and String, I have to form 2 string and
concartenate them in Debug::Write, a real pain. Didn't MS provide
anything simpler adn easier to use?

My apologies for asking if it sounds really dumb.
Jan 6 '06 #4
Your problem stems from the fact that you are mixing managed types (String^)
and unmanaged types (wchar_t etc...) in one compilation unit (that's called
mixed mode). If you want to use the managed System::Diagnos tics::Debug class
methods methods you need to pass them pure managed types, else you have to
marshal the unmanaged data to managed data. The same is true for printf, if
you need to pass a managed String to printf you have to marshal the String
to a native type (char*, wchar_t*), this is the price you pay when using
mixed mode in C++/CLI. If you aren't prepared for this, you'll have to stick
with or pure unmaged code (using MFC, ATL stuff) or use pure managed code.
In the latter case you should start to read (and use) the framework class
docs, these class libraries are key in .NET development, they are actually
more important than ATL or MFC ever was for unmanaged code.

Anyway, a simple function like this:

void DebugOut(whar_t *buff)
{
String ^s = String::Format( "{0}",
Marshal::PtrToS tringUni((IntPt r)buff));
Debug::Write(s) ;
}

is all you need to output debug mesages in mixed mode programs. If this is
not enough, no-one stops you from using ATL in mixed mode C++/CLI programs.

Willy.
"Lonewolf" <an*******@mozi lla.org> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
| Willy Denoyette [MVP] wrote:
| > Again why do you call this unmanaged code?
| > C++/CLI compiles to managed code,
| > String^ s; is a managed string reference.
| > this:
| > s->format("\n Buffer=%s", Buffer);
| > can't even compile, format is not a String method!
| >
| > so what you should do is this (a copy of a reply to your other posting):
| >
| > <
| > I guess you mean from managed code, here is how...
| >
| > wchar_t *unm = L"Test";
| > String ^s = String::Format( "{0}",
Marshal::PtrToS tringUni((IntPt r)unm));
| > Debug::Write(s) ;
|
|
| OK, I understand now. But still, is there no C++/CLI substitute for the
| MFC TRACE or the C "printf" which can be used conveniently? it's such a
| bloody pain to write all the marshal code. right now, I'm using back the
| old dprintf function which I used in the old days of Windows SDK
| programming. it's declared as,
|
| void cdecl dprintf(WCHAR* szFormat, ...)
| {
|
| static WCHAR Buffer[1024];
| wvsprintf( Buffer, szFormat, (LPSTR)(&szForm at+1) );
| OutputDebugStri ng(Buffer);
| }
| this fucntion behaves like printf, but outputs to the debug window. But
| it will not be like MFC TRACE which expands to nothing in dbeug build.
| so I have to put #ifdef_DEBUG everywhere I use it. Using this method, I
| would be able to do
|
| dprintf("this is string1, %s and this is string2, %s", pszStr1, pszStr2);
|
| using the Debug::Write and String, I have to form 2 string and
| concartenate them in Debug::Write, a real pain. Didn't MS provide
| anything simpler adn easier to use?
|
| My apologies for asking if it sounds really dumb.
Jan 6 '06 #5

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

Similar topics

9
2586
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and explain it. I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the "Managed Extensions for C++ Reference"....
8
3501
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
8
1992
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid the usage of old style COM, my alternative is to expose my unmanaged interface through the CLI, to achieve that I have created a mixed mode DLL in which my unmanaged class are defined. When referencing the DLL just described in another mixed mode EXE...
1
1358
by: Kluch | last post by:
Hello, I have a mixed mode DLL that I am trying to debug that's acting really weird, Basiclly I expose a bunch of functions through virtual functions and other code loads it that way. What's really weird is in my CPP file I have breakpoints set where it jumps into one or two functions perfectly just like you would expect it to. But then I have other functions in the exact same cpp file that when it gets to that breakpoint I end up in the...
2
1427
by: Ben Harper | last post by:
I'm trying to load an assembly of mine from a C# webforms page, but IIS fails to load the page because of failed dependencies. My problem is that I cannot for the life of me discover the dependency that is causing the failure. I have verified that the assembly in question is loadable by a small test EXE. Is there any way that I can debug the process at an earlier stage, or retrieve more helpful error information that simple "The assembly...
7
1425
by: Kevin Frey | last post by:
Using .NET 1.1. We have a mixed-mode assembly written in Managed C++ that we are using from an ASP.NET application that has been coded using C#. The mixed-mode assembly has its own "initialisation" routine to cater for any potential "mixed-mode DLL loading problem". Some of our code uses thread-local-storage, and in the DllMain for my mixed-mode assembly I did the appropriate initialisation of the thread-local-storage object on...
8
2309
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
0
1400
by: Russ Barrett | last post by:
Hello, I'm new to ASP.Net and I'm trying to interface an ASP.Net (C#) application to functionality resident in a C++ static lib. From posts I've seen around I understand this requires creation of a 'mixed-mode' assembly. Since a dll of this type provides no normal entry point for C Runtime (CRT) library initialization, I understand that the dll must provide its own exported functions to do this. Thus, from samples I've seen on the web,...
5
7794
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an app.config file referencing arbitrary versions of the plug-in components they wish to consume. Here's the problem: Assuming I have installed any one of our application software,
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.