<?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>Fooling Around &#187; visual studio</title>
	<atom:link href="http://alax.info/blog/tag/visual-studio/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>// Software Production Line</description>
	<lastBuildDate>Wed, 02 May 2012 15:42:49 +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>ATLENSURE_SUCCEEDED double failure</title>
		<link>http://alax.info/blog/1244</link>
		<comments>http://alax.info/blog/1244#comments</comments>
		<pubDate>Tue, 19 Jul 2011 17:18:13 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[inline]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1244</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1244" title="ATLENSURE_SUCCEEDED double failure"></a>A colleague pointed out that code snippet in previous post is misusing ATL&#8217;s ATLENSURE_SUCCEEDED macro making it [possibly] evaluate its argument twice in case of failure, that is evaluating into failure HRESULT code. As it is defined like this: #define &#8230;<p class="read-more"><a href="http://alax.info/blog/1244">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1244" title="ATLENSURE_SUCCEEDED double failure"></a><p>A colleague pointed out that code snippet in <a href="http://alax.info/blog/1241">previous post</a> is misusing ATL&#8217;s ATLENSURE_SUCCEEDED macro making it [possibly] evaluate its argument twice in case of failure, that is evaluating into failure HRESULT code. As it is defined like this:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">define</span><span style="color: #004a43;"> ATLENSURE_SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">hr</span><span style="color: #808030;">)</span><span style="color: #004a43;"> ATLENSURE_THROW</span><span style="color: #808030;">(</span><span style="color: #004a43;">SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">hr</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #004a43;"> hr</span><span style="color: #808030;">)</span></pre>
<p>It does things in a straightforward way, for a code line</p>
<pre style="color: #000000; background: #ffffff;">ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pFilterGraph<span style="color: #808030;">.</span>CoCreateInstance<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>It is doing &#8220;let&#8217;s CoCreateInstance the thing and if it fails, let&#8217;s CoCreateInstance it again to find out error code&#8221;. Disassembly shows this clearly:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/07/Image0031.png"><img class="alignnone size-full wp-image-1245" title="ATLENSURE_SUCCEEDED evaluates the argument twice" src="http://alax.info/blog/wp-content/uploads/2011/07/Image0031.png" alt="" width="640" height="458" /></a></p>
<p>This is exactly another spin of the story previously happened with <a href="http://msdn.microsoft.com/en-us/library/ms680746%28VS.85%29.aspx">HRESULT_FROM_WIN32</a> macro and possibly a number of others. With it being originally a macro, SDK offered an option to override the definition by pre-defining INLINE_HRESULT_FROM_WIN32. This way a user might be explicitly requesting a safer definition while still leaving legacy code live with macro. See <a href="http://blogs.msdn.com/b/matthew_van_eerde/archive/2007/12/28/the-evolution-of-hresult-from-win32.aspx">more detailed story on this in Matthew&#8217;s blog</a>.</p>
<p>A tricky thing is that with successful execution the problem does not come up. In case of failure, it depends on the functions called, some with just repeat the error code, some will return a different code on second run, some might create less desired and expected consequences. So you can find yourself having written quite some code before you even suspect a problem.</p>
<p>Having identified the issue, there are a few solutions.</p>
<p>1. First of all, the original ATLENSURE_SUCCEEDED macro can still be used, provided that you don&#8217;t put expressions as arguments.</p>
<p>This is going to do just fine:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">const</span> HRESULT nCoCreateInstanceResult <span style="color: #808030;">=</span> pFilterGraph<span style="color: #808030;">.</span>CoCreateInstance<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nCoCreateInstanceResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>2. Second straightforward way is to replace the original ATL definition in ATL code (boo, woodenly)</p>
<p>3. As ATL code is checking for the macros to be already defined, and skipping its own definition in such case, it is possible to inject a safer private definition before including ATL headers (which would typically need one to do the define in stdafx.h):</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">define</span><span style="color: #004a43;"> ATLENSURE_SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">x</span><span style="color: #808030;">)</span><span style="color: #808030;">{</span><span style="color: #004a43;"> const HRESULT nResult </span><span style="color: #808030;">=</span><span style="color: #808030;">(</span><span style="color: #004a43;">x</span><span style="color: #808030;">)</span><span style="color: #808030;">;</span><span style="color: #004a43;"> ATLENSURE_THROW</span><span style="color: #808030;">(</span><span style="color: #004a43;">SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">nResult</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #004a43;"> nResult</span><span style="color: #808030;">)</span><span style="color: #808030;">; </span><span style="color: #808030;">}</span>

<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">atlbase.h</span><span style="color: #800000;">&gt;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">atlstr.h</span><span style="color: #800000;">&gt;</span></pre>
<p>Pre-evaluating the argument into local variable is going to resolve the original multi-evaluation problem.</p>
<p>4. There might be a new inline function defined on top of the original macro, which will be used instead and which is free from the problem:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">inline</span> <span style="color: #603000;">VOID</span> ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>HRESULT nResult<span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span></pre>
<p>Either way, the correct code compiles into single argument evaluation and throws an exception with failure code immediately:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/07/Image0041.png"><img class="alignnone size-full wp-image-1246" title="Corrected ATLENSURE_SUCCEEDED code" src="http://alax.info/blog/wp-content/uploads/2011/07/Image0041.png" alt="" width="640" height="333" /></a></p>
<p>Also, <del datetime="2011-07-20T05:21:51+00:00"><a href="https://connect.microsoft.com/VisualStudio/feedback/details/679899/atlensure-succeeded-macro-is-unsafe-for-use-with-evaluatable-arguments#details">vote for the suggestion on Microsoft Connect</a></del>. The issue is marked as fixed in future version of Visual Studio.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1244/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your ATL service C++ project might need some extra care after upgrade to Visual Studio 2010</title>
		<link>http://alax.info/blog/1198</link>
		<comments>http://alax.info/blog/1198#comments</comments>
		<pubDate>Wed, 11 May 2011 21:55:59 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[epic]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1198</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1198" title="Your ATL service C++ project might need some extra care after upgrade to Visual Studio 2010"></a>If you dare to convert your C++ ATL Service project created with an earlier version of Visual Studio to version 2010, as I recently did, you might find yourself surprised with why the hell the bloody thing does not work &#8230;<p class="read-more"><a href="http://alax.info/blog/1198">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1198" title="Your ATL service C++ project might need some extra care after upgrade to Visual Studio 2010"></a><p>If you dare to convert your C++ ATL Service project created with an earlier version of Visual Studio to version 2010, as I recently did, you might find yourself surprised with why the hell the bloody thing does not work anymore as a regular executable.</p>
