<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx</link><description>Often programming is just assembling the building blocks you already have.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188717</link><pubDate>Tue, 20 Jul 2004 14:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188717</guid><dc:creator>Dr. Jekyll</dc:creator><description>If everything is so nicely scoped, why not use CComPtr&amp;lt;&amp;gt;s / CComQIPtr&amp;lt;&amp;gt;s ? This very same code would be so much more readable (no ugly QueryInterfaces, Releases, uninitialized variables)...&lt;br&gt;&lt;br&gt;Guess it's a habit thing.&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188723</link><pubDate>Tue, 20 Jul 2004 14:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188723</guid><dc:creator>Raymond Chen</dc:creator><description>I try to avoid using any extra libraries in these articles. If you like those libraries, you can translate raw C++ into your library; but it's harder for others to translate a library into raw C++. (For example, I could've used a library to auto-free the pidlFolder, but that would have confused anybody who wasn't familiar with that library.)</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188727</link><pubDate>Tue, 20 Jul 2004 14:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188727</guid><dc:creator>A. Reader</dc:creator><description>Hideous.  That screams &amp;quot;potential memory leaks!&amp;quot;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188754</link><pubDate>Tue, 20 Jul 2004 15:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188754</guid><dc:creator>Ben Cooke</dc:creator><description>That code is hilarious. It's stuff like that which really puts me off learning about COM. Fortunately, I've managed to basically ignore COM so far, and if all this .NET stuff becomes popular maybe I can just pretend it never happened. :)&lt;br&gt;&lt;br&gt;Pleaaase release me, let me gooooooo......</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188761</link><pubDate>Tue, 20 Jul 2004 15:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188761</guid><dc:creator>Jack Mathews</dc:creator><description>Well, you could easily flatten out that code with a CComPtr class, a CComMemoryHandle class, and a function called GuaranteeSuccess that throws an exception on a bad HRESULT and catch that in the function.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188772</link><pubDate>Tue, 20 Jul 2004 15:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188772</guid><dc:creator>Raymond Chen</dc:creator><description>Any reader who wants to make an ATL version of this function is free to do so. It would probably be a lot prettier. But I write in pure C++ in order to avoid arguing over which template library is best.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188776</link><pubDate>Tue, 20 Jul 2004 15:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188776</guid><dc:creator>dude</dc:creator><description>cant compile : error C2065: 'StrRetToBuf' : undeclared identifier</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188816</link><pubDate>Tue, 20 Jul 2004 16:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188816</guid><dc:creator>Ben Hutchings</dc:creator><description>Does Explorer lock windows that external clients are looking at (or indeed &amp;lt;em&amp;gt;all&amp;lt;/em&amp;gt; of them while the windows are being enumerated) or is this code vulnerable to race conditions?</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188830</link><pubDate>Tue, 20 Jul 2004 16:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188830</guid><dc:creator>Michael</dc:creator><description>&amp;gt;I try to avoid using any extra libraries in these articles. &amp;lt;&lt;br&gt;&lt;br&gt;I for one am glad you approach your problems this way.  It shows me what is &amp;quot;really going on&amp;quot;.   Keep up the good work!!</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188861</link><pubDate>Tue, 20 Jul 2004 17:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188861</guid><dc:creator>Cedric Beust</dc:creator><description>I believe the only point you've made is that only   VB or C# should ever be used to access COM :-)&lt;br&gt;&lt;br&gt;-- &lt;br&gt;Cedric&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188878</link><pubDate>Tue, 20 Jul 2004 17:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188878</guid><dc:creator>drebin</dc:creator><description>I have a burning sensation in my eyes, is that normal?? </description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#188943</link><pubDate>Tue, 20 Jul 2004 18:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:188943</guid><dc:creator>Zachary Turner</dc:creator><description>Even in pure C++, better to just stick a label at the bottom and have a goto statement if the COM call fails, rather than use deeper nesting if the call succeeds.&lt;br&gt;&lt;br&gt;To the poster who said it's things like that make you not want to learn COM, it's very simple and easy to read as long as you provide an appropriate framework for making it easy to read.  For example, consider the following two macros:&lt;br&gt;&lt;br&gt;#define COM_CALL(pfn, lbl) \&lt;br&gt;   if (FAILED(pfn)) goto lbl;&lt;br&gt;&lt;br&gt;#define RELEASE(ptr) \&lt;br&gt;   if (ptr) ptr-&amp;gt;Release();&lt;br&gt;&lt;br&gt;Now the RecalcText function is as follows:&lt;br&gt;&lt;br&gt;void CALLBACK RecalcText(HWND hwnd, UINT, UINT_PTR, DWORD)&lt;br&gt;{&lt;br&gt;	HWND hwndFind = GetForegroundWindow();&lt;br&gt;	g_szPath[0] = TEXT('\0');&lt;br&gt;	g_szItem[0] = TEXT('\0');&lt;br&gt;&lt;br&gt;	IShellWindows *psw;&lt;br&gt;	COM_CALL(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&amp;amp;psw), finish);&lt;br&gt;	&lt;br&gt;	VARIANT v;&lt;br&gt;	V_VT(&amp;amp;v) = VT_I4;&lt;br&gt;	IDispatch  *pdisp;&lt;br&gt;	BOOL fFound = FALSE;	&lt;br&gt;	for (V_I4(&amp;amp;v) = 0; !fFound &amp;amp;&amp;amp; psw-&amp;gt;Item(v, &amp;amp;pdisp) == S_OK; V_I4(&amp;amp;v)++)&lt;br&gt;	{&lt;br&gt;&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	IWebBrowserApp *pwba = NULL;&lt;br&gt;	IServiceProvider *psp = NULL;&lt;br&gt;	IShellBrowser *psb = NULL;&lt;br&gt;	IShellView *psv = NULL;&lt;br&gt;	IFolderView *pfv = NULL;&lt;br&gt;	IPersistFolder2 *ppf2 = NULL;&lt;br&gt;	LPITEMIDLIST pidlFolder = NULL;&lt;br&gt;	LPITEMIDLIST pidlItem = NULL;&lt;br&gt;	IShellFolder *psf = NULL;&lt;br&gt;	STRRET str;&lt;br&gt;	COM_CALL(pdisp-&amp;gt;QueryInterface(IID_IWebBrowserApp, (void**)&amp;amp;pwba), finish);&lt;br&gt;	if (hwndWBA != hwndFind)&lt;br&gt;		goto finish;&lt;br&gt;	COM_CALL(pwba-&amp;gt;QueryInterface(IID_IServiceProvider, (void**)&amp;amp;psp), finish);&lt;br&gt;	COM_CALL(psp-&amp;gt;QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&amp;amp;psb), finish);&lt;br&gt;	COM_CALL(psb-&amp;gt;QueryActiveShellView(&amp;amp;psv), finish);&lt;br&gt;	COM_CALL(psv-&amp;gt;QueryInterface(IID_IFolderView, (void**)&amp;amp;pfv), finish);&lt;br&gt;	COM_CALL(pfv-&amp;gt;GetFolder(IID_IPersistFolder2, (void**)&amp;amp;ppf2), finish);&lt;br&gt;	COM_CALL(ppf2-&amp;gt;GetCurFolder(&amp;amp;pidlFolder), finish);&lt;br&gt;&lt;br&gt;	if (!SHGetPathFromIDList(pidlFolder, g_szPath)) &lt;br&gt;		lstrcpyn(g_szPath, TEXT(&amp;quot;&amp;lt;not a directory&amp;gt;&amp;quot;), MAX_PATH);&lt;br&gt;&lt;br&gt;	int iFocus;&lt;br&gt;	COM_CALL(pfv-&amp;gt;GetFocusedItem(&amp;amp;iFocus), finish);&lt;br&gt;	COM_CALL(pfv-&amp;gt;Item(iFocus, &amp;amp;pidlItem), finish);&lt;br&gt;	COM_CALL(ppf2-&amp;gt;QueryInterface(IID_IShellFolder, (void**)&amp;amp;psf), finish);&lt;br&gt;	COM_CALL(psf-&amp;gt;GetDisplayNameOf(pidlItem, SHGDN_INFOLDER, &amp;amp;str), finish);&lt;br&gt;	StrRetToBuf(&amp;amp;str, pidlItem, g_szItem, MAX_PATH);&lt;br&gt;&lt;br&gt;&lt;br&gt;finish:&lt;br&gt;	RELEASE(psf);&lt;br&gt;	TASK_FREE(pidlItem);&lt;br&gt;	TASK_FREE(pidlFolder);&lt;br&gt;	RELEASE(ppf2);&lt;br&gt;	RELEASE(pfv);&lt;br&gt;	RELEASE(psv);&lt;br&gt;	RELEASE(psb);&lt;br&gt;	RELEASE(psp);&lt;br&gt;	RELEASE(pwba);&lt;br&gt;	RELEASE(pdisp);&lt;br&gt;	RELEASE(psw);&lt;br&gt;&lt;br&gt;	InvalidateRect(hwnd, NULL, TRUE);&lt;br&gt;}&lt;br&gt;&lt;br&gt;I probably introduced a few bugs here, but I just typed this in notepad and didn't bother compiling.  The point is obvious, just change the logic flow and COM is much easier to follow.  Don't listen to what they say, that you should &amp;quot;never&amp;quot; use goto statements.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189165</link><pubDate>Tue, 20 Jul 2004 19:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189165</guid><dc:creator>Larry Osterman</dc:creator><description>Never use goto statements?  I LOVE goto statements :)&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189177</link><pubDate>Tue, 20 Jul 2004 20:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189177</guid><dc:creator>Jack Mathews</dc:creator><description>Zach: Ummm, except now you can't use C++ construction/destruction semantics with yoru code...</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189184</link><pubDate>Tue, 20 Jul 2004 20:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189184</guid><dc:creator>Nicole DesRosiers</dc:creator><description>Having had to actually code up a program using a raw dispatch interface in C++, I really appreciate that you wrote this example without libraries.  When I was trying to design my program I nearly tore my hair out trying to translate the things written on MSDN with the wrapper code into raw function calls that were actually useful to me.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189244</link><pubDate>Tue, 20 Jul 2004 21:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189244</guid><dc:creator>MadHungarian :)</dc:creator><description>The thing that bugs me is the use of Hungarian notation. 'psf' doesn't say much, 'shellFolder' does.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189252</link><pubDate>Tue, 20 Jul 2004 21:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189252</guid><dc:creator>Raymond Chen</dc:creator><description>Zachary: Note however that some of your code goto's over variable initialization - for example if the initial CoCreateInstance fails. This results in the RELEASE trying to use an uninitialized variable.&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189295</link><pubDate>Tue, 20 Jul 2004 22:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189295</guid><dc:creator>Joe</dc:creator><description>Zachary, you have to make sure that when you make macros you take care to write them correctly.  For instance, this hypothetical code is wrong:&lt;br&gt;if(--i == 0) // we have no more use for the object&lt;br&gt;  RELEASE(pObj);&lt;br&gt;else&lt;br&gt;  COM_CALL(pObj-&amp;gt;foo(), finish);&lt;br&gt;&lt;br&gt;First, because the RELEASE() macro has a semi-colon, you end up with two semi-colons and that'll terminate the if statement before the else.  If you remove the extra semi-colon, then the else clause gets attached to the if statement in the macro, and not the if(--i == 0).  &lt;br&gt;&lt;br&gt;I think the usual way of handling this is to use:&lt;br&gt;#define RELEASE(ptr) \ &lt;br&gt;if (ptr) ptr-&amp;gt;Release(); else&lt;br&gt;&lt;br&gt;So that the semi-colon at the end of RELEASE(foo); will close the else.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189321</link><pubDate>Tue, 20 Jul 2004 23:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189321</guid><dc:creator>Jack Mathews</dc:creator><description>Or instead of a macro, you use something like a CComPtr, and to fix the nesting, you do like this:&lt;br&gt;&lt;br&gt;enum EBadResult&lt;br&gt;{&lt;br&gt;  kBadResult&lt;br&gt;};&lt;br&gt;&lt;br&gt;void Succeed( HRESULT hr )&lt;br&gt;{&lt;br&gt;  if ( !SUCCEEDED(hr) )&lt;br&gt;  {&lt;br&gt;    throw kBadResult;&lt;br&gt;  }&lt;br&gt;}&lt;br&gt;&lt;br&gt;...  then in your code, you can simply do ...&lt;br&gt;&lt;br&gt;try&lt;br&gt;{&lt;br&gt;  Object obj;&lt;br&gt;&lt;br&gt;  Succeed( incoming-&amp;gt;DoThis( obj.GetPtrPtr() ) );&lt;br&gt;  Succeed( obj-&amp;gt;DoThisNow() );&lt;br&gt;} &lt;br&gt;catch ( EBadResult )&lt;br&gt;{ &lt;br&gt;  // Do what you need to in order to fail&lt;br&gt;}&lt;br&gt;&lt;br&gt;...  and you will get automatic destruction of the intermediate objects that you didn't use.  You write a small amount more code, you get similar ease of use as goto, and much MUCH more robust error handling in the language.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189374</link><pubDate>Wed, 21 Jul 2004 01:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189374</guid><dc:creator>John Schroedl</dc:creator><description>Great post.  Keep 'em coming with more good stuff for the shell!</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189444</link><pubDate>Wed, 21 Jul 2004 03:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189444</guid><dc:creator>Steven Engelhardt</dc:creator><description>For writing anything but the simplest macros, I typically recommend enclosing in a do { ... } while(0) block as follows:&lt;br&gt;&lt;br&gt;#define DoStuff() \&lt;br&gt;    do { \&lt;br&gt;        // statement 1; \&lt;br&gt;        // statement 2; \&lt;br&gt;        // ...; \&lt;br&gt;    } while (0)&lt;br&gt;&lt;br&gt;The if (...) else trick should work as well.&lt;br&gt;&lt;br&gt;I also explained my C/C++ error-handling style which uses gotos, along with its limitations, in:&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://www.livejournal.com/users/sengelha/35640.html"&gt;http://www.livejournal.com/users/sengelha/35640.html&lt;/a&gt;&lt;br&gt;&lt;a target="_new" href="http://www.livejournal.com/users/sengelha/37087.html"&gt;http://www.livejournal.com/users/sengelha/37087.html&lt;/a&gt;&lt;br&gt;&lt;a target="_new" href="http://www.livejournal.com/users/sengelha/37182.html"&gt;http://www.livejournal.com/users/sengelha/37182.html&lt;/a&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189646</link><pubDate>Wed, 21 Jul 2004 09:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189646</guid><dc:creator>Tim Robinson</dc:creator><description>&amp;gt; I try to avoid using any extra libraries in these articles.&lt;br&gt;&lt;br&gt;Even the Microsoft C++ runtime library includes COM support classes. For most Windows developers, that's hardly an 'extra library'.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189841</link><pubDate>Wed, 21 Jul 2004 13:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189841</guid><dc:creator>Stewart Tootill</dc:creator><description>I tend to use the exception concept and ATL com smart pointers. I know the example wasn't written in ATL, but even if thats the only ATL functionality you use its worth it in my opinion.&lt;br&gt;&lt;br&gt;As for the macro, I typically use&lt;br&gt;&lt;br&gt;inline HRESULT TestComCall( HRESULT hr ) throw (_com_error)&lt;br&gt;{&lt;br&gt;    if ( FAILED( hr ) )&lt;br&gt;        _com_issue_error( hr );&lt;br&gt;    return hr;&lt;br&gt;}&lt;br&gt;&lt;br&gt;it returns hr so you can use it with the Next method on IEnum interfaces. You can replace the _com_error with your favourite exception. Also its a shame, but the microsoft compiler whinges about the exception specification.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189877</link><pubDate>Wed, 21 Jul 2004 14:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189877</guid><dc:creator>Tudor Tihan</dc:creator><description>Hy,&lt;br&gt;&lt;br&gt;Is there any way to similarly get a handle of the text inputs in the Internet Explorer ?&lt;br&gt;&lt;br&gt;If it could be a write-only way (for setting texts inside) that would be great, because it would mean that I could write a program to fill my credentials on my visited sites without sharing them with password manager and such.&lt;br&gt;&lt;br&gt;So, is it possible?&lt;br&gt;Could you give me some guidelines, please, as I am new to advanced COM programming.&lt;br&gt;&lt;br&gt;Thank you!</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189889</link><pubDate>Wed, 21 Jul 2004 14:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189889</guid><dc:creator>Raymond Chen</dc:creator><description>mshtml.h contains the interfaces you need. I leave filling in the details as an exercise. (Besides, this is an IE question and that's not my area.)</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#189980</link><pubDate>Wed, 21 Jul 2004 16:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:189980</guid><dc:creator>Michael Geary</dc:creator><description>Steve, I'm curious about the use of do...while(0) in your macro. I've written scads of multiline code macros, and all I ever do is enclose them in braces. So your example would be:&lt;br&gt;&lt;br&gt;#define DoStuff() \&lt;br&gt;{ \&lt;br&gt;// statement 1; \&lt;br&gt;// statement 2; \&lt;br&gt;// ...; \&lt;br&gt;}&lt;br&gt;&lt;br&gt;Is there a situation where that would fail and do...while(0) would fix it?&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190079</link><pubDate>Wed, 21 Jul 2004 18:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190079</guid><dc:creator>Steven Engelhardt</dc:creator><description>Michael Geary: The #define DoStuff() { ... } style works in most cases but not all.  See &lt;a target="_new" href="http://www.livejournal.com/users/sengelha/38124.html"&gt;http://www.livejournal.com/users/sengelha/38124.html&lt;/a&gt; for details.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190083</link><pubDate>Wed, 21 Jul 2004 18:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190083</guid><dc:creator>Zachary Turner</dc:creator><description>Well as I said, I typed it in notepad and didn't compile anything ;-)  The point was just to illustrate a general concept, which when applied would simplify readability.  Thanks for pointing out the errors though.   To respond to the individual comments (I'm sure everyone knows everything I'm about to say, but I might as well say it anyway for the sake of completeness):&lt;br&gt;&lt;br&gt;Raymond: Skipping over variable initialization is easily handled by moving all declarations and setting them equal to 0.  The release macro checks whether or not the value of the pointer is 0, and if it is it does nothing.  So you never release garbage that way.  Obviously you know that already, but like I said just pointing it out for completeness' sake.&lt;br&gt;&lt;br&gt;Jack: Are you referring to construction/destruction semantics with regards to COM smart pointers auto add-refing and releasing?  You can use whatever you want, this was just an attempt to simplify readability in a way that didn't use any smart pointer template library, which was Raymond's initial goal as well.  Since some readers said &amp;quot;it sucks, you can't read it without smart pointers&amp;quot;, I was just providing a way by which you could ;-)&lt;br&gt;&lt;br&gt;Joe: Good point, thanks :)&lt;br&gt;&lt;br&gt;Jack (2nd message): Raymond's original goal was specifically NOT to use any library such as that, so that people didn't have to argue over which template library was best.&lt;br&gt;&lt;br&gt;Michael:  Yes, the do while macro allows you to put a semicolon at the end Consider your macro to be called DOMICHAEL, and steve's to be called DOSTEVE.  Now consider the following code:&lt;br&gt;&lt;br&gt;if (1)&lt;br&gt;     DOMIKE();&lt;br&gt;else&lt;br&gt;     DOSTEVE();&lt;br&gt;&lt;br&gt;if (1)&lt;br&gt;     DOSTEVE();&lt;br&gt;else&lt;br&gt;     DOMIKE();&lt;br&gt;&lt;br&gt;The first if/else block generates a compiler error, because a ; after DOMIKE() terminates the if block, as Joe pointed out earlier.  The second if block does NOT generate a compiler error, however, as you are required to put a ; to terminate the do while.  &lt;br&gt;&lt;br&gt;That's the only difference that I see.  This only applies for single line if blocks as well, if you already had enclosing braces for the if block there would be no difference.</description></item><item><title>The old goto problem</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190091</link><pubDate>Wed, 21 Jul 2004 21:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190091</guid><dc:creator>Otaku, Cedric's weblog</dc:creator><description>I was once reminded of the constant controversy that surrounds the use of goto by the two following posts: Raymond Chen's article on a COM trick to track the Explorer...</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190435</link><pubDate>Wed, 21 Jul 2004 20:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190435</guid><dc:creator>Michael Moore</dc:creator><description>Seems to me you might as well stick with the simple braces method since a do { ... } while (0) approach also results in a syntax error if you leave off the semicolon.&lt;br&gt;&lt;br&gt;i.e. this won't compile either:&lt;br&gt;&lt;br&gt;if ( expression )&lt;br&gt;  do { a(); b(); } while (0)&lt;br&gt;else&lt;br&gt;  c();&lt;br&gt;&lt;br&gt;so its really just a question of whether you think semicolon's should be used to terminate macro usage.&lt;br&gt;&lt;br&gt;I'll grant you the lack of a semicolon is a bit more obvious a syntax error for the macro than a mismatched else.&lt;br&gt;&lt;br&gt;-Michael&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190736</link><pubDate>Thu, 22 Jul 2004 00:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190736</guid><dc:creator>Michael Geary</dc:creator><description>Stephen and Zachary, many thanks for the explanation on the do...while(0) bit. All makes sense now, and I'll start doing my own macros that way.&lt;br&gt;&lt;br&gt;Michael M., when I write a code macro like this, I like to do it in such a way that I can use the semicolon when I use the macro. The idea is that the code that calls the macro should look the same whether it's a macro or a function.&lt;br&gt;&lt;br&gt;Taking a simpler example, I would write a macro like this:&lt;br&gt;&lt;br&gt;#define DoStuff() CallSomething()&lt;br&gt;&lt;br&gt;and not like this:&lt;br&gt;&lt;br&gt;#define DoStuff() CallSomething();&lt;br&gt;&lt;br&gt;because when I call DoStuff, I want to call it like this:&lt;br&gt;&lt;br&gt;DoStuff();&lt;br&gt;&lt;br&gt;and not like this:&lt;br&gt;&lt;br&gt;DoStuff()&lt;br&gt;&lt;br&gt;The latter style means that the caller has to know it's a macro, which I wouldn't want.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190759</link><pubDate>Thu, 22 Jul 2004 00:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190759</guid><dc:creator>Raymond Chen</dc:creator><description>The semicolon-less style also messes up most code auto-formatters / syntax colorers.</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#190900</link><pubDate>Thu, 22 Jul 2004 05:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:190900</guid><dc:creator>sir</dc:creator><description>buncha jealous heytah's ;-)</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#191282</link><pubDate>Thu, 22 Jul 2004 16:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:191282</guid><dc:creator>Kyle Lahnakoski</dc:creator><description>Looks like this turned into a discussion about code readability and the use of gotos.&lt;br&gt;&lt;br&gt;Gotos are not good, but suggest the need for better error handling than the inadequate try-catch semantics.  I suggest Structured Cascaded Exception Handling solves this problem and should be adopted in the next generation of languages.&lt;br&gt;</description></item><item><title>re: Querying information from an Explorer window</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#191993</link><pubDate>Fri, 23 Jul 2004 04:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:191993</guid><dc:creator>Steve Donie</dc:creator><description>You forgot to mention the Accessibilty Interfaces! Go straight to the focused item, get notified when it changes rather than polling...&lt;br&gt;&lt;br&gt;Run the magnifier (Start-&amp;gt;Programs-&amp;gt;Accessories-&amp;gt;Accessibility-&amp;gt;Magnifier) or Narrator (same place) to see what those can do. Then see &lt;a target="_new" href="http://microsoft.com/enable/"&gt;http://microsoft.com/enable/&lt;/a&gt; for a ling to the developer docs. </description></item><item><title>Kind of cool</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#349511</link><pubDate>Sun, 09 Jan 2005 22:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:349511</guid><dc:creator>crashBlog</dc:creator><description /></item><item><title>Using script to query information from Internet Explorer windows</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx#435658</link><pubDate>Tue, 05 Jul 2005 17:00:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:435658</guid><dc:creator>The Old New Thing</dc:creator><description>The ShellWindows object was designed for scripting.</description></item></channel></rss>