{"id":87,"date":"2006-11-16T07:00:15","date_gmt":"2006-11-16T12:00:15","guid":{"rendered":"http:\/\/www.nynaeve.net\/?p=87"},"modified":"2019-12-13T17:39:47","modified_gmt":"2019-12-13T22:39:47","slug":"the-troolean-strikes-back","status":"publish","type":"post","link":"http:\/\/www.nynaeve.net\/?p=87","title":{"rendered":"The troolean strikes back"},"content":{"rendered":"<p>There is a particularly amusing curiousity in Microsoft Win32 code that I have seen crop up a couple of times over the year: The &#8220;troolean&#8221;, or the &#8220;boolean&#8221; value with true\/false\/other as possible values.<\/p>\n<p>You have probably seen this before in the winuser messaging APIs, such as the classic example of GetMessage:<\/p>\n<pre>WINUSERAPI\r\nBOOL\r\nWINAPI\r\nGetMessageW(\r\n    __out LPMSG lpMsg,\r\n    __in_opt HWND hWnd,\r\n    __in UINT wMsgFilterMin,\r\n    __in UINT wMsgFilterMax);<\/pre>\n<p>According to the <a title=\"GetMessage [MSDN]\" href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/winui\/winui\/windowsuserinterface\/windowing\/messagesandmessagequeues\/messagesandmessagequeuesreference\/messagesandmessagequeuesfunctions\/getmessage.asp\">GetMessage documentation<\/a> on MSDN, the return value has the following meanings:<\/p>\n<blockquote><p>If the function retrieves a message other than WM_QUIT, the return value is nonzero.<\/p>\n<p>If the function retrieves the WM_QUIT message, the return value is zero. <\/p>\n<p>If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError.\n<\/p><\/blockquote>\n<p>Yep, it&#8217;s zero, non-zero, or negative one.<\/p>\n<p>Okay, I&#8217;ll give Microsoft a bit of slack there, since GetMessage has been around since the 16-bit Windows days, and the alternate return value for GetMessage was probably not there in the original design.<\/p>\n<p>The thing that really got me started writing this article, though, was a little gem that I found while poking around in the CRT source code included with Visual Studio 2005.  In &#8220;mstartup.cpp&#8221;, I found the following bit of code which is apparently used for Managed C++ support (which is not exactly legacy\/old code):<\/p>\n<pre>class TriBool\r\n{\r\npublic:\r\n    enum State { False = 0, True = -1, Unknown = 2 };\r\nprivate:\r\n    TriBool();\r\n    ~TriBool();\r\n};\r\n<\/pre>\n<p>I guess trooleans are still all the rage these days (for some of us, anyway).  Perhaps somebody needs to introduce the CRT programmer(s) to <a title=\"What is truth? [The Daily WTF]\" href=\"http:\/\/thedailywtf.com\/forums\/47844\/ShowPost.aspx\">The Daily WTF<\/a>&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a particularly amusing curiousity in Microsoft Win32 code that I have seen crop up a couple of times over the year: The &#8220;troolean&#8221;, or the &#8220;boolean&#8221; value with true\/false\/other as possible values. You have probably seen this before in the winuser messaging APIs, such as the classic example of GetMessage: WINUSERAPI BOOL WINAPI [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/87"}],"collection":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=87"}],"version-history":[{"count":1,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":635,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions\/635"}],"wp:attachment":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}