Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

Viewing strings in the Visual C++ 6.0 Debugger

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
EmbeddedProgrammer
Asked:
EmbeddedProgrammer
1 Solution
 
EmbeddedProgrammerAuthor Commented:
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
 
EmbeddedProgrammerAuthor Commented:
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
 
EmbeddedProgrammerAuthor Commented:
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
Technology Partners: 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!

 
rsanwatsarkarCommented:
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
 
EmbeddedProgrammerAuthor Commented:
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
 
bkrahmerCommented:
The display unicode strings option is contained in the workspace nor project, and it comes off by default for VC6.

brian
0
 
bcladdCommented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now