?
Solved

Viewing strings in the Visual C++ 6.0 Debugger

Posted on 2003-03-06
8
Medium Priority
?
512 Views
Last Modified: 2012-08-13
Experts,

Here's the relevant information...

    LPOLESTR pwszTarget = NULL;

// @@@ ======= TEST =======
    CoTaskMemFree(pwszTarget);
    pwszTarget = (LPOLESTR) CoTaskMemAlloc(
                 (ustrlen(" Filename.EXT") + 1)
                 * sizeof(OLECHAR));
    if (!pwszTarget)
        hr = E_OUTOFMEMORY, throw HRException();
    ustrcpy(pwszTarget, OLESTR(" Filename.EXT"));
// @@@ ======= END  =======


Now my problem is this:

I have absolutely no idea what I'm doing in Visual C++, yet the project that I am currently working on requires that I make things work.  In the snippet above, I am attempting to allocate space for 'pwszTarget', then load a constant string into it.

I have made the following assumptions:

- Memory must be allocated before the copy of the string to 'pwszTarget'
- OLESTR() is used because that's the way everything else that I've seen is done
- It isn't working

I mention that last assumption because I'm not even sure if it *isn't* working.  This brings up the second part of my question, how do I view a string in the debugger for Visual C++ 6.0?  

This is what I'm seeing in the watch window with a few variations on how the variable is displayed...

     &pwszTarget                0x0012eaa8 "Я"
     pwszTarget             0x0017afd0
     (char *)(pwszTarget)   0x0017afd0 " "
     *pwszTarget                32

Much thanks,
EmbeddedProgrammer
0
Comment
Question by:EmbeddedProgrammer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Author Comment

by:EmbeddedProgrammer
ID: 8085038
Oh, and in case anyone points it out, I *do* realize that " " is 32 in ASCII... :).  I believe that this is the start of the string that I mention, but why isn't the rest of it shown?

EmbeddedProgrammer
0
 

Author Comment

by:EmbeddedProgrammer
ID: 8085066
I realize that I'm talking to myself here, but it's been a long day. :P

Does this have something to do with the fact that a UNICODE string is interleaved with '0's, and the debugger thinks this is the end of the string when displaying it?  If so, is there another way to see the WHOLE string at runtime in the debugger?

EmbeddedProgrammer
0
 

Author Comment

by:EmbeddedProgrammer
ID: 8085068
I realize that I'm talking to myself here, but it's been a long day. :P

Does this have something to do with the fact that a UNICODE string is interleaved with '0's, and the debugger thinks this is the end of the string when displaying it?  If so, is there another way to see the WHOLE string at runtime in the debugger?

EmbeddedProgrammer
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:rsanwatsarkar
ID: 8086334
Hi,
First of all I will suggest you to use TCHAR. TCHAR can act as a multibyte string or a wide string depending on compilation options set to _MBCS or _UNICODE
So the code can be as simple as:

TCHAR szTarget[MAX_BUFFER_LEN];
_tcscpy(szTarget, _T("Filename.EXT"));

Next, to watch the string value in debugger, go to
View-->OutputWindows --> Memory

Once the memory window is open, copy the address of the target string from watch window and paste in memory edit box. Press return and you   should be able to see the string value in BSTRs, OLESTRs
In your case above, the addr of pwszTarget, that is 0x0012eaa8, should be pasted in the memory window
&pwszTarget                0x0012eaa8 "P/"

Good luck,
rsan
 
0
 

Accepted Solution

by:
EmbeddedProgrammer earned 0 total points
ID: 8089216
Thanks for your comment, Rsan.

Unfortunately, I don't have the option to change the variable types that are used.  I'm working from a template and many of the variables are already in place.  I will, however, keep this in mind if I ever have to work with this horrible language on another project. ;)

Another person that I was talking to mentioned the method of viewing memory.  Though this approach would work, it seems very cumbersome when there are many strings to be viewed while debugging.

I was able to solve the problem by turning on an option called "Display unicode strings", under "Tools" | "Options", then on the "Debug" tab.  This checkbox was disabled for some reason.  Whether that is the default in the installation, or the original project template that I received contained the setting, I don't know.  Why it was disabled in the first place, I don't know.  All I know is that now I can view unicode strings within the debugger (and with that neat little 'MouseOver' feature).  This allows me to debug as debugging should be done instead of doing so blindly.

EmbeddedProgrammer
0
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8095677
The display unicode strings option is contained in the workspace nor project, and it comes off by default for VC6.

brian
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9889686
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered by original poster: Archive and refund points

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question