Suppose you have a class foo like this:

class foo
{
public:
	int X;
	int Y;
	int Z;

	foo(int x = 0, int y = 0, int z = 0): X(x), Y(y), Z(z) {}
};


And you have a variable f(1, 2, 3) what you watch in your Watch window. The window looks like this:

Default expansion for foo

The field Value shows a default expansion of the object, {X=1 Y=2 Z=3}. However, this can be changed by modifying a file called autpexp.dat, located in the Visual Studio installation folder, under Common7\Packages\Debugger. This file allows the control of several things in the debugger, such as the string displayed in the Value column, the functions the debugger skips when stepping, etc. One important limitation however, is that it does not support complex expression, for which it simply displays “???”. This file is loaded each time you start the debugger.

The Autoexp.dat file consists in a set of rules, called AutoExpand rules, specified on a single line and having the format:

type=...



where

type      Name of the type (may be followed by <*> for template
          types such as the ATL types listed below).
text      Any text.Usually the name of the member to display,
          or a shorthand name for the member.
member    Name of a member to display.
format    Watch format specifier. One of the following:

Letter  Description                 Sample         Display
------  --------------------------  ------------   -------------
d,i     Signed decimal integer      0xF000F065,d   -268373915
u       Unsigned decimal integer    0x0065,u       101
o       Unsigned octal integer      0xF065,o       0170145
x,X     Hexadecimal integer         61541,X        0X0000F065
l,h     long or short prefix for    00406042,hx    0x0c22
          d, i, u, o, x, X
f       Signed floating-point       3./2.,f        1.500000
e       Signed scientific-notation  3./2.,e        1.500000e+000
g       Shorter of e and f          3./2.,g        1.5
c       Single character            0x0065,c       'e'
s       Zero-terminated string      pVar,s         "Hello world"
su      Unicode string              pVar,su        "Hello world"


The AutoExpand rules must be located under the [AutoExpand] section, because the file also contains rules for visualizing types when the object is expanded. These visualization rules are located under [Visualizer] and are a feature new in VS2005.

Going back to our foo class, suppose you use this class heavily and you don’t like the default string shown in the Value column, and you would like it to be like this: {X=0×00000001, Y=0×00000002, Z=0×00000008}. That means using comma to separate the fields and display the values as hexadecimal numbers. What you would have to do is adding a AutoExpand rule like this:

foo =X=< X, X >, Y=< Y, X >, Z=< Z, X >


It says something like this: display X followed by = and the value of member X of foo in hexadicimal, followed by comma, space, Y and = followed by the value of member Y of foo in hexadecimal, and so on. Debugging now, will show a different string:

Custom auto expand string for foo

But now let’s imagine that our foo class was actually a template class, like this:

template < typename T >
class foo
{
public:
	T X;
	T Y;
	T Z;

	foo(T x, T y, T z): X(x), Y(y), Z(z) {}
};


The rule above would not help for an object foo f(1, 2, 3) and the default format would be used. That is so because template types have a different form: we need to use <*>.

foo< * > =X=< X, X >, Y=< Y, X >, Z=< Z, X >


With this rule the string is the same as in the above image (the type though changes to foo).

What is this good for? Well, I have shown you a simple example here, but suppose you have complex types, with a lot of members, and the default string shown by the debugger doesn’t help you. To see the info you actually need in the watch window or when you put the mouse over the variable you would have to expand the object and scroll down, perhaps expand aggregated objects, etc. to reach what you actually need on a regular basis. Creating a custom rule for the auto displayed value allows you to show exactly the information you need, in the form you want. For instance you may always want to see the numeric values of X,Y and Z from foo as hexadecimal, but you switched for decimal view in the debugger (from the context menu of the Watch window). That won’t affect the way you view your type, because of the custom rule.

A second part of autoexp.dat file is dedicated to visualization rules. These are mappings from types to display form, shown when you expand the object. Unlike the simple AutoExpand rules, these are more complex and have a dedicated scripting language, which unfortunatelly is not documented.

