Display strings with embedded nulls in VS2010 debugger visualizer - visual-studio-2010

In Visual Studio 2010, I am trying to have strings (char* and wchar_t*) display with embedded nulls in the various native C++ Debugger Visualizer components, such as the data tip area (Watch window, preview) and expanded area accessed by the magnifying glass (stringview). For example, I want to display a BSTR (embedded in an ATL::CComBSTR) with all of its content, even if null characters are in the string. By default, setting a pointer to ,s8, ,s, or ,su will treat the string as null-terminated, which is not the desired behavior. This question specifically applies to VS2010, not 2012, 2008, or prior versions.
Any clever ideas?

Any clever ideas?
Assuming you know when the data changes, and you have your own structure wrapping the BSTR, you could add a second debug only vector of strings (or a single string with some separator replacing the nulls) to your structure that you keep in sync with the string containing embedded nulls, then visualize the vector instead. It's not pretty, but it allows you to debug your code.

Related

How to count selected (or found) characters and lines in Visual Studio (Not VS Code)

I am developing a combined Embedded + Desktop application. Memory constraints on the embedded platform make it important to know the size and count of items that will be sent and received. When I make size or element count changes on one system I need to coordinate those changes with the other system.
To get this information, I currently select and copy the elements of interest within visual studio and paste them into an external text editor that can give me the character count and the line count.
I would like to find a way to see that same information (count of selected lines and count of selected characters) within Visual Studio (2017).
The only way I've found so far is to perform find and replace within a selection, which does report the count of replacements. If I use regular expressions for the match I can get a count of whatever matched, so with two passes I can get the count of characters and lines replaced -- but then I have to Ctrl-Z to undo the damage, and this just seems like a bad idea. There must be a better way.
Is there any way to get the count of found or selected elements other than using Find & Replace and then un-doing the damage?
Virtually every other editor I've seen permits doing a "find" within a selection and tells you the count of matches, but I've not found any way to make Visual Studio show the count of matches, even though all the found elements are color-marked. I have to do "replace all" to get the count.
I see that there have been periodic feature requests for this same functionality going back quite a few years, but up to now they have been closed for lack of votes. I found macros for VS2010 that can do this, but I don't find any evidence that macros exist in VS2017. I have not found any marketplace extension that gives the count of selected lines and selected characters.
Note that I'm not looking to count lines of code in a file, or a project, or a solution. I'm only seeking to count the characters and lines "on the fly" in a selection within the Visual Studio IDE. I searched, but did not find any questions that appear to be duplicates of this question.
Edit:
Sadly, nearly 4 years later it seems there still is no native way to do this in any version of Visual Studio up to and including VS 2022. VS Code does show the count of selected characters, but that doesn't help since I need the full IDE of Visual Studio. Sigh.
VSCode displays the number of characters currently selected in the status bar, e.g. (143 selected)
You can use the following command (C# language) with my Visual Commander extension to count selected characters and lines:
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
System.Windows.MessageBox.Show("Lines=" + (1 + ts.BottomLine - ts.TopLine) + " Characters=" + ts.Text.Length);
}
}
(BTW, Visual Commander can also run a VS 2010 macro.)

Visual Studio Hexadecimal Display Uppercase

I work directly with binaries files, doing a lot of reverse engineering and inserting security patches to bypass some things.
Anyways this means I'm constantly starring at hexadecimal, and I have my hexadecimal display enabled in Visual Studio, but the one thing that my mind has a hard time with is all other hex editors put their alpha-numeric numbers (0xA-0xF) in uppercase, Visual Studio is lower case. I've spent some time looking over all the options and references but couldn't find anything. Anyone know of an option to change this to uppercase?
I'm talking the debugging hexadecimal display for example I want this to be in uppercase:

MSVC Autoexp.dat tokens explanation

In Visual Studio 2010, there is a little bit of explanation at the beginning of autoexp.dat on how to define rules. However, this explanation is quite limited and I haven't come across any other document. Appreciate your help in understanding a few tokens.
Here is a rule I copied from somewhere. It works for my needs.
MyString{
preview ([$e.data,su])
stringview ([$e.data,sub])
}
Q1. What is the difference between preview and stringview? Do I really need stringview.
Q2. Why does stringview use "sub" and not "su?"
Q3. What does a hash (#) do on an expression? What is the difference between the following two lines?
preview ([$e.data,su])
preview #([$e.data,su])
preview is that you see in Debuger's watch window, if you define stringview it will add a small icon (looking glass) witch calls a Text Visuzlisers. (read StringView)
Format Specifiers in C++
I think this is some syntax requirements like tokens #tree #list etc

How to make Intellisense in Visual Studio 2012 not to substitute text right to the cursor?

While programming I often realize that I need to add something before already typed code. For example I type the name of the variable:
input[0]
and then I realize that my array is of type string and I need to convert it. So, I move to the beginning of the word (with Ctrl-Left Arrow) and start typing
Convert.To|input[0]
with pipe used to show the position of my cursor. I get some suggestions from Intellisense, including the ToInt32() method I am looking for. But as long as I confirm this suggestion with Tab or Space, I get the following:
Convert.ToInt32(|)[0]
So, the text from the cursor position to the end of the word is substituted with suggestion, and this is definitely not what I want.
This problem is not specific for VS 2012 and might be due to some extensions I have installed, but my attempt to pursue its origin did not yield anything. I have following extensions installed: ReSharper, PowerCommands, Productivity Power Tools.
If you are entering an unrelated expression before an identifier, add a space before you start typing the new expression. This will prevent the completion from replacing the existing identifier.
For example, if | marks the caret, the following scenario would avoid the problem you are facing.
Convert.To| input
This code completion feature is designed to prevent the insertion of incorrect identifiers. If Visual Studio behaved like some other IDEs I know of, using the code completion feature in your original example would result in the insertion of ToInt32input, which would never be valid.
If you are interested in additional thoughts regarding this feature in general, I have described this as the Extend (default for Visual Studio) and No-extend (default for NetBeans, Eclipse, and others) modes in my blog article Code Completion filtering, selection, and replacement algorithms.
A two years later answer. But it might still be useful for some.
What helped for me in VS2015 (which might also work in VS2012) is to add the a space character to the list of 'Member List Commit Characters' in the Intellisense settings.
After this the characters after the cursor are not removed by an auto-completion.

Printing the expression result in hexadecimal format using visual studio's trace points

Does anybody know, whether it's possible to output the values in a hexadecimal via the visual studio's trace points?
Thanks!
I have recently found out, how this can be done. Visual studio provides a way to specify the format we want to see the expression in the watch/immediate windows. You can do the following:
foo, x
This will display the foo variable in the hexadecimal format regardless of whether the hex or dec displayed is globally enabled in VS. You can also specify lots of other display formats. The full list can be found there http://msdn.microsoft.com/en-us/library/75w45ekt.aspx.
This feature also works with trace points, which is very useful when you want the values to appear in hexadecimal format in output window.
{bar,x}

Resources