<p>After passing compiler/linker and SDK update issues, which you possibly might have too, the started executable will stumble on ATL error/exception with CO_E_NOTINITIALIZED (0x800401F0 &#8220;CoInitialize has not been called.&#8221;). Luckily the error code is good enough for quickly locating the problem and the reason is that the one you trusted, that is ATL, introduced an small improvement which is good for running as service but it not initializing COM anymore if you run your .EXE in application mode.</p>
<p><a href="http://connect.microsoft.com/VisualStudio/feedback/details/582774/catlservicemodulet-winmain-coinitialize-not-called-800401f0">The bug is on MS Connect</a> since August 3, 2010 closed as if it is going to be fixed some time in future when the fix is propagated to end developers. If you are in a rush and would like to write some code before the event, here are the details.</p>
<p>Previously, COM was initialized right in module constructor, in CAtlExeModuleT. CAtlServiceModuleT class just inherited from there. Later on, someone smart decided that it was not so cool and moved initialization to a later point into CAtlExeModuleT::WinMain. Well, this makes sense as you might (a) end up not needing COM at all, or (b) you want to do some important things before even initializing COM.</p>
<p>Unfortunately, the fact that CAtlServiceModuleT is inherited and relies on base class was not paid too much attention. CAtlServiceModuleT is not getting COM initialization from constructor any longer, CAtlServiceModuleT::WinMain is overridden in full and does not receive initialization from new location either. So well, it does not receive it at all unless run as service, which code execution branch looks still heatlhy here and exhibits another issue later soon.</p>
<p>To resolve the problem, the fragment in CAtlServiceModuleT::Start needs the correction as shown below (within #pragma region):</p>
<pre style="color: #000000; background: #ffffff;">        <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span><span style="color: #800080;">::</span><span style="color: #400000;">StartServiceCtrlDispatcher</span><span style="color: #808030;">(</span>st<span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span>
                m_status<span style="color: #808030;">.</span>dwWin32ExitCode <span style="color: #808030;">=</span> <span style="color: #400000;">GetLastError</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            <span style="color: #800000; font-weight: bold;">return</span> m_status<span style="color: #808030;">.</span>dwWin32ExitCode<span style="color: #800080;">;</span>
        <span style="color: #800080;">}</span>

        <span style="color: #696969;">// local server - call Run() directly, rather than</span>
        <span style="color: #696969;">// from ServiceMain()</span>
<span style="color: #004a43;">        #</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">region Run wrapped by InitializeCom/UninitializeCom</span>
        <span style="color: #696969;">// </span><span style="color: #ffffff; background: #808000;">FIX: See http://connect.microsoft.com/VisualStudio/feedback/details/582774/catlservicemodulet-winmain-coinitialize-not-called-800401f0</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">ifndef</span><span style="color: #004a43;"> _ATL_NO_COM_SUPPORT</span>
        HRESULT hr <span style="color: #808030;">=</span> E_FAIL<span style="color: #800080;">;</span>
        hr <span style="color: #808030;">=</span> T<span style="color: #800080;">::</span>InitializeCom<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span>FAILED<span style="color: #808030;">(</span>hr<span style="color: #808030;">)</span><span style="color: #808030;">)</span>
        <span style="color: #800080;">{</span>
            <span style="color: #696969;">// Ignore RPC_E_CHANGED_MODE if CLR is loaded. Error is due to CLR initializing</span>
            <span style="color: #696969;">// COM and InitializeCOM trying to initialize COM with different flags.</span>
            <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span>hr <span style="color: #808030;">!</span><span style="color: #808030;">=</span> RPC_E_CHANGED_MODE <span style="color: #808030;">|</span><span style="color: #808030;">|</span> <span style="color: #400000;">GetModuleHandle</span><span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Mscoree.dll</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">)</span>
                <span style="color: #800000; font-weight: bold;">return</span> hr<span style="color: #800080;">;</span>
        <span style="color: #800080;">}</span> <span style="color: #800000; font-weight: bold;">else</span>
            m_bComInitialized <span style="color: #808030;">=</span> <span style="color: #800000; font-weight: bold;">true</span><span style="color: #800080;">;</span>
        m_status<span style="color: #808030;">.</span>dwWin32ExitCode <span style="color: #808030;">=</span> pT<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Run<span style="color: #808030;">(</span>nShowCmd<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span>m_bComInitialized<span style="color: #808030;">)</span>
            T<span style="color: #800080;">::</span>UninitializeCom<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">else</span>
        m_status<span style="color: #808030;">.</span>dwWin32ExitCode <span style="color: #808030;">=</span> pT<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Run<span style="color: #808030;">(</span>nShowCmd<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">endif</span>
<span style="color: #004a43;">        #</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">endregion </span>

        <span style="color: #800000; font-weight: bold;">return</span> m_status<span style="color: #808030;">.</span>dwWin32ExitCode<span style="color: #800080;">;</span>
    <span style="color: #800080;">}</span></pre>
<p>Going further from there, the introduced optimization also removed COM initialization from main process thread module Run function. Provided there earlier too through module constructor it is not longer there. So if you are doing something in application&#8217;s run when the application is set to run as service and is executed in application (where you might want to start application as a sort of a helper, or otherwise in specific mode), you need COM initialization there too.</p>
<p><span id="more-1198"></span>It might be something like this:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">class</span> CFooModule <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CAtlServiceModuleT<span style="color: #800080;">&lt;</span>CFooModule<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #696969;">// [...]</span>
    HRESULT Run<span style="color: #808030;">(</span><span style="color: #603000;">INT</span> nShowCommand <span style="color: #808030;">=</span> SW_HIDE<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
<span style="color: #696969;">// [...]</span>
            <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>m_bServiceHelper<span style="color: #808030;">)</span>
            <span style="color: #800080;">{</span>
                <span style="color: #696969;">// NOTE: Starting with Visual Studio 2010 service helper's Run receives no automatic COM initialization any longer</span>
                nResult <span style="color: #808030;">=</span> InitializeCom<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
                <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>SUCCEEDED<span style="color: #808030;">(</span>nResult<span style="color: #808030;">)</span><span style="color: #808030;">)</span>
                <span style="color: #800080;">{</span>
                    nResult <span style="color: #808030;">=</span> __super<span style="color: #800080;">::</span>Run<span style="color: #808030;">(</span>nShowCommand<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
                    UninitializeCom<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
                <span style="color: #800080;">}</span>
            <span style="color: #800080;">}</span> <span style="color: #800000; font-weight: bold;">else</span>
                nResult <span style="color: #808030;">=</span> __super<span style="color: #800080;">::</span>Run<span style="color: #808030;">(</span>nShowCommand<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// [...]</span>
    <span style="color: #800080;">}</span>
<span style="color: #696969;">// [...]</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span></pre>
<p>Having done that we are really closer but there is still another breaking bug in ATL caused by Visual Studio 2010 changes. You start a service and its endlessly shown as being started.</p>
<p>It appears that ATL is failing to call <a href="http://msdn.microsoft.com/en-us/library/ms686241%28VS.85%29.aspx">SetServiceStatus</a>(SERVICE_RUNNING) to indicated startup completion and service healthy state. Again, the bug is related to change in base class behavior. This time, the problem is caused by the fact that SetServiceStatus call was moved from CAtlServiceModuleT::Run into CAtlServiceModuleT::PreMessageLoop. However, it was moved into the section conditionally compiled with definition of _ATL_FREE_THREADED. If you are and old school guy with _ATL_APARTMENT_THREADED instead and is just converting and older project that worked before, you have a problem here again: you have to add missing call.</p>
<p>To fix this, the end of CAtlServiceModuleT::PreMessageLoop should be looking like this:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">else</span>
        hr <span style="color: #808030;">=</span> CAtlExeModuleT<span style="color: #800080;">&lt;</span>T<span style="color: #800080;">&gt;</span><span style="color: #800080;">::</span>PreMessageLoop<span style="color: #808030;">(</span>nShowCmd<span style="color: #808030;">)</span><span style="color: #800080;">;</span>

<span style="color: #004a43;">        #</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">region Missing SetServiceStatus</span>
        <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span>m_bService<span style="color: #808030;">)</span>
        <span style="color: #800080;">{</span>
            LogEvent<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Service started/resumed</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            <span style="color: #400000;">SetServiceStatus</span><span style="color: #808030;">(</span>SERVICE_RUNNING<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="color: #800080;">}</span>
<span style="color: #004a43;">        #</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">endregion </span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">endif</span><span style="color: #004a43;"> </span><span style="color: #696969;">// _ATL_FREE_THREADED</span>

<span style="color: #004a43;">#</span><span style="color: #004a43;">endif</span><span style="color: #004a43;">    </span><span style="color: #696969;">// _ATL_NO_COM_SUPPORT</span>

        ATLASSERT<span style="color: #808030;">(</span>SUCCEEDED<span style="color: #808030;">(</span>hr<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="color: #800000; font-weight: bold;">return</span> hr<span style="color: #800080;">;</span></pre>
<p>Well, this is embarrassing.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1198/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build Incrementer Add-In for Visual Studio: Latest Visual Studio Versions</title>
		<link>http://alax.info/blog/1170</link>
		<comments>http://alax.info/blog/1170#comments</comments>
		<pubDate>Sat, 05 Mar 2011 13:08:38 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[add-in]]></category>
		<category><![CDATA[ATL]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1170</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1170" title="Build Incrementer Add-In for Visual Studio: Latest Visual Studio Versions"></a>If you share concept (as I do) that every build should have a unique file version stamp in it, for a simple purpose – at least – to distinguish between different version of the same binary, then a helpful tool &#8230;<p class="read-more"><a href="http://alax.info/blog/1170">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1170" title="Build Incrementer Add-In for Visual Studio: Latest Visual Studio Versions"></a><p>If you share concept (as I do) that every build should have a unique file version stamp in it, for a simple purpose – at least – to distinguish between different version of the same binary, then a helpful tool of automatic incrementing fourth number in FILEVERSION&#8217;s file version is something you cannot live without. After going through several fixes and updates, it is finally here available for download.</p>
<p>The last issue was in particular that projects that are in solution&#8217;s folder are not found by the add-in with <a href="http://www.microsoft.com/visualstudio/en-us/">Visual Studio</a> 2008. Why? <a href="http://msdn.microsoft.com/en-us/library/aa301986.aspx">OnBuildProjConfigBegin</a> event provides you with a unique project name string in Project argument, but it appears that it is only good enough as a quick lookup argument with Visual Studio 2010.</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #696969;">// EnvDTE::_dispBuildEvents</span>
    STDMETHOD<span style="color: #808030;">(</span>OnBuildBegin<span style="color: #808030;">)</span><span style="color: #808030;">(</span>_EnvDTE_vsBuildScope Scope<span style="color: #808030;">,</span> _EnvDTE_vsBuildAction Action<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    STDMETHOD<span style="color: #808030;">(</span>OnBuildDone<span style="color: #808030;">)</span><span style="color: #808030;">(</span>_EnvDTE_vsBuildScope Scope<span style="color: #808030;">,</span> _EnvDTE_vsBuildAction Action<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    STDMETHOD<span style="color: #808030;">(</span>OnBuildProjConfigBegin<span style="color: #808030;">)</span><span style="color: #808030;">(</span>BSTR <strong><span style="text-decoration: underline;">Project</span></strong><span style="color: #808030;">,</span> BSTR ProjectConfig<span style="color: #808030;">,</span> BSTR Platform<span style="color: #808030;">,</span> BSTR SolutionConfig<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        _Z4<span style="color: #808030;">(</span>atlTraceCOM<span style="color: #808030;">,</span> <span style="color: #008c00;">4</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Project </span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\"</span><span style="color: #0000e6;">, ProjectConfig </span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\"</span><span style="color: #0000e6;">, Platform </span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\"</span><span style="color: #0000e6;">, SolutionConfig </span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>Project<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>ProjectConfig<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>Platform<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>SolutionConfig<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        _ATLTRY
        <span style="color: #800080;">{</span>
            <span style="color: #696969;">// NOTE: const CString&amp; cast forces compiler to process statement as variable definition rather than function forward declaration</span>
            CProjectConfiguration ProjectConfiguration<span style="color: #808030;">(</span><span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">CString</span><span style="color: #808030;">&amp;</span><span style="color: #808030;">)</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>Project<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>ProjectConfig<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>Platform<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>SolutionConfig<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            CRoCriticalSectionLock DataLock<span style="color: #808030;">(</span>m_DataCriticalSection<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            <span style="color: #696969;">// NOTE: Check the project on the first run only (to skip multiple increments in batch build mode)</span>
            <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span><span style="color: #808030;">!</span>Project <span style="color: #808030;">|</span><span style="color: #808030;">|</span> m_VersionMap<span style="color: #808030;">.</span>Lookup<span style="color: #808030;">(</span>ProjectConfiguration<span style="color: #808030;">)</span><span style="color: #808030;">)</span>
                <span style="color: #800000; font-weight: bold;">return</span> S_FALSE<span style="color: #800080;">;</span>
            _Z3<span style="color: #808030;">(</span>atlTraceGeneral<span style="color: #808030;">,</span> <span style="color: #008c00;">3</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Checking project </span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\"</span><span style="color: #0000e6;">...</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>Project<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            <span style="color: #696969;">// Checking the project is of C++ kind</span>
            CComPtr<span style="color: #800080;">&lt;</span>EnvDTE<span style="color: #800080;">::</span>Project<span style="color: #800080;">&gt;</span> pProject <span style="color: #808030;">=</span> GetProject<span style="color: #808030;">(</span>CComVariant<span style="color: #808030;">(</span><strong><span style="text-decoration: underline;">Project</span></strong><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            _A<span style="color: #808030;">(</span>pProject<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            <span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span></pre>
<p>When the project is in a folder, <a href="http://msdn.microsoft.com/en-us/library/aa301425.aspx">Projects::Item</a> can just fail if you are looking up for the element interface. In which case, you have to walk the collection taking into account <a href="http://msdn.microsoft.com/en-us/library/aa301157.aspx">SubProjects</a> and additionally look there yourself. Visual Studio 2010 is one step smarter and gives the thing to you right from the start.</p>
<p>Eventually, the add-in is here. It&#8217;s job is to go to .RC file and increment file version each time you build the binary. It reports the action into build output window:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/03/Image001.png"><img class="size-large wp-image-1172 alignnone" title="Build Incrementer Report in Visual Studio Build Output" src="http://alax.info/blog/wp-content/uploads/2011/03/Image001-800x213.png" alt="" width="640" height="170" /></a></p>
<p>To install the add-in:</p>
<ul>
<li>download and register (regsvr32, administrator) the <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/VisualStudioBuildIncrementerAddIn/_Bin/Release/VisualStudioBuildIncrementerAddIn.dll?format=raw">VisualStudioBuildIncrementerAddIn.dll</a></li>
<li>apply one or more Visual Studio integration registry files:
<ul>
<li><a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/VisualStudioBuildIncrementerAddIn/Visual Studio 2008 Registration.reg?format=raw">Visual Studio 2008 Registration.reg</a></li>
<li><a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/VisualStudioBuildIncrementerAddIn/Visual Studio 2010 Registration.reg?format=raw">Visual Studio 2010 Registration.reg</a></li>
</ul>
</li>
</ul>
<p>Or, alternatively, use installation file <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/VisualStudioBuildIncrementerAddIn/_Bin/Release/VisualStudioBuildIncrementerAddInSetup.msi?format=raw">VisualStudioBuildIncrementerAddInSetup.msi (version 1.0.4, 379K)</a> to have it done for you in a user-friendly way. Partial <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/VisualStudioBuildIncrementerAddIn">source code</a>, a Visual Studio 2010 projectis also there in repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1170/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Attributed ATL: Accessing BLOB with ISequentialStream</title>
		<link>http://alax.info/blog/1136</link>
		<comments>http://alax.info/blog/1136#comments</comments>
		<pubDate>Sat, 10 Jul 2010 10:23:22 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1136</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1136" title="Attributed ATL: Accessing BLOB with ISequentialStream"></a>Before attributed ATL was deprecated, it was a convenient way to access databases using attributed classes on top of OLEDB Consumer Templates. Does not it look nice? [ db_command("SELECT ServerData FROM Server WHERE Server = ?") ] class CGetServerData { &#8230;<p class="read-more"><a href="http://alax.info/blog/1136">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1136" title="Attributed ATL: Accessing BLOB with ISequentialStream"></a><p>Before <a href="http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/a74bcacf-e1e3-44c7-994d-3ebb8fe37973">attributed ATL was deprecated</a>, it was a convenient way to access databases using attributed classes on top of <a href="http://msdn.microsoft.com/en-us/library/fk4h509a.aspx">OLEDB Consumer Templates</a>. Does not it look nice?</p>
<pre style="color: #000000; background: none repeat scroll 0% 0% #ffffff;"><span style="color: #808030;">[</span>
    db_command<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">SELECT ServerData FROM Server WHERE Server = ?</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span>
<span style="color: #808030;">]</span>
<span style="color: #800000; font-weight: bold;">class</span> CGetServerData
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
    <span style="color: #808030;">[</span> db_param<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">)</span> <span style="color: #808030;">]</span> <span style="color: #603000;">LONG</span> m_nServer<span style="color: #800080;">;</span>
    <span style="color: #808030;">[</span> db_column<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span> length <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">m_nDataLength</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span> <span style="color: #808030;">]</span> ISequentialStream<span style="color: #808030;">*</span> m_pDataStream<span style="color: #800080;">;</span> DBLENGTH m_nDataLength<span style="color: #800080;">;</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span></pre>
<p>It worked great with Visual Studio .NET 2003 and it failed to work with later releases. There are <a href="http://www.google.com/search?q=db_column+ISequentialStream">questions on internet about the problem</a>, but there few answers if any. As I recently had to convert a project from 2003 version of the compiler to Visual Studio 2008, the problem was finally to be resolved.</p>
<p><span id="more-1136"></span>The first problem, and an easier one was that you have to put attribute values in quotes. &#8216;Db_column(1, &#8230;&#8217; has to be &#8220;db_column(&#8220;1&#8243;, &#8230;&#8217; and besides going through code and making changes, it appeared that if earlier implementation managed to distinguish between ordinal column numbers and field names by checking provided argument to be a number or a string, with Visual Studio 2008 one has to provide strings at any time. If the string is a valid integer, the attribute processor will treat it as an ordinal number.</p>
<p>So if you want your code to be both compiled with 2003 and 2008 versions of Visual Studio, you have a puzzle now: you have to use quotes, but version 2003 will no longer treat the argument as ordinal number. Note that version 2003 will keep compiling the code and the problem will only come up on runtime. As eventually in the project of interest support for version 2003 will be dropped, I was not interested in this problem anymore.</p>
<p>The main problem is related to use of ISequentialStream pointer variable as a data field. Again, it worked great with Visual Studio .NET 2003, it no longer did with Visual Studio .NET 2005. First of all, you cannot use this data type anymore, as templates don&#8217;t provide an automatic mapper to OLE DB Type.� Instead of ISequentialStream you have to use IUnknown and QueryInterface the provided pointer before use.</p>
<p>This solves compilation problem, but still the code does not work on runtime. An attempt to bind to the column using such accessor results in DB_E_ERRORSOCCURRED (0x80040E21) &#8220;Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.&#8221; A more thorough look gave DBBINDSTATUS_BADBINDINFO (3) for binding to the column of interest.</p>
<p>The cause of the problem is missing DBOBJECT object pointer in the corresponding DBBINDING::pObject field. Why? A general rule for troubleshooting this kind of problem is to enable expanding attributed source code to check what exactly is generated.</p>
<p>The problem is that unlike previous versions of Visual Studio, ATL attributed code provider is no longer generates correct OLEDB template map code for BLOB fields. And this results in incorrectly generated DBBINDING structure, inability to bind to column and as a final result in DB_E_ERRORSOCCURRED error code which does not give a sufficient clue on the root of the problem.</p>
<p>While the map needs a BLOB_* macro for the BLOB column (e.g. BLOB_ENTRY or <a href="http://msdn.microsoft.com/en-us/library/w3k8764c.aspx">BLOB_ENTRY_LENGTH</a>), the generated code uses _COLUMN_ENTRY_CODE instead. This causes missing (null) DBBINDING::pObject field in the binding structure:</p>
<pre style="color: #000000; background: none repeat scroll 0% 0% #ffffff;">BEGIN_ACCESSOR_MAP<span style="color: #808030;">(</span>_CGetServerDataAccessor<span style="color: #808030;">,</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span>
    BEGIN_ACCESSOR<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">true</span><span style="color: #808030;">)</span>
        <span style="color: #696969;">//_COLUMN_ENTRY_CODE(1, DBTYPE_IUNKNOWN, _SIZE_TYPE(m_pDataUnknown), 0, 0, offsetbuf(m_pDataUnknown), offsetbuf(m_nDataLength), 0)</span>
        BLOB_ENTRY_LENGTH<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>ISequentialStream<span style="color: #808030;">)</span><span style="color: #808030;">,</span> STGM_READ<span style="color: #808030;">,</span> m_pDataUnknown<span style="color: #808030;">,</span> m_nDataLength<span style="color: #808030;">)</span>
    END_ACCESSOR<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
END_ACCESSOR_MAP<span style="color: #808030;">(</span><span style="color: #808030;">)</span></pre>
<p>So it appears that to fix the problem, an attributed class needs to be replaced with a non-attributed update. To ease the conversion one can expand attributed source and use it as a base for the non-attributed class.</p>
<p>And example of such correction/replacement is provided below for a reference.</p>
<pre style="color: #000000; background: none repeat scroll 0% 0% #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">if</span><span style="color: #004a43;"> TRUE</span>
<span style="color: #800000; font-weight: bold;">class</span> _CGetServerDataAccessor
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>

DEFINE_COMMAND_EX<span style="color: #808030;">(</span>_CGetServerDataAccessor<span style="color: #808030;">,</span> <span style="color: #800000;">L"</span><span style="color: #0000e6;">SELECT Data FROM Server WHERE Server = ?</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span>

BEGIN_PARAM_MAP<span style="color: #808030;">(</span>_CGetServerDataAccessor<span style="color: #808030;">)</span>
    SET_PARAM_TYPE<span style="color: #808030;">(</span>DBPARAMIO_INPUT<span style="color: #808030;">)</span>
    <span style="color: #696969;">//_COLUMN_ENTRY_CODE(1, _OLEDB_TYPE(m_nServer), _SIZE_TYPE(m_nServer), 0, 0, offsetbuf(m_nServer), 0, 0)</span>
    COLUMN_ENTRY<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span> m_nServer<span style="color: #808030;">)</span>
END_PARAM_MAP<span style="color: #808030;">(</span><span style="color: #808030;">)</span>

BEGIN_ACCESSOR_MAP<span style="color: #808030;">(</span>_CGetServerDataAccessor<span style="color: #808030;">,</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span>
    BEGIN_ACCESSOR<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">true</span><span style="color: #808030;">)</span>
        <span style="color: #696969;">//_COLUMN_ENTRY_CODE(1, DBTYPE_IUNKNOWN, _SIZE_TYPE(m_pDataUnknown), 0, 0, offsetbuf(m_pDataUnknown), offsetbuf(m_nDataLength), 0)</span>
        BLOB_ENTRY_LENGTH<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>ISequentialStream<span style="color: #808030;">)</span><span style="color: #808030;">,</span> STGM_READ<span style="color: #808030;">,</span> m_pDataUnknown<span style="color: #808030;">,</span> m_nDataLength<span style="color: #808030;">)</span>
    END_ACCESSOR<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
END_ACCESSOR_MAP<span style="color: #808030;">(</span><span style="color: #808030;">)</span>

<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
    <span style="color: #603000;">LONG</span> m_nServer<span style="color: #800080;">;</span>
    IUnknown<span style="color: #808030;">*</span> m_pDataUnknown<span style="color: #800080;">;</span>
    DBLENGTH m_nDataLength<span style="color: #800080;">;</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span>

<span style="color: #800000; font-weight: bold;">class</span> CGetServerData <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CCommand<span style="color: #800080;">&lt;</span>CAccessor<span style="color: #800080;">&lt;</span>_CGetServerDataAccessor<span style="color: #800080;">&gt;</span> <span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
<span style="color: #696969;">// CGetServerData</span>
    HRESULT OpenRowset<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">const</span> CSession<span style="color: #808030;">&amp;</span> Session<span style="color: #808030;">,</span> <span style="color: #603000;">LPCWSTR</span> pszCommand <span style="color: #808030;">=</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span><span style="color: #808030;">!</span>pszCommand<span style="color: #808030;">)</span>
            _V<span style="color: #808030;">(</span>_CGetServerDataAccessor<span style="color: #800080;">::</span>GetDefaultCommand<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>pszCommand<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="color: #800000; font-weight: bold;">return</span> Open<span style="color: #808030;">(</span>Session<span style="color: #808030;">,</span> pszCommand<span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800080;">}</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">else</span>
<span style="color: #808030;">[</span>
    db_command<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">SELECT Data FROM Server WHERE Server = ?</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span>
<span style="color: #808030;">]</span>
<span style="color: #800000; font-weight: bold;">class</span> CGetServerData
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
    <span style="color: #808030;">[</span> db_param<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">1</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span> <span style="color: #808030;">]</span> <span style="color: #603000;">LONG</span> m_nServer<span style="color: #800080;">;</span>
    <span style="color: #808030;">[</span> db_column<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">1</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> length <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">m_nDataLength</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span> <span style="color: #808030;">]</span> IUnknown<span style="color: #808030;">*</span> m_pDataUnknown<span style="color: #800080;">;</span> DBLENGTH m_nDataLength<span style="color: #800080;">;</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">endif</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1136/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio .NET 2008 (9.0), Windows SDK version and MIDL compiler</title>
		<link>http://alax.info/blog/837</link>
		<comments>http://alax.info/blog/837#comments</comments>
		<pubDate>Tue, 17 Feb 2009 19:20:13 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[IDL]]></category>
		<category><![CDATA[MIDL]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[windows sdk]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=837</guid>
		<description><![CDATA[<a href="http://alax.info/blog/837" title="Visual Studio .NET 2008 (9.0), Windows SDK version and MIDL compiler"></a>Having installed Visual Studio .NET 2008 Service Pack 1 (installs Windows SDK 6.0a) and Windows SDK 6.1, I would obviously like to have newer Windows SDK used in include path. However after edit of WindowsSdkDir environment variable and checking all &#8230;<p class="read-more"><a href="http://alax.info/blog/837">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/837" title="Visual Studio .NET 2008 (9.0), Windows SDK version and MIDL compiler"></a><p>Having installed Visual Studio .NET 2008 Service Pack 1 (installs Windows SDK 6.0a) and Windows SDK 6.1, I would obviously like to have newer Windows SDK used in include path. However after edit of <em>WindowsSdkDir</em> environment variable and checking all include directories to point to new Windows (former Platform) SDK path &#8220;<em>C:\Program Files\Microsoft SDKs\Windows\v6.1</em>&#8220;, MIDL compiler still looked for files in wrong directoty, why?</p>
<pre>1&gt;Microsoft (R) 32b/64b MIDL Compiler Version 7.00.05001&gt;Copyright (c) Microsoft Corporation 1991-2006. All rights reserved.
1&gt;Processing .\MyProject.idl
1&gt;MyProject.idl
1&gt;Processing <span style="color: #ff0000;">C:\Program Files\Microsoft SDKs\Windows\v6.0a</span>\include\dispex.idl
1&gt;dispex.idl
1&gt;Processing <span style="color: #ff0000;">C:\Program Files\Microsoft SDKs\Windows\v6.0a</span>\include\ocidl.idl
1&gt;ocidl.idl
...</pre>
<p>A quick check of devenv.exe process environment variables revealed mystic names _ACP_ATLPROV, _ACP_INCLUDE, _ACP_LIB, _ACP_PATH defined by Visual Studio environment itself and they don&#8217;t seem to be configurable through some file in Visual Studio directory.</p>
<p>However the solution came rather quickly. The older SDK directory has to be referenced from somewhere for the Visual Studio to pick it up. Installed Widnows SDK versions are listed in registry under key <em>HKEY_CURRENT_USER\Software\Microsoft\Microsoft SDKs\Windows</em>, a subkey for each version, and it was older SDK set to be current.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/02/17-image001.png"><img class="alignnone size-medium wp-image-838" title="Windows SDK Versions in Registry" src="http://alax.info/blog/wp-content/uploads/2009/02/17-image001-300x77.png" alt="Windows SDK Versions in Registry" width="300" height="77" /></a></p>
<p>Once switched to new there, MIDL compiler started taking include files from proper directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/837/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio .NET 2008 freeze on opening a setup project</title>
		<link>http://alax.info/blog/823</link>
		<comments>http://alax.info/blog/823#comments</comments>
		<pubDate>Sun, 15 Feb 2009 22:40:13 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[freeze]]></category>
		<category><![CDATA[vdproj]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=823</guid>
		<description><![CDATA[<a href="http://alax.info/blog/823" title="Visual Studio .NET 2008 freeze on opening a setup project"></a>Some time ago I faced an annoying problem with a freeze of Visual Studio opening a solution with a Setup Project. I found that the problem was related to setup projects (.vdproj) that time and it was something with Visual &#8230;<p class="read-more"><a href="http://alax.info/blog/823">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/823" title="Visual Studio .NET 2008 freeze on opening a setup project"></a><p>Some time ago I faced an annoying problem with a freeze of Visual Studio opening a solution with a Setup Project. <a href="http://alax.info/blog/472">I found that the problem was related to setup projects</a> (<em>.vdproj</em>) that time and it was something with Visual Studio update, but I was of an opinion that Visual Studio .NET 2008 has problems opening projects created by version 2005. Compatibility or something&#8230; however the problem appeared that it cannot even create a new Setup Project with again a freeze.</p>
<p>Luckily, I found <a href="http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/9a0b3699-7109-4ac4-bd77-3efc8b841c27/">a hint on MSDN Forums</a>, and although the solution/workaround was not detailed enough, it worked for me from the first guess. Here it goes:</p>
<ol>
<li>Start Component Services (<em>dcomcnfg</em>) from command line</li>
<li>Right-click My Computer, and click Properties:<a href="http://alax.info/blog/wp-content/uploads/2009/02/16-image001.png">
<p><img class="alignnone size-medium wp-image-824" title="Component Services, My Computer, Properties" src="http://alax.info/blog/wp-content/uploads/2009/02/16-image001-300x219.png" alt="Component Services, My Computer, Properties" width="300" height="219" /></a></p>
<p>In the popped up window uncheck additional security box:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/02/16-image002.png"><img class="alignnone size-medium wp-image-825" title="My Computer Properties" src="http://alax.info/blog/wp-content/uploads/2009/02/16-image002-253x300.png" alt="My Computer Properties" width="253" height="300" /></a></li>
</ol>
<p>It appears to be sufficient for the Visual Studio .NET 2008 to start loading <em>.vdproj</em> projects again.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/823/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Visual Studio has encountered an internal error.</title>
		<link>http://alax.info/blog/730</link>
		<comments>http://alax.info/blog/730#comments</comments>
		<pubDate>Thu, 04 Dec 2008 22:43:37 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=730</guid>
		<description><![CDATA[<a href="http://alax.info/blog/730" title="Microsoft Visual Studio has encountered an internal error."></a>A picture for relaxation: It is probably a fresh bug there as it seems to be happening far more frequently with version 2008 (with ot without SP1) as compared to 2005. Luckily it has no effect to code being written, &#8230;<p class="read-more"><a href="http://alax.info/blog/730">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/730" title="Microsoft Visual Studio has encountered an internal error."></a><p>A picture for relaxation:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2008/12/04-image001.png"><img class="alignnone size-full wp-image-729" title="Visual Studio .NET Crash" src="http://alax.info/blog/wp-content/uploads/2008/12/04-image001.png" alt="" width="500" height="288" /></a></p>
<p>It is probably a fresh bug there as it seems to be happening far more frequently with version 2008 (with ot without SP1) as compared to 2005. Luckily it has no effect to code being written, the problem clearly relates to debugger. At some point there is a crash, though which the IDE perfectly survives but longer can start a new debugging session until IDE is entirely restarted.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/730/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft Visual Studio .NET 2008 SP1 IDE bugs continued</title>
		<link>http://alax.info/blog/653</link>
		<comments>http://alax.info/blog/653#comments</comments>
		<pubDate>Wed, 24 Sep 2008 15:28:46 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=653</guid>
		<description><![CDATA[<a href="http://alax.info/blog/653" title="Microsoft Visual Studio .NET 2008 SP1 IDE bugs continued"></a>It is amazing how bugs go through versions and years. Visual Studio&#8217;s IDE dockable windows framework is cool, no doubt. But it was since 2005, if not earlier, that tool window undocked by a double click while application is running &#8230;<p class="read-more"><a href="http://alax.info/blog/653">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/653" title="Microsoft Visual Studio .NET 2008 SP1 IDE bugs continued"></a><p>It is amazing how bugs go through versions and years. Visual Studio&#8217;s IDE dockable windows framework is cool, no doubt. But it was since 2005, if not earlier, that tool window undocked by a double click while application is running (debugging session active) is brought to wrong position and is tending to go out of screen area being re-shown.</p>
<p>This is exactly the behavior in 2008 version, regardless of reworked framework and fancy icons/hints/placeholders for the window being dragged. But just now it was even better. I double clicked &#8220;Find Results 1&#8243; window to maximize the window&#8230; and it disappeared. After looking for it through menu and other GUI elements, I finally found it at the rightmost border of the secondary monitor:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2008/09/24-image012.png"><img class="alignnone size-medium wp-image-654" title="MS VS 2008 SP1 IDE" src="http://alax.info/blog/wp-content/uploads/2008/09/24-image012-300x252.png" alt="" width="300" height="252" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/653/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Visual Studio .NET Development Environment</title>
		<link>http://alax.info/blog/646</link>
		<comments>http://alax.info/blog/646#comments</comments>
		<pubDate>Mon, 15 Sep 2008 06:50:42 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[stupidity]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=646</guid>
		<description><![CDATA[<a href="http://alax.info/blog/646" title="Microsoft Visual Studio .NET Development Environment"></a>The other day I &#8220;wrote some code&#8221; to workaround an extremely stupid hardware issues. The depth of idiocy is just incredible: to release a bunch of hardware that just don&#8217;t work, release a number of firmware updates that just don&#8217;t &#8230;<p class="read-more"><a href="http://alax.info/blog/646">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/646" title="Microsoft Visual Studio .NET Development Environment"></a><p>The other day I &#8220;wrote some code&#8221; to workaround an extremely stupid hardware issues. The depth of idiocy is just incredible: to release a bunch of hardware that just don&#8217;t work, release a number of firmware updates that just don&#8217;t fix the simplest thing: HTTP compatibility. If there was a single little try to see how this piece of crap comminicates with any WinHTTP based application, an error 12152 ERROR_WINHTTP_INVALID_SERVER_RESPONSE on the first second of execution would imminently come up and demonstrate that someone has to be fired without any hesitation.</p>
<p>Things, however, definitely went a different way with hardware still on the shelves and no firmware upgrades available on the website. Our customer got into trouble having already recommended his customer the buggy thing in amount of X and forwarded us the question of getting everything working. As we decided to make a step towards, I needed to &#8220;write some code&#8221; to settle the problem.</p>
<p>However, the story was about a different thing. So in order to put a comment into code that explains what kind of problem we are dealing with, I copy/pasted a fragment of HTTP request/response content from <a href="http://www.wireshark.org/">Wireshark</a> into source file being edited within MS Visual Studio .NET IDE. Wireshark copies text with some weird line endings, I knew that. I removed extra empty lines from pasted text and actually did not expect anything to go wrong. However who appeared to be wrong was me.</p>
<p>Initially there seemed to be no problem, I tried to compile code, fixed some compiler errors, even started application. I was somewhat confused that the application did not hit my breakpoint while it should. Then I noticed it did not even generate code for this line. As these things do happen with development environment, I re-opened IDE, deleting .NCB for the project and Rebuilt All. The problem however did not go.  After further code modification, the compiler started giving errors and shown wrong lines in build output, which did not match source code line numbers.</p>
<p>This started being completely stupid: I was to look at wrong identifier, search through entire source file for occurrences, see if this particular occurrence might be actually a problem for compiler and so on. I made it compiled successffully but under debugger there were still wrong line numbers which made it impossible to debug and set breakpoints.</p>
<p>At this point I remembered Wireshark and line endings. Just removing the comments did not worked. And since visually everything was OK with the source, there should be an easy way found to normalize text. And what I did was the following: I started new message in <a href="http://en.wikipedia.org/wiki/Mozilla_Thunderbird">Mozilla Thunderbird</a> and copy/pasted entire source file content into Thunderbird&#8217;s editor. Then copy/pasted back into Visual Studio and finally got the things fixed.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/646/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Visual Studio .NET 2008 annoyances</title>
		<link>http://alax.info/blog/635</link>
		<comments>http://alax.info/blog/635#comments</comments>
		<pubDate>Sun, 07 Sep 2008 21:14:38 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=635</guid>
		<description><![CDATA[<a href="http://alax.info/blog/635" title="New Visual Studio .NET 2008 annoyances"></a>Version 2008 (9.0) of Microsoft Visual Studio .NET 2008 Service Pack 1 development environment brings new annoyances in. It seems to be still freezing and crashing on certain source code files, just as previous versions did and additionally there is &#8230;<p class="read-more"><a href="http://alax.info/blog/635">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/635" title="New Visual Studio .NET 2008 annoyances"></a><p>Version 2008 (9.0) of <a href="http://msdn.microsoft.com/en-us/vstudio/products/default.aspx">Microsoft Visual Studio .NET 2008 Service Pack 1</a> development environment brings new annoyances in. It seems to be still freezing and crashing on certain source code files, just as previous versions did and additionally there is a new trick in:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2008/09/07-image001.png"><img class="alignnone size-medium wp-image-634" title="MS Visual Studio .NET 2008 SP1 Crash" src="http://alax.info/blog/wp-content/uploads/2008/09/07-image001-300x154.png" alt="" width="300" height="154" /></a></p>
<p>A termination of debugged application quite often ends up with a crash. Once crashed, IDE is still alive (thanks, really) but no debugging session will ever start again. A restart of IDE is required. Posted a crash report once again, hopefully someone is receiving them on MS side and takes to consideration.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/635/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