The basic form of a rule is:

typename[|typename...] {
    preview (
        preview-string-expression
    )
    stringview (
        text-visualizer-expression
    )
    children (
        expanded-contents-expression
    )
}


The three sections have the following purpose:

  • preview: an expression (string literal or expression) to be shown in the Watch, QuickWatch or Command window; if the preview section is present and you also have a AutoExpand rulu for it, the AutoExpand rule is ignored;
  • children: offer the possibility to construct hierarchies;
  • stringview: used to compose the string that is shown in the Text, XML or HTML visualizer; for instance when you have a string, it shows a magnifying glass on the right; clicking it opens a modal dialog that displays the full content of the variable

Considering the template version of foo, the visualizer template bellow sets the text to be shown in the preview. It’s the same result as with the AutoExpand rule.

foo< * > {
	preview
	(
	  #(
		"X=",
		[$c.X, X],
		", Y=",
		[$c.Y, X],
		", Z=",
		[$c.Z, X]
	  )
	)
}


If you are interested to see the sum of the values, in decimal, you could add a children element like this:

children
(
  #(
	sum: [$c.X + $c.Y + $c.Z, d]
  )
)



The Watch window now looks like this:

Visualizer with childrens

But now the X, Y and Z members are gone. You can shown them modifying the children:

children
(
  #(
	X: [$c.X, X],
	Y: [$c.Y, X],
	Z: [$c.Z, X],
	[sum]: [$c.X + $c.Y + $c.Z, d]
  )
)


Visualizer with childrens

To show original members with the auto evaluation, you can use [$c, !]. However, the parser seems to be unstable, and many times it yields errors that may confuse it, or it could work in a way you don’t understand. At least that’s my case.

The visualizers are more complicated. They allow displaying of array, lists, trees, and could contain conditional statements. You actually have to use variable $c to dereference the current variable. A good attempt to document it can be found at http://www.virtualdub.org/blog/pivot/entry.php?id=120. I recommend reading this article for more information avout visualizers.

Hits for this post: 27969 .

A collegue of mine pointed to me today a chapter from a book called “The UNIX-HATERS Handbook”, published by IDG Books Worldwide Inc. in 1994 (ISBN 1-56884-203-1). One of the latest chapters is called “Creators Admit C, Unix Were Hoax”. In this chapter the authors say that Ken Thompson, Dennis Ritchie and Brian Kernighan addmited that the C language and the UNIX operating system was an ellaborate April Fool’s prank that had a success far beyond what they imagined. Alledegly, Thompson declared at a UnixWorld Software Developer Forum that

In 1969, AT&T had just terminated their work with the GE/AT&T Multics project. Brian and I had just started working with an early release of Pascal from Professor Nichlaus Wirth’s ETH labs in Switzerland, and we were impressed with its elegant simplicity and power. Dennis had just finished reading Bored of the Rings, a hilarious National Lampoon parody of the great Tolkien Lord of the Rings trilogy. As a lark, we decided to do parodies of the Multics environment and Pascal. Dennis and I were responsible for the operating environment. We looked at Multics and designed the new system to be as complex and cryptic as possible to maximize casual users’ frustration levels, calling it Unix as a parody of Multics, as well as other more risque allusions.Then Dennis and Brian worked on a truly warped version of Pascal, called “A.” When we found others were actually trying to create real 308 Creators Admit C, Unix Were Hoax programs with A, we quickly added additional cryptic features and evolved into B, BCPL, and finally C. We stopped when we got a clean compile on the following syntax:

for(;P("n"),R=;P("|"))for(e=C;e=P("_"+(*u++/8)%2))P("|"+(*u/4)%2);



