<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tdistler.com &#187; windows</title>
	<atom:link href="http://tdistler.com/tag/windows/feed" rel="self" type="application/rss+xml" />
	<link>http://tdistler.com</link>
	<description>&#34;To err is human, but to really foul things up you need a computer.”</description>
	<lastBuildDate>Wed, 16 May 2012 03:00:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Inside the .NET CLR Garbage Collector</title>
		<link>http://tdistler.com/2011/09/09/inside-the-net-clr-garbage-collector</link>
		<comments>http://tdistler.com/2011/09/09/inside-the-net-clr-garbage-collector#comments</comments>
		<pubDate>Fri, 09 Sep 2011 15:00:29 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=1049</guid>
		<description><![CDATA[Here&#8217;s a great interview with Microsoft Technical Fellow and author of the CLR garbage collector, Patrick Dussud. How does GC, work, generally? Why is it important? The GC inside of the CLR is of a specfic type &#8211; ephemeral, concurrent (the server version has always been concuurent and now with Background GC on the client [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a great interview with Microsoft Technical Fellow and author of the CLR garbage collector, <a title="Profile: Patrick Dussud" href="http://www.microsoft.com/presspass/exec/techfellow/dussud/default.mspx" target="_blank">Patrick Dussud</a>.</p>
<blockquote><p>How does GC, work, generally? Why is it important? The GC inside of the CLR is of a specfic type &#8211; ephemeral, concurrent (the server version has always been concuurent and now with Background GC on the client in CLR 4, GC is concurrent on the client as well, but there are differences&#8230;)</p></blockquote>
<p><iframe style="height: 288px; width: 512px;" src="http://channel9.msdn.com/Shows/Going+Deep/E2E-Erik-Meijer-and-Patrick-Dussud-Inside-Garbage-Collection/player?w=512&amp;h=288" frameborder="0" scrolling="no" width="320" height="240"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2011/09/09/inside-the-net-clr-garbage-collector/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Live555: Compiling with VS2008</title>
		<link>http://tdistler.com/2011/05/14/live555-compiling-with-vs2008</link>
		<comments>http://tdistler.com/2011/05/14/live555-compiling-with-vs2008#comments</comments>
		<pubDate>Sat, 14 May 2011 18:30:49 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[live555]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=959</guid>
		<description><![CDATA[4 easy steps to compile Live555 using VS2008. Fixes link error: LNK1181: cannot open input file 'msvcirt.lib'.]]></description>
			<content:encoded><![CDATA[<p><a href="http://tdistler.com/wp-content/uploads/2011/02/network.jpg"><img class="alignright size-thumbnail wp-image-795" title="network" src="http://tdistler.com/wp-content/uploads/2011/02/network-150x150.jpg" alt="" width="100" height="100" /></a>Compiling <a title="Live555 Streaming Media" href="http://www.live555.com/liveMedia/" target="_blank">Live555 Streaming Media</a> with Visual Studio 2008 isn&#8217;t obvious. Using Cygwin or MinGW is just a pain and frankly unnecessary. There is no built-in support for VS solution files, because Windows support is a low priority for the Live555 community. This is evidenced by <a title="Live555 Forum" href="http://lists.live555.com/pipermail/live-devel/2008-January/008022.html" target="_blank">this forum response</a> from Ross Finlayson:</p>
<blockquote><p><em>&gt;4.  Is it possible to include a Visual Studio solution in the</em><br />
<em> &gt;distrubution to make it more convenient for Windows developers to</em><br />
<em> &gt;use live555?</em><br />
<em> &gt;5.  Is it possible for live555 to generate adequate makefiles for</em><br />
<em> &gt;Windows systems with development environments newer than Visual</em><br />
<em> &gt;Studio 2003?</em></p>
<p><strong>I have no current plans to change this.  (These days, fewer and fewer</strong> <strong>people seem to be using Windows for development of system software.)</strong></p></blockquote>
<p>Regardless, Live555 works fine on Windows and is actually quite easy to build. Simply do the following:</p>
<ol>
<li>Open the &#8216;win32config&#8217; file and change the <code>TOOLS32=... </code>variable to your VS2008 install directory. For me, it&#8217;s <code>TOOLS32=C:\Program Files\Microsoft Visual Studio 9.0\VC</code></li>
<li>In &#8216;win32config&#8217;, modify the <code>LINK_OPTS_0=...</code> line from <code>msvcirt.lib</code> to <code>msvcrt.lib</code>. This fixes the link error:<br />
<code>LINK : fatal error LNK1181: cannot open input file 'msvcirt.lib'</code></li>
<li>Open the Visual Studio command prompt.</li>
<li>From the &#8216;live&#8217; source directory, run <code>genWindowsMakefiles</code></li>
<li>Now you&#8217;re ready to build. Simply run the following commands:
<pre><code>cd liveMedia
nmake /B -f liveMedia.mak
cd ..\groupsock
nmake /B -f groupsock.mak
cd ..\UsageEnvironment
nmake /B -f UsageEnvironment.mak
cd ..\BasicUsageEnvironment
nmake /B -f BasicUsageEnvironment.mak
cd ..\testProgs
nmake /B -f testProgs.mak
cd ..\mediaServer
nmake /B -f mediaServer.mak</code></pre>
</li>
</ol>
<p>That&#8217;s it. You should be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2011/05/14/live555-compiling-with-vs2008/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Rendering Video with GDI (Example)</title>
		<link>http://tdistler.com/2011/04/20/rendering-video-with-gdi-example</link>
		<comments>http://tdistler.com/2011/04/20/rendering-video-with-gdi-example#comments</comments>
		<pubDate>Wed, 20 Apr 2011 18:04:25 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=932</guid>
		<description><![CDATA[Example C++ GDI video window class with text overlay.]]></description>
			<content:encoded><![CDATA[<p><a href="http://tdistler.com/wp-content/uploads/2011/04/video-icon.jpg"><img class="alignright size-thumbnail wp-image-948" title="video-icon" src="http://tdistler.com/wp-content/uploads/2011/04/video-icon-150x150.jpg" alt="" width="150" height="150" /></a>In this post, I outline a basic GDI video window class. GDI is inefficient for rendering video, but it&#8217;s also very convinient when writing simple tools on Windows. I find myself doing it often enough that it makes sense to do a brain-dump here. This is only an outline, but it should get you over the biggest hurdles.</p>
<h4>Outline</h4>
<ol>
<li>Video Window Class Definition</li>
<li>Creating and Destroying the Window</li>
<li>The Window Thread</li>
<li>The Message Pump</li>
<li>Rendering a Video Frame</li>
</ol>
<p>Things to note:</p>
<ul>
<li>You will need a thread in your window class to &#8220;pump&#8221; window events.</li>
<li>GDI does NOT do any color conversion, so you will need to convert each frame into the same format as the display (always RGB, usually 24 or 32 bits).</li>
</ul>
<h4>Video Window Class Definition</h4>
<pre><code>class VideoWindow
{
public:
    ...
private:
    static DWORD _ThreadMain(void*);
    static LRESULT WINAPI _MsgProc(HWND, UINT, WPARAM, LPARAM);

    CRITICAL_SECTION _lok;
    HANDLE _thread;
    HWND _hWnd;
    HDC _hDC;
    HDC _hFrameDC;
    HFONT _hFont;
    int _bpp;   // bit depth
    volatile bool _exit;
    int _x, _y, _w, _h; // Window dimensions
    int _imgWidth, _imgHeight, _imgLength; // Frame dimensions
    unsigned char *_imgBits;
};

</code></pre>
<h4>Creating and Destroying the Window</h4>
<pre><code>void VideoWindow::Create(int x, int y, int w, int h)
{
    EnterCriticalSection(&amp;_lok);
    _x = x;
    _y = y;
    _w = w;
    _h = h;
    _hWnd = 0;
    _exit = false;
    _thread = CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)_ThreadMain,
        this, NULL, 0 );
    LeaveCriticalSection(&amp;_lok);

    // Wait for window to be created. Cheap, but it works.
    while (!_hWnd) {
        ::Sleep(100);
    }
}
<span id="more-932"></span>
void VideoWindow::Destroy()
{
    // Safe to call from the destructor.

    EnterCriticalSection(&amp;_lok);
    if(_hWnd)
    {
        _exit = true;
        LeaveCriticalSection(&amp;_lok);
        WaitForSingleObject( _thread, INFINITE );
        CloseHandle(_thread);
        EnterCriticalSection(&amp;_lok);
        DestroyWindow(_hWnd);
        _hWnd = 0;
    }
    if (_hFont) ::DeleteObject(_hFont);
    if (_hFrameDC) ::DeleteDC(_hFrameDC);
    if (_hDC) ::DeleteDC(_hDC);
    LeaveCriticalSection(&amp;_lok);
}

</code></pre>
<h4>The Window Thread</h4>
<pre><code>DWORD VideoWindow::_ThreadMain(void* ctx)
{
    VideoWindow *p = (VideoWindow*)ctx;
    EnterCriticalSection(&amp;p-&gt;_lok);

    LPCSTR className = "VideoWndClass";
    LPCSTR windowName = "MyWindowText";
    WNDCLASSEX wcex = {
        sizeof(WNDCLASSEX),
        CS_OWNDC | CS_HREDRAW | CS_VREDRAW,
        _MsgProc,
        0L,
        0L,
        NULL,
        NULL,
        NULL,
        (HBRUSH)GetStockObject(BLACK_BRUSH),
        NULL,
        className,
        NULL
    };

    RegisterClassEx(&amp;wcex);   

    p-&gt;_hWnd = CreateWindow(className, windowName, WS_OVERLAPPEDWINDOW,
        p-&gt;_x, p-&gt;_y, p-&gt;_w, p-&gt;_h, ::GetDesktopWindow(), NULL, NULL, NULL);

    p-&gt;_hDC = ::GetDC(p-&gt;_hWnd);
    p-&gt;_bpp = ::GetDeviceCaps(p-&gt;_hDC, BITSPIXEL);
    p-&gt;_hFrameDC = ::CreateCompatibleDC(p-&gt;_hDC);

    p-&gt;_hFont = ::CreateFont(18, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
        ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
        ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");

    ShowWindow(p-&gt;_hWnd,SW_SHOW);
    UpdateWindow(p-&gt;_hWnd);

    while( !p-&gt;_exit )
    {
        MSG msg;
        if(PeekMessage(&amp;msg,p-&gt;_hWnd,0,0,PM_REMOVE))
        {
            TranslateMessage(&amp;msg);
            DispatchMessage(&amp;msg);
        }

        LeaveCriticalSection(&amp;p-&gt;_lok);
        Sleep(50); // A better way to do this is to use a message
        EnterCriticalSection(&amp;p-&gt;_lok);
    }
    LeaveCriticalSection(&amp;p-&gt;_lok);
    return 0;
}

</code></pre>
<h4>The Message Pump</h4>
<pre><code>LRESULT WINAPI VideoWindow::_MsgProc(HWND hWnd, UINT msg, WPARAM w, LPARAM l)
{
    if (msg == WM_PAINT &amp;&amp; l)
    {
        VideoWindow *p = (VideoWindow*)l;
        EnterCriticalSection(&amp;p-&gt;_lok);

        HGDIOBJ  oldFont  = ::SelectObject(p-&gt;_hDC, p-&gt;_hFont);
        COLORREF oldFtColor = ::SetTextColor(p-&gt;_hDC, RGB(255,255,255));
        COLORREF oldBkColor = ::SetBkColor(p-&gt;_hDC, RGB(64,64,64));

        // Render image
        //
        // NOTE: This assumes you've already coverted the image to the proper
        // RGB bit-depth (_bpp) and copied the data into _imageBits.
        //
        HBITMAP hBMP = ::CreateCompatibleBitmap(p-&gt;_hDC, p-&gt;_imgWidth,
            p-&gt;_imgHeight);
        ::SetBitmapBits(hBMP, p-&gt;_imgLength, p-&gt;_imgBits);
        HGDIOBJ oldBMP = ::SelectObject(p-&gt;_hFrameDC, hBMP);
        ::BitBlt(p-&gt;_hDC, 0, 0, p-&gt;_imgWidth, p-&gt;_imgHeight, p-&gt;_hFrameDC,
            0, 0, SRCCOPY);
        ::SelectObject(p-&gt;_hFrameDC, oldBMP);

        // Draw some text over the image
        RECT rect;
        ::SetRectEmpty(&amp;rect);
        ::DrawText(p-&gt;_hDC, p-&gt;_imageText, -1, &amp;rect, DT_CALCRECT);
        ::DrawText(p-&gt;_hDC, p-&gt;_imageText, -1, &amp;rect, DT_CENTER | DT_VCENTER);

        if (hBMP) ::DeleteObject(hBMP);

        LeaveCriticalSection(&amp;p-&gt;_lok);
    }
    return DefWindowProc(hWnd, msg, w, l);
}

</code></pre>
<p><strong>Rendering a Video Frame</strong></p>
<pre><code>
void VideoWindow::Render(const unsigned char* frame, int w, int h, int stride)
{
    // Convert frame to the proper RGB bit depth to match _bpp and copy it
    // into _imgBits buffer. Update _imgWidth, _imgHeight, and _imgLength as
    // necessary.

    ::PostMessage(_hWnd, WM_PAINT, 0, (LPARAM)this);
}

</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2011/04/20/rendering-video-with-gdi-example/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Define NaN (Not-a-Number) on Windows</title>
		<link>http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows</link>
		<comments>http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows#comments</comments>
		<pubDate>Thu, 24 Mar 2011 20:41:48 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=874</guid>
		<description><![CDATA[The C99 spec requires that math.h should define the constant float value NAN. However, NAN isn&#8217;t defined in the Visual Studio version of math.h, so you have to define it yourself (VS only implements C89). It&#8217;s pretty straight-forward for 32-bit machines&#8230; here&#8217;s my implementation with cross-platform protection: #ifdef WIN32 #ifndef NAN static const unsigned long [...]]]></description>
			<content:encoded><![CDATA[<p>The C99 spec requires that <a title="The Open Group: math.h" href="http://pubs.opengroup.org/onlinepubs/009695399/basedefs/math.h.html" target="_blank">math.h should define the constant float value NAN</a>. However, NAN isn&#8217;t defined in the Visual Studio version of math.h, so you have to define it yourself (VS only implements C89). It&#8217;s pretty straight-forward for 32-bit machines&#8230; here&#8217;s my implementation with cross-platform protection:</p>
<pre><code>#ifdef WIN32
    #ifndef NAN
        static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
        #define NAN (*(const float *) __nan)
    #endif
#endif

</code></pre>
<p>This code is adapted from an MSDN <a title="MSDN: Not A Number (NAN) Items" href="http://msdn.microsoft.com/en-us/library/w22adx1s(v=vs.80).aspx" target="_blank">example</a>.<del datetime="2011-04-20T17:26:37+00:00"></del></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cross-Platform IPv6 Socket Programming</title>
		<link>http://tdistler.com/2011/02/28/cross-platform-ipv6-socket-programming</link>
		<comments>http://tdistler.com/2011/02/28/cross-platform-ipv6-socket-programming#comments</comments>
		<pubDate>Tue, 01 Mar 2011 04:00:39 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=793</guid>
		<description><![CDATA[Writing code that works on Windows, Linux, and Mac is frequently challenging. Socket programming is no exception. Modern versions of Linux and Mac have full implementations of the latest IPv6 socket API extensions defined in RFC 3493. Windows, however, has only a partial implementation of the original (deprecated) version, RFC 2553. This sounds worse than [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tdistler.com/wp-content/uploads/2011/02/network.jpg"><img class="alignright size-thumbnail wp-image-795" title="network" src="http://tdistler.com/wp-content/uploads/2011/02/network-150x150.jpg" alt="IPv6 Networking" width="150" height="150" /></a>Writing code that works on Windows, Linux, and Mac is frequently challenging. Socket programming is no exception. Modern versions of Linux and Mac have full implementations of the latest IPv6 socket API extensions defined in <a title="IETF RFC 3493" href="http://tools.ietf.org/html/rfc3493" target="_blank">RFC 3493</a>. Windows, however, has only a partial implementation of the original (deprecated) version, <a title="IETF RFC 2553" href="http://tools.ietf.org/html/rfc2553" target="_blank">RFC 2553</a>. This sounds worse than it is, but it&#8217;s something you have to consider.</p>
<p><em><strong>Note</strong></em>: This post assumes you are already familiar with the socket extensions for IPv6 (<a title="IETF RFC 3493" href="http://tools.ietf.org/html/rfc3493" target="_blank">RFC 3493</a>).</p>
<p><strong>Linux and Mac</strong><br />
Good news&#8230; they both fully support <a title="IETF RFC 3493" href="http://tools.ietf.org/html/rfc3493" target="_blank">RFC 3493</a>.</p>
<p><strong>Windows</strong><br />
Windows IPv6 support varies based on which version you&#8217;re targeting. Microsoft started adding IPv6 in Windows 2000, and they&#8217;ve continued adding more of the socket extensions as time went on. Most of the core functionality is present in XP, and what&#8217;s missing is easily replaced by using Winsock calls directly (more on this later).</p>
<p>Windows gained IPv6 support while <a title="IETF RFC 2553" href="http://tools.ietf.org/html/rfc2553" target="_blank">RFC 2553</a> was still the supported standard. Since then, it has been deprecated by <a title="IETF RFC 3493" href="http://tools.ietf.org/html/rfc3493" target="_blank">RFC 3493</a>. However, Microsoft doesn&#8217;t want to break existing code written against it&#8217;s API, so the older API lives on. The main impact of this is that <code>sockaddr_in6</code> and <code>sockaddr_storage</code> are slightly different on Windows than Mac and Linux. The size of the structures across platforms is the same (the <code>sa_family_t</code> member was shortened), it&#8217;s just that the Windows structures don&#8217;t begin with the length member. For example:</p>
<pre><code>// Linux and Mac
struct sockaddr_in6 {
    uint8_t      sin6_len;    /* Added in RFC 3493 */
    sa_family_t  sin6_family;
    ...
};
struct sockaddr_storage {
    uint8_t      ss_len;      /* Added in RFC 3493 */
    sa_family_t  ss_family;
    ...
};

// Windows
struct sockaddr_in6 {
    sa_family_t  sin6_family;
    ...
};
struct sockaddr_storage {
    sa_family_t  ss_family;
    ...
};</code></pre>
<p>I&#8217;ve never had a problem with this, because the size of <code>sockaddr_in6</code> is easily determined (<code>sizeof(sockaddr_in6)</code>) and I always end up casting <code>sockaddr_storage</code> to the specific type (<code>sockaddr_in</code> or <code>sockaddr_in6</code>) based on <code>ss_family</code>.</p>
<p>Besides the data structure differences, it&#8217;s important to remember that Microsoft added IPv6 support over multiple versions. Support first appeared in Windows 2000, but more of the extensions have been added over time. Most of the core functionality was present in XP (including multicast), but not everything is implemented as of Windows 7. It&#8217;s annoying, but I will say that what&#8217;s missing is easily replaced by using Winsock calls directly.</p>
<p>Here&#8217;s the breakdown of IPv6 socket extensions by Windows version:</p>
<table border="1" width="570">
<tbody><!-- Results table headers --></p>
<tr>
<th>Socket Extension</th>
<th>2K</th>
<th>XP</th>
<th>Vista</th>
<th>7</th>
<th>Comments</th>
</tr>
<tr>
<td>if_indextoname()</td>
<td></td>
<td></td>
<td>x</td>
<td>x</td>
<td>GetAdaptersAddresses() for XP</td>
</tr>
<tr>
<td>if_nametoindex()</td>
<td></td>
<td></td>
<td>x</td>
<td>x</td>
<td>GetAdaptersAddresses() for XP</td>
</tr>
<tr>
<td>if_nameindex()</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>GetAdaptersAddresses() (XP, later)</td>
</tr>
<tr>
<td>if_freenameindex()</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>getaddrinfo()</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td></td>
</tr>
<tr>
<td>getnameinfo()</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td></td>
</tr>
<tr>
<td>freeaddrinfo()</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td></td>
</tr>
<tr>
<td>gai_strerror()</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td>x</td>
<td></td>
</tr>
<tr>
<td>inet_pton()</td>
<td></td>
<td></td>
<td>x</td>
<td>x</td>
<td>WSAStringToAddress() (2000, XP)</td>
</tr>
<tr>
<td>inet_ntop()</td>
<td></td>
<td></td>
<td>x</td>
<td>x</td>
<td>WSAAddressToString() (2000, XP)</td>
</tr>
<tr>
<td>All IN6_IS_ADDR_* macros</td>
<td></td>
<td>x</td>
<td>x</td>
<td>x</td>
<td>Ex: IN6_IS_ADDR_LOOPBACK()</td>
</tr>
<tr>
<td>struct sockaddr_storage</td>
<td></td>
<td>x</td>
<td>x</td>
<td>x</td>
<td></td>
</tr>
<tr>
<td>Multicast support</td>
<td></td>
<td>x</td>
<td>x</td>
<td>x</td>
<td></td>
</tr>
</tbody>
</table>
<p>As you can see, you may still have to call Winsock directly depending on what version of Windows you are targeting. In my opinion, programming IPv6 on Windows is a lot easier if you only support XP and later, but I know that&#8217;s not always possible.</p>
<p><strong>Summary</strong></p>
<p>Modern operating systems all support IPv6. However, for business reasons, Windows has a slightly older version of the socket API which requires special consideration. My goal was to enumerate those differences to help make the transition to IPv6 smoother. Writing cross-platform code can be a fun challenge at times, but it&#8217;s also a little tedious. Hopefully, this post helps ease the pain.</p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2011/02/28/cross-platform-ipv6-socket-programming/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPU Profiling on Windows: Very Sleepy</title>
		<link>http://tdistler.com/2010/12/21/cpu-profiling-on-windows-very-sleepy</link>
		<comments>http://tdistler.com/2010/12/21/cpu-profiling-on-windows-very-sleepy#comments</comments>
		<pubDate>Tue, 21 Dec 2010 19:59:04 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=697</guid>
		<description><![CDATA[A colleague of mine found a pretty cool profiling tool for Windows called Very Sleepy. It&#8217;s simple, straight-forward, free, and it works&#8230; everything I like in a tool (this is why I like the Sysinternals stuff so much). It&#8217;s also got call-graph and 64-bit support. Definitely worth checking out.]]></description>
			<content:encoded><![CDATA[<p>A colleague of mine found a pretty cool profiling tool for Windows called <a title="Coders Notes: Very Sleepy" href="http://www.codersnotes.com/sleepy" target="_blank">Very Sleepy</a>. It&#8217;s simple, straight-forward, free, and it works&#8230; everything I like in a tool (this is why I like the <a title="Mircosoft Sysinternals" href="http://www.sysinternals.com" target="_blank">Sysinternals</a> stuff so much). It&#8217;s also got call-graph and 64-bit support. Definitely worth checking out.</p>
<p><a href="http://tdistler.com/wp-content/uploads/2011/01/very_sleepy_screenshot.jpg"><img class="aligncenter size-medium wp-image-698" title="very_sleepy_screenshot" src="http://tdistler.com/wp-content/uploads/2011/01/very_sleepy_screenshot-300x218.jpg" alt="Very Sleep Screen Shot" width="300" height="218" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2010/12/21/cpu-profiling-on-windows-very-sleepy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>High-performance Timing on Linux / Windows</title>
		<link>http://tdistler.com/2010/06/27/high-performance-timing-on-linux-windows</link>
		<comments>http://tdistler.com/2010/06/27/high-performance-timing-on-linux-windows#comments</comments>
		<pubDate>Mon, 28 Jun 2010 05:15:55 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=350</guid>
		<description><![CDATA[High-performance timing is hard… no doubt about it. I can’t tell you how many times I’ve seen high-performance timing code done wrong. Timing is one of those things where a little knowledge can be problematic; the code may work, but it either won’t perform or will exhibit “unexplained” behavior. The purpose of this post is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tdistler.com/wp-content/uploads/2010/06/melting_clock.jpg"><img class="alignright size-full wp-image-352" title="melting_clock" src="http://tdistler.com/wp-content/uploads/2010/06/melting_clock.jpg" alt="Melting Clock" width="96" height="96" /></a>High-performance timing is hard… no doubt about it. I can’t tell you how many times I’ve seen high-performance timing code done wrong. Timing is one of those things where a little knowledge can be problematic; the code may work, but it either won’t perform or will exhibit “unexplained” behavior. The purpose of this post is to explain a foundational component to getting timing right: <em>the clock</em>. I won’t focus on theory… this post is meant to be pragmatic.</p>
<p><em>Note</em>: I’m talking here about interval timing (i.e. accurately measuring the duration between 2 events). This is different than synchronizing different clocks or maintaining accurate wall time.</p>
<p><strong>Anatomy of the Clock</strong></p>
<p>The first mistake most people make when doing timing is to use functions like <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/gettimeofday.html" target="_blank">gettimeofday()</a></code>, <code><a title="MSDN: GetSystemTime" href="http://msdn.microsoft.com/en-us/library/ms724390(VS.85).aspx" target="_blank">GetSystemTime()</a></code>, etc. These functions return what is called &#8220;wall time&#8221;… time that corresponds to a calendar date/time. These clocks suffer from the follow limitations:</p>
<ol>
<li>They have a low resolution: “High-performance” timing, by my definition, requires clock resolutions into the microseconds or better.</li>
<li>They can jump forwards and backwards in time: Computer clocks all tick at slightly different rates, which causes the time to drift. Most systems have NTP enabled which periodically adjusts the system clock to keep them in sync with “actual” time. The adjustment can cause the clock to suddenly jump forward (artificially inflating your timing numbers) or jump backwards (causing your timing calculations to go negative or hugely positive).</li>
</ol>
<p>For interval timing, all that’s needed for a clock is a simple counter that increments at a stable rate. For high-performance timing, the rate this counter increments should be high. A related constraint is that the counter must be monotonic (can never “tick” backwards&#8230; ever). The counter may overflow and wrap back to 0, but using unsigned math in your timing calculations can compensate for that (see example below).</p>
<p>Something to note: since we are usually measuring short durations, the drift of the clock is so small that we aren&#8217;t concerned by it (what matters is the drift between successive reads, not total drift over time).<span id="more-350"></span></p>
<p><strong>Using the Clock</strong></p>
<p>To use the clock, you need access to 2 pieces of information: the clock value, and the rate (frequency) at which it increments. Once you have that information, it’s trivial to calculate the duration between 2 successive reads of the clock.</p>
<p>For example, consider the following:</p>
<p>-        <code>start</code> equals the clock value at the beginning of the interval to measure.</p>
<p>-        <code>end</code> equals the clock value at the end of the interval.</p>
<p>-        <code>frequency</code> equals the frequency that the clock increments per second.</p>
<p>Calculating the duration of the interval (in seconds) is as simple as:</p>
<p><code>duration = (end – start) / frequency</code></p>
<p><code>duration</code> will equal the floating-point interval time in seconds (e.g. 0.000237 = 237us).</p>
<p>A common use case I’ve seen is wanting to measure the duration between successive calls to a function. Here’s one way to implement that:</p>
<pre><code>float freq = (float) get_frequency();

Foo()
{
    unsigned now = read_clock();
    float duration = (float)(now – last) / (float)freq;
    last = now;

    /* Your code here */
}
</code></pre>
<p>It is important to use unsigned variables for <code>now</code> and <code>last</code> or your calculations will go haywire if the clock ever wraps back to 0. Consider what happens if <code>now</code> is less than <code>last</code>. Using unsigned variables allows the math operation to underflow, which produces the correct result. If you don&#8217;t believe me, just write some test code and see for yourself&#8230; it&#8217;s an important concept to understand.</p>
<p><strong>Don’t Use RDTSC As Your Clock</strong></p>
<p>I’m dismayed by how many forum posts suggest that newbie’s use <a title="Wikipedia: RDTSC" href="http://en.wikipedia.org/wiki/RDTSC" target="_blank">RDTSC</a> for timing. Don’t get me wrong; the TSC isn’t bad in-and-of-itself. It’s just way too hard to get timing right with it unless you’re an expert… and if you’re reading this, chances are you aren’t <img src='http://tdistler.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Stick to the higher level API’s I present below.</p>
<p>Even if you are an expert, I still suggest avoiding RDTSC for the following reasons:</p>
<ol>
<li>It’s processor core specific: Using RDTSC will give different values on different processor cores. This causes non-monotonic clock behavior as a thread is migrated across cores during execution (i.e. the clock can tick backwards on two successive reads). Conversely, the clock may also appear to jump forwards if the thread moves to a different core.</li>
<li>It doesn’t always tick at the same rate: On some systems, the clock frequency will vary as the CPU load changes. This is due to power saving features in the processor that throttle down the clock speed when the load is low (e.g. Intel SpeedStep).</li>
<li>It’s unnecessary: there are better alternatives to RDTSC that are readily available (<a title="Wikipedia: High Precision Event Timer" href="http://en.wikipedia.org/wiki/High_Precision_Event_Timer" target="_blank">HPET</a> and <a title="Wikipedia: Advanced Programmable Interrupt Controller" href="http://en.wikipedia.org/wiki/Advanced_Programmable_Interrupt_Controller" target="_blank">APIC</a>).</li>
</ol>
<p>“<a title="Game Timing and Multicore Processors" href="http://msdn.microsoft.com/en-us/library/ee417693(VS.85).aspx" target="_blank">Game Timing and Multicore Processors</a>” has more info, though it’s centered around Windows.</p>
<p>“<a title="Guidelines For Providing Multimedia Support" href="http://www.microsoft.com/whdc/system/sysinternals/mm-timer.mspx" target="_blank">Guidelines For Providing Multimedia Support</a>” has a good summary of the hardware clocks on the PC platform, and justification for the creation of the HPET.</p>
<p>A more technical look into the past problems with RDTSC can be found in <a title="Email from Rick Brunner" href="http://lkml.org/lkml/2005/11/4/173" target="_blank">this email from Rick Brunner (AMD Fellow)</a>.</p>
<p>If you&#8217;re having trouble sleeping, you can look at <a title="Intel: HPET Design" href="http://www.intel.com/hardwaredesign/hpetspec_1.pdf" target="_blank">Intel’s HPET design document</a>.</p>
<p><strong>Linux Clock</strong></p>
<p>POSIX.1b defines realtime clock methods that you’ll find on most *NIX systems (the full spec can be viewed <a title="POSIX Specification 2008" href="http://www.opengroup.org/onlinepubs/9699919799/" target="_blank">HERE</a>). Specifically, you want to use <code>clock_getres()</code> and <code>clock_gettime()</code>. <code>clock_getres()</code> returns the resolution (frequency) of the clock, and <code>clock_gettime()</code> returns the current value of the clock. Most systems implement the <code>CLOCK_MONOTONIC</code> type, which provides a frequency-stable, monotonically-increasing counter. The resolution of <code>CLOCK_MONOTONIC</code> is high on the 2.6 kernel, in my experience. I recommend using this clock when building a high-performance timing solutions on Linux.</p>
<p>The methods are defined in <code>time.h</code>, and you need to link against librt (pass ‘-lrt’ to gcc). The prototypes for the functions are:</p>
<p><code>int clock_getres(clockid_t <em>clock_id</em>, struct timespec *<em>res</em>);</code><br />
<code>int clock_gettime(clockid_t <em>clock_id</em>, struct timespec *<em>tp</em>);</code></p>
<p>A detailed description of these methods can be found <a href="http://www.opengroup.org/onlinepubs/000095399/functions/clock_getres.html" target="_blank">HERE</a>.</p>
<p>I also suggest looking at <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/clock_nanosleep.html" target="_blank">clock_nanosleep()</a></code>, but that’s a separate topic.</p>
<p><strong>Windows Clock</strong></p>
<p>On Windows, <code><a href="http://msdn.microsoft.com/en-us/library/ms644905(VS.85).aspx" target="_blank">QueryPerformanceFrequency()</a></code> and <code><a href="http://msdn.microsoft.com/en-us/library/ms644904(v=VS.85).aspx" target="_blank">QueryPerformanceCounter()</a></code> are the obvious choice. <code>QueryPerformanceFrequency()</code> returns (surprise!) the frequency of the counter. <code>QueryPerformanceCounter()</code> returns the current value of the counter. Just like <code>CLOCK_MONOTONIC</code> on Linux, the Windows performance counter is a high-frequency, stable, monotonically-increasing counter.</p>
<p>The methods are defined in <code>windows.h</code>. The prototypes are:</p>
<p><code>BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);<br />
BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount)</code>;</p>
<p><strong>Windows Timing Errata</strong></p>
<p><em>Note</em>: The follow items do NOT affect the resolution of the Window’s performance counter, but I think it’s still important to know when doing timing on Windows.</p>
<p>One problem you may run into on Windows is that the default system clock interval defaults to 10 or 15ms (depending of the OS version). This clock is what drives all the timers and sleep functions for that platform. What this means is that, left to the default, your timers will trigger 5 to 7.5ms late, on average.</p>
<p>You can fix this by increasing the system clock resolution to 2ms (I remember reading a tech article by Microsoft saying that 2ms gave better system performance than 1ms, but I can’t find it for the life of me). You do this by using the <code>timeGetDevCaps()</code>, <code>timeBeginPeriod()</code> and <code>timeEndPeriod()</code>. Sample code can be found <a title="Windows Multimedia Timers" href="http://msdn.microsoft.com/en-us/library/dd743626(v=VS.85).aspx" target="_blank">HERE</a>. You have to include <code>mmsystem.h</code> and link against <code>Winmm.lib</code>.</p>
<p>I feel it necessary to note that increasing the system clock interval negatively affects power consumption. The Windows 7 blog as an interesting breakdown of “<a title="Windows 7 Energy Efficiency" href="http://blogs.msdn.com/b/e7/archive/2009/01/06/windows-7-energy-efficiency.aspx" target="_blank">Windows 7 Energy Efficiency</a>”. Specifically, they noticed a 10% drop in battery life when the clock resolution was set to 1ms using <code>timeBeginPeriod()</code>.</p>
<p>Maybe this last section belongs in a separate post, but whatever&#8230; <img src='http://tdistler.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2010/06/27/high-performance-timing-on-linux-windows/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>StackHash and Application Crashes on Windows</title>
		<link>http://tdistler.com/2009/04/10/stackhash-and-application-crashes-on-windows</link>
		<comments>http://tdistler.com/2009/04/10/stackhash-and-application-crashes-on-windows#comments</comments>
		<pubDate>Fri, 10 Apr 2009 15:00:50 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=186</guid>
		<description><![CDATA[We got an interesting application crash yesterday with a confusing message similar to this: Fault bucket 42424242, type 1 Event Name: APPCRASH Response: None Cab Id: 0 Problem signature: P1: MyApp.exe P2: 1.42.42.42 P3: 598773cf P4: StackHash_ac62 P5: 0.0.0.0 P6: 00000000 P7: c0000007 P8: 00000000 P9: P10: We spent some time wondering if our crypto [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" src="/media/images/software_bug.jpg" alt="Software Bug" />We got an interesting application crash yesterday with a confusing message similar to this:</p>
<p class="codeblock">
Fault bucket 42424242, type 1<br />
Event Name: APPCRASH<br />
Response: None<br />
Cab Id: 0<br/><br />
Problem signature:<br />
P1: MyApp.exe<br />
P2: 1.42.42.42<br />
P3: 598773cf<br />
P4: StackHash_ac62<br />
P5: 0.0.0.0<br />
P6: 00000000<br />
P7: c0000007<br />
P8: 00000000<br />
P9:<br />
P10:
</p>
<p>We spent some time wondering if our crypto libraries were the problem (we just made some changes recently), but concluded that was unlikely. So what the heck is the &#8220;StackHash&#8221; module? Did our trashed stack cause the kernel to think we were a different module? Nope.</p>
<p>The answer is that the Windows executive couldn&#8217;t identify the module we were in when the application crashed (it uses the instruction pointer to determine what code was executing). In this case, the kernel simply takes a hash of the stack so at least we might be able to identify if we&#8217;ve seen this exact crash before. Here&#8217;s the answer summarized by an engineer from Microsoft:</p>
<blockquote><p>In the OS when I try to get a faulting module name it is possible that there is no module laoded (sic) at that address. For example in this case the EIP was zero. So in those cases where a module is not loaded and it is not also in the unloaded module list, I take a stack hash of the stack so that we can identify this crash from other crashes where also the module is not known.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2009/04/10/stackhash-and-application-crashes-on-windows/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>The &#8220;Analogy&#8221; Screensaver</title>
		<link>http://tdistler.com/2009/04/09/the-analogy-screensaver</link>
		<comments>http://tdistler.com/2009/04/09/the-analogy-screensaver#comments</comments>
		<pubDate>Thu, 09 Apr 2009 18:14:45 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Oh So Random]]></category>
		<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=176</guid>
		<description><![CDATA[I&#8217;ve been jealous of Rob&#8217;s screensaver for awhile now. I thought it was Mac only until I asked him about it&#8230; nope. I installed the Windows version today. What a beautiful piece of art! The creator, Jesson Yip, describes it like this: Analogy is a typographic clock which fuses the immediacy of digital with the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been jealous of <a href="http://rob.crabapples.net/" target="_blank">Rob&#8217;s</a> screensaver for awhile now. I thought it was Mac only until I asked him about it&#8230; nope. I installed the Windows version today. What a beautiful piece of art! The creator, <a href="http://www.jessonyip.com/analogy/" target="_blank">Jesson Yip</a>, describes it like this:</p>
<blockquote><p>Analogy is a typographic clock which fuses the immediacy of digital with the visual-spatial quality of analogue into a hybrid format. It presents an everyday object with a fresh twist.</p></blockquote>
<p>Click on the image below to visit his site and download it. Enjoy!</p>
<p style="text-align: center;"><a href="http://www.jessonyip.com/analogy/" target="_blank"><img src="/media/images/analogy_screensaver.jpg" alt="Analogy Screensaver" width="400" height="400" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2009/04/09/the-analogy-screensaver/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debugging: ACE, Windows, and Memory Leak Detection</title>
		<link>http://tdistler.com/2008/11/14/debugging-ace-windows-and-memory-leak-detection</link>
		<comments>http://tdistler.com/2008/11/14/debugging-ace-windows-and-memory-leak-detection#comments</comments>
		<pubDate>Sat, 15 Nov 2008 00:26:30 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=148</guid>
		<description><![CDATA[The Windows development environment provided by VisualStudio has some neat tools for detecting memory leaks in code. You simply #define _CRTDBG_MAP_ALLOC before including your headers, and #include &#60;crtdbg.h&#62; as the last header: #define _CRTDBG_MAP_ALLOC // Include other header files here #include &#60;crtdbg.h&#62; Then, you call _CrtDumpMemoryLeaks() before your application exits. If your program exits at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="float: right;" src="/media/images/ACE_Logo.jpg" alt="ACE Logo" />The Windows development environment provided by VisualStudio has some neat tools for detecting memory leaks in code. You simply <code>#define _CRTDBG_MAP_ALLOC</code> before including your headers, and <code>#include &lt;crtdbg.h&gt; </code>as the last header:</p>
<p><code>#define _CRTDBG_MAP_ALLOC<br />
// Include other header files here<br />
#include &lt;crtdbg.h&gt;</code></p>
<p>Then, you call <code>_CrtDumpMemoryLeaks()</code> before your application exits. If your program exits at many points, you can alternatively call <code>_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF )</code> at the beginning of you application, which will cause the leaks to also be printed when it exits. The results are printed to the Debug Window and look like the following:</p>
<pre><code>Detected memory leaks!
Dumping objects -&gt;
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) :
{18} normal block at 0x00780E80, 64 bytes long.
Data: &lt;                &gt; CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.</code></pre>
<p><br/></p>
<p>Cool, Huh?! However, some libraries don&#8217;t play nice with this, as I explain below.</p>
<p><span id="more-148"></span><strong>Memory Leak Detection and ACE:</strong></p>
<p>I&#8217;ve mentioned <a title="Adaptive Communication Environment" href="http://www.cs.wustl.edu/~schmidt/ACE.html" target="_blank">ACE</a> before in a previous post <a title="C++ Portable Runtime Evaluation" href="http://tdistler.com/2007/11/01/c-portable-runtime-evaluation" target="_blank">evaluating portable runtime environments</a>. It&#8217;s a pretty cool set of libraries that provides a portable OS abstraction layer and communication environment. If you write your application using ACE, it will compile and run on a whole host of system types&#8230; but I digress.</p>
<p>One problem with ACE is that it conflicts with the Windows leak check code. If you define <code>_CRTDBG_MAP_ALLOC</code> before the ACE headers, you will get build errors like the following:</p>
<p><code>1&gt;..\include\ace\os_ns_unistd.h(154) : error C2059: syntax error : 'constant'</code></p>
<p>What&#8217;s happening is that the ACE headers try to enable the leak detection code themselves, which causes the overridden memory functions to conflict with the original versions. In essence, ACE is trying to define <code>malloc</code> (for example) after <code>crtdbg.h</code> has already overridden it.</p>
<p>So, how do you get your application to build with leak detection and ACE? Define <code>_CRTDBG_MAP_ALLOC</code> after the ACE headers (Remember: the ACE headers must <em>always </em>be included before other headers&#8230; another complaint I have).</p>
<p><code>#include "ace/ACE.h"<br />
#define _CRTDBG_MAP_ALLOC<br />
// Include other headers here<br />
#include &lt;crtdbg.h&gt;</code></p>
<p>Okay, your application should compile now. Run it and look at the output window. For a simple application that does nothing but return, this is what I see:</p>
<pre><code>Detected memory leaks!
Dumping objects -&gt;
{178} normal block at 0x00CDBD78, 50 bytes long.
Data: &lt;---TEST---      &gt; 2D 2D 2D 48 45 4C 4C 4F 2D 2D 2D 00 CD CD CD CD
{173} normal block at 0x002EAAC8, 8 bytes long.
Data: &lt;  .     &gt; C0 A1 2E 00 CD CD CD CD
{172} normal block at 0x002EAA78, 20 bytes long.
Data: &lt;4  Z       Z    &gt; 34 90 F3 5A 0A 01 00 00 F3 17 DA 5A 03 00 00 00
{171} normal block at 0x002EAA18, 32 bytes long.
Data: &lt;   Z  ]         &gt; C4 91 F3 5A C0 FB 5D 00 FF FF FF FF 00 00 00 00
{170} normal block at 0x002EA9B8, 32 bytes long.
Data: &lt;   Z  ]         &gt; C4 91 F3 5A 88 FB 5D 00 FF FF FF FF 00 00 00 00
{169} normal block at 0x002EA958, 32 bytes long.
Data: &lt;   ZP ]         &gt; B4 91 F3 5A 50 FB 5D 00 FF FF FF FF 00 00 00 00
{168} normal block at 0x002EA910, 8 bytes long.
Data: &lt;   Z    &gt; D4 91 F3 5A 00 00 00 00

... Truncated for sanity (30 more leaks follow) ...

Object dump complete.
The program '[14288] simple.exe: Native' has exited with code 0 (0x0).</code></pre>
<p><br/></p>
<p>These are very likely false-positives, but they are annoying. There are other problems too:</p>
<ol>
<li>There are no file/line numbers printed, so we can&#8217;t track down the code to verify if the errors are real or not.</li>
<li>File and line numbers don&#8217;t show up for errors <em>outside </em>of ACE (the first leak is mine).</li>
<li>All this output adds noise that can hide other memory leaks (I wish Microsoft would add a way to suppress errors we don&#8217;t care about&#8230; props to <a title="Valgrind" href="http://valgrind.org/" target="_blank">Valgrind</a> for doing this).</li>
</ol>
<p>Anyways, all of this is quite frustrating. I was hunting around on the ACE newsgroup for solutions and could only find <a title="ACE Newsgroup: checking application for memory leaks" href="http://groups.google.co.kr/group/comp.soft-sys.ace/browse_thread/thread/cc1c9642efaf17d7/36e97ef862bb84c0?#36e97ef862bb84c0" target="_blank">this thread</a>:</p>
<blockquote><p>&#8220;In general, we track memory issues on Windows using Purify, so you might try going that route.&#8221;<br />
Douglas Schmidt</p></blockquote>
<blockquote><p>&#8220;Correct. This memory tracking scheme and the ACE restrictions onheader file placement are at odds here. You have two choices:</p>
<p>1. Use a different memory tracking scheme such as Purify, which Doug<br />
suggested.</p>
<p>2. Develop, or sponsor, necessary changes to remove ACE&#8217;s restrictions<br />
on header file placement.&#8221;<br />
Steve Huston</p></blockquote>
<p>So there you have it: ACE and Window memory leak detection don&#8217;t play nice together. I hate encountering a problem without a viable solution&#8230; it bugs me (no pun intended). I even tried modifying the ACE headers with marginal results (it came close to compiling). Oh well&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2008/11/14/debugging-ace-windows-and-memory-leak-detection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 7 Development Guide</title>
		<link>http://tdistler.com/2008/11/04/windows-7-development-guide</link>
		<comments>http://tdistler.com/2008/11/04/windows-7-development-guide#comments</comments>
		<pubDate>Tue, 04 Nov 2008 18:39:40 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=144</guid>
		<description><![CDATA[Microsoft has started to release developer information for Windows 7 (the follow-on to Windows Vista). Of particular interest to me is the Windows 7 Developer Guide. It discusses many of the new features that will be available when this new version of Windows is released. Of particular interest to me are the changes to DirectX [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="float: right;" src="/media/images/windows-7-construction.jpg" alt="Windows 7: Under Construction" />Microsoft has started to release developer information for Windows 7 (the follow-on to Windows Vista). Of particular interest to me is the <a title="MSDN: Windows 7 Developer Guide" href="http://code.msdn.microsoft.com/Win7DeveloperGuide" target="_blank">Windows 7 Developer Guide</a>. It discusses many of the new features that will be available when this new version of Windows is released.</p>
<p>Of particular interest to me are the changes to DirectX 10, Media Foundation, and the new DirectX 11. Here are some highlights.</p>
<p>DirectX 11:</p>
<ul>
<li>&#8220;&#8230;resource creation and management has been optimized for multithreaded use, enabling more efficient dynamic texture management for streaming.&#8221;</li>
<li>Several improvements have been made to the high-level shading language (HLSL), such as a limited form of dynamic linkage in shaders to improve specialization complexity, and object-oriented programming constructs like classes and interfaces.&#8221;</li>
</ul>
<p>DirectX 10 improvements:</p>
<ul>
<li>&#8220;The pipeline also introduces the geometry shader stage, which offloads work entirely from the CPU to the GPU. This new stage enables you to create geometry, stream the data to memory, and render the geometry with no CPU interaction.&#8221;</li>
<li>Predicated rendering performs occlusion culling to reduce the amount of geometry that is rendered. Instancing APIs can dramatically reduce the amount of geometry that needs to be transferred to the GPU by drawing multiple-instances of similar objects. Texture arrays enable the GPU to do texture swapping without CPU intervention.&#8221;</li>
</ul>
<p>Media Foundation improvements:</p>
<ul>
<li>&#8220;&#8230;Media Foundation has been enhanced to provide better format support, including MPEG-4, as well as support for video capture devices and hardware codecs.&#8221;</li>
<li>&#8220;In Windows 7, Media Foundation provides extensive format support that includes codecs for H.264 video, MJPEG, and MP3; new sources for MP4, 3GP, MPEG2-TS, and AVI; and new file sinks for MP4, 3GP, and MP3.&#8221;</li>
<li>&#8220;In Windows Vista, Media Foundation exposed a relatively low-level set of APIs. These APIs are flexible, but may not be appropriate for performing tasks. Windows 7 adds new high-level APIs that make it simpler to write media applications in C++.&#8221;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2008/11/04/windows-7-development-guide/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows &#8220;Blue Screen of Death&#8221; at Olympic Opening Ceremony</title>
		<link>http://tdistler.com/2008/08/12/windows-blue-screen-of-death-at-olympic-opening-ceremony</link>
		<comments>http://tdistler.com/2008/08/12/windows-blue-screen-of-death-at-olympic-opening-ceremony#comments</comments>
		<pubDate>Tue, 12 Aug 2008 16:40:35 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Oh So Random]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=132</guid>
		<description><![CDATA[The Sydney Morning Herald has a great piece on a computer malfunction that showed up during the 2008 Olympic opening ceremony in Beijing. The dreaded &#8220;Blue Screen of Death&#8221; (BSOD), familiar to Windows XP users, was projected on the stadium ceiling when one of the display computers crashed. Here&#8217;s one of the images: It seems [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="Sydney Morning Herald: Software malfunction at the opening ceremony" href="http://www.smh.com.au/news/off-the-field/bills-blue-screen-of-death-malfunction/2008/08/12/1218306871673.html" target="_blank">Sydney Morning Herald has a great piece</a> on a computer malfunction that showed up during the 2008 Olympic opening ceremony in Beijing. The dreaded <a title="Wikipedia: Blue Screen of Death" href="http://en.wikipedia.org/wiki/Blue_Screen_of_Death" target="_blank">&#8220;Blue Screen of Death&#8221; (BSOD)</a>, familiar to Windows XP users, was projected on the stadium ceiling when one of the display computers crashed. Here&#8217;s one of the images:</p>
<p style="text-align: center;"><img style="vertical-align: middle;" src="/media/images/OlympicBSOD2008.jpg" alt="Blue Screen of Death at the 2008 Olympic Opening Ceremony" width="417" height="265" /></p>
<p style="text-align: left;">It seems that Lenovo (the PC supplier for the games) chose Windows XP instead fo Vista. From the article:</p>
<blockquote>
<p style="text-align: left;">Lenovo chairman, Yang Yuanqing, was quoted as saying that because of the  complexity of the IT functions at the Games, it was decided to not use the the  more recent operating system. &#8220;If it&#8217;s not stable, it could have some problems,&#8221;  he said.</p>
</blockquote>
<p style="text-align: left;">Ironically, former Microsoft CEO Bill Gates was in the crowd (he can run but he can&#8217;t hide). <img src='http://tdistler.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p style="text-align: left;"><a title="Gizmodo: Blue Screen of Death" href="http://gizmodo.com/5035456/blue-screen-of-death-strikes-birds-nest-during-opening-ceremonies-torch-lighting" target="_blank">Gizmodo</a> has some more images and links to the incident.</p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2008/08/12/windows-blue-screen-of-death-at-olympic-opening-ceremony/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft&#8217;s Midori OS</title>
		<link>http://tdistler.com/2008/07/30/microsofts-midori-os</link>
		<comments>http://tdistler.com/2008/07/30/microsofts-midori-os#comments</comments>
		<pubDate>Wed, 30 Jul 2008 16:49:33 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=128</guid>
		<description><![CDATA[The SDTimes has an article up about a new operating system Microsoft is working on called &#8220;Midori&#8221;. It is based on their &#8220;Singularity&#8221; OS, with everything being written in managed code then natively compiled.  Rumor has it that this is the follow-on to the Windows platform&#8230; we&#8217;ll see if it ever materializes commercially. SDTimes bases [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="float: right;" src="/media/images/MicrosoftLogo.jpg" alt="Microsoft" width="150" height="41" />The <a title="SDTimes" href="http://www.sdtimes.com" target="_blank">SDTimes</a> has an <a title="SDTimes: Microsoft's plans for post-Windows OS revealed" href="http://www.sdtimes.com/MICROSOFT_S_PLANS_FOR_POST_WINDOWS_OS_REVEALED/About_CLOUDCOMPUTING_and_MOBILEDEVELOPMENT_and_NET_and_SOASAAS_and_SOFTWAREDEVELOPMENT_and_WINDOWS_and_MICROSOFT/32627" target="_blank">article</a> up about a new operating system Microsoft is working on called &#8220;Midori&#8221;. It is based on their &#8220;<a title="Microsoft Research: Singularity" href="http://research.microsoft.com/os/Singularity/" target="_blank">Singularity</a>&#8221; OS, with everything being written in managed code then natively compiled.  Rumor has it that this is the follow-on to the Windows platform&#8230; we&#8217;ll see if it ever materializes commercially. SDTimes bases the article on some internal documents they got access to, which may be why we haven&#8217;t seen this level of detail before (<a title="Wikipedia: Midori Operating System" href="http://en.wikipedia.org/wiki/Midori_(operating_system)" target="_blank">see the entry in Wikipedia</a>). From the article:</p>
<blockquote><p>According to the documentation, Midori will be built with an asynchronous-only  architecture that is built for task concurrency and parallel use of local and  distributed resources, with a distributed component-based and data-driven  application model, and dynamic management of power and other resources.</p></blockquote>
<blockquote><p>The Midori documents foresee applications running across a multitude of  topologies, ranging from client-server and multi-tier deployments to  peer-to-peer at the edge, and in the cloud data center. Those topologies form a  heterogeneous mesh where capabilities can exist at separate places.</p>
<p>In  order to efficiently distribute applications across nodes, Midori will introduce  a higher-level application model that abstracts the details of physical machines  and processors. The model will be consistent for both the distributed and local  concurrency layers, and it is internally known as Asynchronous Promise  Architecture.</p></blockquote>
<blockquote><p>&#8230;operating system services, such as storage, would either be provided to the  applications by the OS or be discovered across a trusted distributed  environment.</p></blockquote>
<p><span id="more-128"></span>The programming model and API are also changing to help developers develop in the new model (goodbye Win32):</p>
<blockquote><p>The Midori documents indicate that the proposed OS would have a non-blocking  object-oriented framework API. This would have strong notions of immutability—in  the sense of objects that cannot be modified once created—and strive to foster  application correctness through deep verifiability by using .NET programming  languages.</p></blockquote>
<blockquote><p>The Midori programming model will tackle state management, which Microsoft  admits in its documentation is a challenge in Windows, by migrating APIs,  applications and developers to a constrained model.</p>
<p>Other objectives are  eliminating dynamic loading and in-process extensions; developing a failure  model based on reliable transactions, so the system understands exactly which  processes are impacted by a cascading failure and how to restart the  computation; and having a standard way of dealing with latency, asynchronous  behavior and cancellation, throughout the stack.</p></blockquote>
<p>To provide better modularity (and to support mobile devices), Midori will be a micro-kernel:</p>
<blockquote><p>Unlike Windows, Microsoft intends for Midori to be componentized from the  beginning to achieve performance and security benefits. It will have strong  isolation boundaries and enforced contracts between components, to ensure that  servicing one component will not cause others to fail, while keeping overhead  minimal.</p>
<p>At its lowest level, Midori has two separate kernel layers: a  microkernel comprised of unmanaged code that controls hardware and environment  abstracts, and higher-level managed kernel services that provide the full set of  operating system functionality.</p></blockquote>
<p>There are a lot more gems in the article&#8230; definitely worth a read. Click <a title="SDTimes: Microsoft's plans for post-Windows OS revealed" href="http://www.sdtimes.com/MICROSOFT_S_PLANS_FOR_POST_WINDOWS_OS_REVEALED/About_CLOUDCOMPUTING_and_MOBILEDEVELOPMENT_and_NET_and_SOASAAS_and_SOFTWAREDEVELOPMENT_and_WINDOWS_and_MICROSOFT/32627" target="_blank">HERE</a> to read it.</p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2008/07/30/microsofts-midori-os/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Display runs Windows</title>
		<link>http://tdistler.com/2007/10/15/iphone-display-runs-windows</link>
		<comments>http://tdistler.com/2007/10/15/iphone-display-runs-windows#comments</comments>
		<pubDate>Mon, 15 Oct 2007 15:22:50 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Oh So Random]]></category>
		<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=34</guid>
		<description><![CDATA[This is too good not to post: Picture source]]></description>
			<content:encoded><![CDATA[<p>This is too good not to post:</p>
<p align="center"><img title="iPhone display" src="/media/images/Windows-iPhone.jpg" alt="iPhone display" /></p>
<p><a title="Worst-Than-Failure" href="http://worsethanfailure.com/Articles/Taking-It-Outside-.aspx" target="_blank">Picture source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2007/10/15/iphone-display-runs-windows/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing DllMain in a linux shared library</title>
		<link>http://tdistler.com/2007/10/05/implementing-dllmain-in-a-linux-shared-library</link>
		<comments>http://tdistler.com/2007/10/05/implementing-dllmain-in-a-linux-shared-library#comments</comments>
		<pubDate>Fri, 05 Oct 2007 18:00:43 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Code Monkey]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=40</guid>
		<description><![CDATA[Overview When writing a shared library, it is sometimes useful to have a set of functions that get called when the library is loaded and unloaded. In Windows, this is done by implementing the DllMain function. This function is called by the loader whenever a DLL is loaded or unloaded into the address space of [...]]]></description>
			<content:encoded><![CDATA[<h2>Overview</h2>
<p>When writing a shared library, it is sometimes useful to have a set of functions that get called when the library is loaded and unloaded. In Windows, this is done by implementing the DllMain function. This function is called by the loader whenever a DLL is loaded or unloaded into the address space of a process (and also when the process creates a new thread, but it is less common to handle this case). A value is passed in as an argument to the DllMain function that indicates which event is occurring: DLL load or unload.</p>
<p>On Linux, one must use the GCC __attribute__((constructor)) and __attribute__((destructor)) keywords (double underscores before and after) to explicitly declare functions to be called on load and unload. These keywords cause the compiler/linker to add the specified functions to the __CTOR_LIST__ and __DTOR_LIST__ (&#8220;ConstrucTOR LIST&#8221; and &#8220;DestrucTOR LIST&#8221; respectively) in the object file. Functions on the __CTOR_LIST__ are called by the loader when the library is loaded (either implicitly or by <strong>dlopen()</strong>). The main purpose for this list is to call the constructors on global objects in the library. Conversely, functions on the __DTOR_LIST__ are called when the library is unloaded (either implicitly or by <strong>dlclose()</strong>). By adding initialization and clean-up functions to this list, one can effectively replicate the DllMain functionality on Linux.</p>
<p><strong><em>NOTE: There are many ways to &#8220;shoot yourself in the foot&#8221; with these methods (on both Windows and Linux) because certain things aren&#8217;t available to your library until loading is complete. Don&#8217;t use these methods unless you have a real need&#8230; just export an Initialize() and Destroy() function instead, and force the consuming application to call them. Please read the &#8220;Gotcha&#8217;s&#8221; section below.</em></strong></p>
<p><span id="more-40"></span></p>
<h3>External Resources:</h3>
<ul>
<li><span class="nobr"><a rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/ms682583.aspx" target="_blank">MSDN: DllMain</a></span></li>
<li><span class="nobr"><a rel="nofollow" href="http://www.dwheeler.com/program-library/Program-Library-HOWTO/miscellaneous.html" target="_blank">Misc. Linux Library Information</a></span></li>
<li><span class="nobr"><a rel="nofollow" href="http://linux4u.jinr.ru/usoft/WWW/www_debian.org/Documentation/elf/node11.html" target="_blank">Extended GCC Features</a></span></li>
<li><span class="nobr"><a rel="nofollow" href="http://www.securityfocus.com/infocus/1872" target="_blank">Dynamic Linking on Linux and Windows</a></span></li>
</ul>
<h2>Example: Linux</h2>
<div class="codeblock">
<p>void __attribute__ ((constructor)) my_load(void);<br />
void __attribute__ ((destructor))  my_unload(void);</p>
<p>// Called when the library is loaded and before dlopen() returns<br />
void my_load(void)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;// Add initialization code&#8230;<br />
}</p>
<p>// Called when the library is unloaded and before dlclose()<br />
// returns<br />
void my_unload(void)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;// Add clean-up code&#8230;<br />
}</p>
</div>
<h2>Example: Windows</h2>
<div class="codeblock">
<p>// Return TRUE on success and FALSE if an error occurs. Returning<br />
// FALSE will cause the library to be unloaded.<br />
BOOL WINAPI DllMain<br />
(<br />
&nbsp;&nbsp;&nbsp;&nbsp;HINSTANCE hinstDLL,<br />
&nbsp;&nbsp;&nbsp;&nbsp;DWORD     fdwReason,<br />
&nbsp;&nbsp;&nbsp;&nbsp;LPVOID    lpReserved<br />
)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch (fdwReason)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case DLL_PROCESS_ATTACH:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add initialization code&#8230;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case DLL_PROCESS_DETACH:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add clean-up code&#8230;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;return (TRUE);<br />
}
</p></div>
<h2>Gotcha&#8217;s</h2>
<h3>Linux</h3>
<p><span class="nobr"><a rel="nofollow" href="http://www.dwheeler.com/program-library/Program-Library-HOWTO/miscellaneous.html" target="_blank">From www.dwheeler.com</a></span>:</p>
<blockquote><p>Shared libraries must not be compiled with the gcc arguments &#8220;-nostartfiles&#8221; or &#8220;-nostdlib&#8221;. If those arguments are used, the constructor/destructor routines will not be executed (unless special measures are taken).</p></blockquote>
<h3>Windows</h3>
<p><span class="nobr"><a rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/ms682583.aspx" target="_blank">From Microsoft&#8217;s MSDN page on DllMain</a></span>:</p>
<blockquote><p>The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code.</p>
<p>Because Kernel32.dll is guaranteed to be loaded in the process address space when the entry-point function is called, calling functions in Kernel32.dll does not result in the DLL being used before its initialization code has been executed. Therefore, the entry-point function can call functions in Kernel32.dll that do not load other DLLs. For example, DllMain can create synchronization objects such as critical sections and mutexes, and use TLS. Unfortunately, there is not a comprehensive list of safe functions in Kernel32.dll.</p>
<p>Windows 2000: Do not create a named synchronization object in DllMain because the system will then load an additional DLL. This restriction does not apply to subsequent versions of Windows.</p>
<p>Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components. Conversely, calling functions such as these during termination can cause access violation errors because the corresponding component may already have been unloaded or uninitialized.</p>
<p>Because DLL notifications are serialized, entry-point functions should not attempt to communicate with other threads or processes. Deadlocks may occur as a result.</p>
<p>For information on best practices when writing a DLL, see <span class="nobr"><a rel="nofollow" href="http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx" target="_blank">http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx</a></span>.</p>
<p><span class="nobr">If your DLL is linked with the C run-time library (CRT), the entry point provided by the CRT calls the constructors and destructors for global and static C++ objects. Therefore, these restrictions for DllMain also apply to constructors and destructors and any code that is called from them.</span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2007/10/05/implementing-dllmain-in-a-linux-shared-library/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inside Windows Vista User Account Control (UAC)</title>
		<link>http://tdistler.com/2007/05/31/inside-windows-vista-user-account-control-uac</link>
		<comments>http://tdistler.com/2007/05/31/inside-windows-vista-user-account-control-uac#comments</comments>
		<pubDate>Thu, 31 May 2007 15:26:54 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=64</guid>
		<description><![CDATA[Inside Windows Vista User Account Control (TechNet)]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.microsoft.com/technet/technetmag/issues/2007/06/UAC/?rss=http://www.microsoft.com/technet/technetmag/issues/2007/06/UAC" target="_blank">Inside Windows Vista User Account Control (TechNet)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2007/05/31/inside-windows-vista-user-account-control-uac/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inside the Windows Vista Kernel</title>
		<link>http://tdistler.com/2007/03/22/inside-the-windows-vista-kernel</link>
		<comments>http://tdistler.com/2007/03/22/inside-the-windows-vista-kernel#comments</comments>
		<pubDate>Thu, 22 Mar 2007 15:00:43 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=74</guid>
		<description><![CDATA[Here are some links to 3 great articles by Mark Russinovich about new features in the Windows Vista kernel (Ntoskrnl.exe). Inside the Windows Vista Kernel: Part 1 Inside the Windows Vista Kernel: Part 2 Inside the Windows Vista Kernel: Part 3]]></description>
			<content:encoded><![CDATA[<p>Here are some links to 3 great articles by Mark Russinovich about new features in the Windows Vista kernel (Ntoskrnl.exe).</p>
<p><a title="Microsoft Technet - Inside the Windows Vista Kernel: Part 1" href="http://www.microsoft.com/technet/technetmag/issues/2007/02/VistaKernel" target="_blank">Inside the Windows Vista Kernel: Part 1</a></p>
<p><a title="Microsoft Technet - Inside the Windows Vista Kernel: Part 2" href="http://www.microsoft.com/technet/technetmag/issues/2007/03/VistaKernel" target="_blank">Inside the Windows Vista Kernel: Part 2</a></p>
<p><a title="Microsoft Technet - Inside the Windows Vista Kernel: Part 3" href="http://www.microsoft.com/technet/technetmag/issues/2007/04/VistaKernel" target="_blank">Inside the Windows Vista Kernel: Part 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2007/03/22/inside-the-windows-vista-kernel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Vista and the NSA</title>
		<link>http://tdistler.com/2007/01/09/windows-vista-and-the-nsa</link>
		<comments>http://tdistler.com/2007/01/09/windows-vista-and-the-nsa#comments</comments>
		<pubDate>Tue, 09 Jan 2007 19:00:07 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Tech and Security]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tdistler.com/?p=80</guid>
		<description><![CDATA[The Washington Post is reporting about how Microsoft enlisted the National Security Agency&#8217;s help in securing the next version of Windows. Sounds good, huh? Looks like Microsoft is doing everything is can to secure Vista. The NSA is the best-of-best when it comes to this stuff, so who better to turn to, right? Well, there&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="Read the article" href="http://www.washingtonpost.com/wp-dyn/content/article/2007/01/08/AR2007010801352.html" target="_blank">Washington Post</a> is reporting about how Microsoft enlisted the National Security Agency&#8217;s help in securing the next version of Windows. Sounds good, huh? Looks like Microsoft is doing everything is can to secure Vista. The NSA is the best-of-best when it comes to this stuff, so who better to turn to, right?</p>
<p>Well, there&#8217;s a subtle reason why this is <em>not </em>good, and I believe Bruce Schneier offers a good <a title="Read Bruce's full comments" href="http://www.schneier.com/blog/archives/2007/01/nsa_helps_micro_1.html" target="_blank">summary</a> as to why this is:</p>
<p style="margin-left: 40px"><span style="font-style: italic">It&#8217;s called the &#8220;equities issue.&#8221; Basically, the NSA has two roles: eavesdrop on their stuff, and protect our stuff. When both sides use the same stuff &#8212; Windows Vista, for example &#8212; the agency has to decide whether to exploit vulnerabilities to eavesdrop on their stuff or close the same vulnerabilities to protect our stuff. In its partnership with Microsoft, it could have decided to go either way: to deliberately introduce vulnerabilities that it could exploit, or deliberately harden the OS to protect its own interests.</span></p>
<p>So, which choice did they make? We&#8217;ll probably never know, but given the current administration&#8217;s feeling about privacy and warrentless eavesdropping, this whole thing doesn&#8217;t make me feel any better about Vista security.</p>
<p>The real irony of the whole thing is that this could make Vista seem more secure, when actually the opposite is true.  There&#8217;s an old saying in the security field: &#8220;No security is better than poor security.&#8221; When there&#8217;s no security, at least people are cautious with their data. With the &#8220;illusion&#8221; of security, people tend to act as if they are truly secure.</p>
<p>As a side note, this is an example of why security is so hard to get right. In many ways, true security is counter-intuitive&#8230; that&#8217;s part of what makes this field so interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://tdistler.com/2007/01/09/windows-vista-and-the-nsa/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