To think that modern programmers would try to use a language that allowed such a statement was beyond our comprehension! We actually thought of selling this to the Soviets to set their computer science progress back 20 or more years. Imagine our surprise when AT&T and other U.S. corporations actually began trying to use Unix and C! It has taken them 20 years to develop enough expertise to generate even marginally useful applications using this 1960s technological parody, but we are impressed with the tenacity (if not common sense) of the general Unix and C programmer.In any event, Brian, Dennis, and I have been working exclusively in Lisp on the Apple Macintosh for the past few years and feel really guilty about the chaos, confusion, and truly bad programming that has resulted from our silly prank so long ago.

It’s so hillarious. Unfortunatelly, just another April Fool’s hoax itself. http://www.gnu.org/fun/jokes/unix-hoax.html

Hits for this post: 4431 .

MFC in Orcas comes with several important changes, such as support for Vista specific command button and split button. I have put together a small demo application displaying a command button with the tex Say “Hello Vista” and the note “Click on this button to show a “Hello Vista” message!”.

The command button is still a CButton, but with the style BS_COMMANDLINK (or BS_DEFCOMMANDLINK for a default command button) set. To set the note you should use the SetNote() method. Additional GetNote() and GetNoteLength() methods are available for it. Here is a screenshot:

Demo of command button for Vista

However, there are several problems with the Orcas March CTP that I want to mention (and I hope these will fixed for the next beta version).

When you create a project, add a command button and try to compile, the resource compiler will say that BS_COMMANDLINK is not recognized. The style is defined in commctrl.h like this:

#if _WIN32_WINNT >= 0x0600

// BUTTON STATE FLAGS
#define BST_DROPDOWNPUSHED      0x0400

// BUTTON STYLES
#define BS_SPLITBUTTON          0x0000000CL
#define BS_DEFSPLITBUTTON       0x0000000DL
#define BS_COMMANDLINK          0x0000000EL
#define BS_DEFCOMMANDLINK       0x0000000FL


Trying to define _WIN32_WINNT as 0×0600 either in the project properties or in stdafx.h (if you use precompiled headers) does not help. You have to redeclare the styles whether in resource.h or in the .rc file, but as soon as the IDE modifies them, the code you put there is gone. This is a real bummer, and I’m still looking for the best solution. If I find it, I’ll post it here.

The methods that are available for the command button are defined only for UNICODE builds for Vista, as can be seen in afxwin.h:

#if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
	CString GetNote() const;
	_Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
	BOOL SetNote(_In_z_ LPCTSTR lpszNote);
	UINT GetNoteLength() const;
	BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
	BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
	UINT GetSplitStyle() const;
	BOOL SetSplitStyle(_In_ UINT nStyle);
	BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
	BOOL SetSplitSize(_In_ LPSIZE pSize);
	CImageList* GetSplitImageList() const;
	BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
	TCHAR GetSplitGlyph() const;
	BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
	BOOL SetDropDownState(_In_ BOOL fDropDown);

	// Sets whether the action associated with the button requires elevated permissions.
	// If elevated permissions are required then the button should display an elevated icon.
	HICON SetShield(_In_ BOOL fElevationRequired);
#endif // ( _WIN32_WINNT >= 0x600 ) && defined(UNICODE)


However, if you look in MSDN, method SetShield is not found (though you can find the BCM_SETSHIELD window message). Instead SetElevationRequired() is listed as a member of CButton. This method does not actually exists. Moreover, the people that wrote the documentation don’t seem to know the difference between BOOL and bool (explained here). This method takes a BOOL and returns a BOOL, but MSDN says it returns

true if the method is successful; otherwise false

Using SetShield() with TRUE, displays a shield icon on the button, as shown here:

Demo command button for Vista with shield icon

I hope the issues I mentioned above will be address very soon.

Hits for this post: 8112 .

Google seems to take the April’s Fool Day very seriously. ;) They did two practical jokes, and I’m wondering how many people did fall for it.

First, was the Toilet Internet Service Provider, or TiSP. Yes that was a practical joke, of course. :)

Second, they posted this page about a new service: Gmail on paper. “You Click. We Stack., You Get” it’s just another practical joke, not an actual service.

Seems that the people at google have a great sense of humor. Just look at the info they provide about these “services”:

But what about the environment?
Not a problem. Gmail Paper is made out of 96% post-consumer organic soybean sputum, and thus, actually helps the environment. For every Gmail Paper we produce, the environment gets incrementally healthier.

Google has a long tradition of April Fool’s day. Their hoaxes include:

Details about the hoaxes can be found on wikipedia

If you are interested in more April’s Fools Day jokes, visit this site that lists a top of best 100 jokes ever.

Hits for this post: 1797 .

Channel9 has posted recently an interview with Sarita Bafna, a Program Manager on the VC++ Libraries team, about the new features available in Orcas (in March CTP also) for VC++. The interview is focused on 2 things: marshaling library and MFC updates.

The marshaling library consists on one single API, marshal_as,?for marshaling between managed and unmanaged types. For now, it only supports 22 conversion between various string types (from ATL, Windows and STL), but it can be extended by developers. The API has the form:

to = marshal_as(from);



and to marshal from const char* to System::String^ you only have to do this:

const char* str1 = "sample";
String^ str2 = marshal_as(str1);



If you want the reverse, convert from a String^ to a const char* you need to use a marshal_context object, which keeps track of allocated objects and frees them in the destructor:

marshal_context context;

String^ str1 = gcnew String("sample");
const char* str2 = context.marshal_as(str1);



You can read more about this on Nish’s blog.

On the other hand, several updates were done to MFC. MFC headers were last updated in 1998, and they were now changed to support all the windows messages created since then. MFC now also supports the controls that were introduced in Windows Vista.

  • you can now hide your menu to offer more space for the client area; hiding and showing is simply available by hitting the ALT key
  • new style dialogs for open and saved: any new application created with Orcas has the Vista style for these dialogs. More over, existing applications rebuilt with Orcas will have these new dialogs under Vista. For the applications running on the previous operating systems, the dialogs will default to the previous style.
  • VC++ toolbox has new controls available: sys link, network address control (supports IPv4, IPv6 and DNS), split button and command button; property dialogs have also been updated for these controls
  • high quality graphics (images, icons, etc.) can be opened, but not edited, in the resource editor: if you want them edited, you can use the “Open in external editor” command from the menu. The default external editor is MS Paint. The preview area of the resource editor shows all the images that are part of an .ico file;
  • all the new apps have UAC enabled by default: in the manifest file there is an additional setting for running the application with the priviledges of the launching process; these settings can be changed from the project Properties > Linker > Manifest: Enable User Accound Control (UAC) (default set to Yes), UAC Execute Level and UAC Bypass UI Protection (default set to False)

So, for all those saying MFC is dead, have a look on the Orcas March CTP and see the contrary!

Hits for this post: 4651 .

Google did it again: they just launched a free in-home wireless broadband service, called TiSP, available for now in a BETA version. According to google, TiSP is a

Google TiSP (BETA) is a fully functional, end-to-end system that provides in-home wireless access by connecting your commode-based TiSP wireless router to one of thousands of TiSP Access Nodes via fiber-optic cable strung through your local municipal sewage lines.
A list of frequenctly asked questions is available here, while the intallation steps are described here. Installation is easy and fast, it only takes a few minutes, but you can also opt for a professional installation:

You can also choose to request our professional installation service, which dispatches an army of factory-trained, sub-contracted nanobots from the TiSP Access Node. The nanobots travel with exhilarating nano-speed through the sewer system and into your home to perform the installation service, which should be complete within 15 minutes. Note: For your own physical safety and emotional well-being and in consideration of the nanobots’ working conditions, please make absolutely certain that your toilet is unoccupied at the scheduled appointment time.

Hits for this post: 1904 .