<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>SCOTT-HILL.CO.UK</title>
  <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/" />
  <link rel="self" href="http://www.scott-hill.co.uk/blog/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2009-05-07T17:00:58.5506337+01:00</updated>
  <author>
    <name>Scott Hill</name>
  </author>
  <subtitle>Software design and other ramblings</subtitle>
  <id>http://www.scott-hill.co.uk/blog/</id>
  <generator uri="http://dasblog.info/" version="2.3.9074.18820">DasBlog</generator>
  <entry>
    <title>Installshield - GlobalAssemblyCache Install Location</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2009/05/07/InstallshieldGlobalAssemblyCacheInstallLocation.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,12eff0e2-b47b-4b24-b7d7-e1905c179064.aspx</id>
    <published>2009-05-07T17:00:58.5506337+01:00</published>
    <updated>2009-05-07T17:00:58.5506337+01:00</updated>
    <category term="Installshield" label="Installshield" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,Installshield.aspx" />
    <author>
      <name>Scott Hill</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#000000">I had an issue today with installing assemblies into the GAC
through installshield. My installer has several components configured with a
Destination of <strong>[GlobalAssemblyCache]</strong> which is the recommended way
of performing a GacUtil through installshield. Now previously, the <strong>".NET Scan
at Build"</strong> property for these components had been set to <strong>"Dependencies
and Properties"</strong> and everything worked fine. Recently we have been updating
the installers to work for 64 bit installations (managed by altering the ISM as part
of our build process). As a result of this I had to remove the dependancy scan as
this was causing issues on 64 bit servers. I set this field to <strong>"None"</strong> and
soon found that all the assemblies I had targeted at the GAC ended up on the root
of the install drive (i.e. c:\) instead of in the GAC :o</font>
        </p>
        <p>
          <font color="#000000">Anyway, I eventually managed to solve this issue by setting
the <strong>".NET Scan at Build"</strong> property to "<strong>Properties Only</strong>".
It seems that this has to be set for GACed assemblies as it causes the MsiAssembly
table to be populated.</font>
        </p>
        <p>
          <font color="#000000">Hope this helps anyone else with similar issues.</font>
        </p>
        <img src="http://www.scott-hill.co.uk/blog/content/binary/Installshield.jpg" border="0" />
        <img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=12eff0e2-b47b-4b24-b7d7-e1905c179064" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Enlisting in Transactions in Custom SSIS Data Flow Components</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2009/05/06/EnlistingInTransactionsInCustomSSISDataFlowComponents.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,81dd122c-6e96-4fd4-b28b-e5a91c401b92.aspx</id>
    <published>2009-05-06T21:04:57.055+01:00</published>
    <updated>2009-05-06T21:06:40.5395137+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,NET.aspx" />
    <category term="C#" label="C#" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,C.aspx" />
    <author>
      <name>Scott Hill</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've seen a few newsgroups with SSIS developers having difficulties enlisting in the
active transaction with a custom Data Flow component in .NET. I recently had to do
this to enable message queue operations to be performed within the active transaction
for the package. Unfortunately the built in Message Queue task has no support for
enlisting in the active transaction so a custom approach was required. I'm sure that
most SSIS developers who have dabbled with custom components will have seen the following
Microsoft.SqlServer.Dts.Pipeline.PipelineComponent class:
</p>
        <font size="2">
          <pre>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Establishes a connection to a connection manager</span>
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">virtual</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> AcquireConnections
(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> transaction)</span>
          </pre>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" size="2">This
method can be overriden a custom component and used to establish any required connections.
Now we know that SSIS uses DTC transactions and that MSMQ supports DTC but how do
the two map together? What is the transaction object that we are passed in? There
seems to be very little documentation on this subject available on the internet so
I experimented with the debugger and found a way to map this through to .NET. The
first stage is to convert the supplied object into a managed System.Transactions.Transaction
object. This can be achieved with the following code:</font>
            </span>
          </p>
        </font>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Get a &lt;code&gt;System.Transactions.Transaction&lt;/code&gt; from a supplied COM
transaction pointer</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span> Transaction
GetTransactionFromCom(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> comTransaction)
{     Transaction managedTransaction <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;
    ITransaction transactionInterface <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> comTransaction <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span> ITransaction;
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (transactionInterface
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)
    {         managedTransaction <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span>             TransactionInterop.GetTransactionFromDtcTransaction((IDtcTransaction)transactionInterface);
    }     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> managedTransaction;
}</span>
        </pre>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" size="2">Once
the supplied COM transaction pointer has been converted to a managed Transaction object
it can be used as normal with your .NET code. For message queue transactions this
means setting the ambient transaction and sending/receiving messages using <strong><em>MessageQueueTransactionType.Automatic</em></strong>.
For example:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <pre>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Save the current transaction</span> Transaction previousTransaction <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Transaction.Current; <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Set the current ambient transaction</span> Transaction.Current <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> managedTransaction; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">try</span> {
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> (MessageQueue
queue <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> MessageQueue(messageQueuePath))
    {         queue.Send(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Body"</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Label"</span>,
MessageQueueTransactionType.Automatic);     } } <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">finally</span> {
    Transaction.Current <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> previousTransaction;
}</span>
          </pre>
        </span>
        <img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=81dd122c-6e96-4fd4-b28b-e5a91c401b92" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Retrieving Properties from Remote Private Queues in MSMQ</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2009/05/06/RetrievingPropertiesFromRemotePrivateQueuesInMSMQ.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,88f4de13-40d7-4a54-8f16-8f111169fa9d.aspx</id>
    <published>2009-05-06T20:37:55.958+01:00</published>
    <updated>2009-05-06T20:42:18.4461163+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,NET.aspx" />
    <category term="C#" label="C#" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,C.aspx" />
    <author>
      <name>Scott Hill</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently needed to access the Label property of a remote private MSMQ through .NET.
Naturally my first thought was that this should be a pretty trivial operation as this
property is exposed via the MessageQueue (System.Messaging) class in the .NET framework.
Unfortunately however, this property can only be read for local private queues (those
on the same machine as the executing code) not for remote private queues. According
to Microsoft "Private queues are registered on the local computer, not in the directory
service, and their properties <strong>cannot</strong> be obtained by Message Queuing
applications running on remote computers".
</p>
        <p>
After a bit of testing, I found that it is possible to access remote private queue
properties through .NET using DCOM. The following example shows how this can be achieved
for the Label property. The same technique can be applied to retrieve other queue
properties such as the Transactional state of the queue.
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> GetRemoteQueueLabel(MessageQueue
queue, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> serverAddress)
{     <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Find label for remote private queue</span>     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> queueInfoDcom <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Activator.CreateInstance(Type.GetTypeFromProgID(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"MSMQ.MSMQQueueInfo"</span>,
serverAdress));     Type classType <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> queueInfoDcom.GetType();
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Invoke method using reflection and return outputs</span>     BindingFlags
bindingFlags <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> BindingFlags.Public <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.Instance <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.SetProperty;
    classType.InvokeMember(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"FormatName"</span>,
bindingFlags, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>,
queueInfoDcom, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>[]
{ queue.FormatName });     bindingFlags <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> BindingFlags.Public <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.Instance <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.InvokeMethod;
    classType.InvokeMember(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Refresh"</span>,
bindingFlags, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>,
queueInfoDcom, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>[]
{ });     bindingFlags <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> BindingFlags.Public <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.Instance <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.GetProperty;
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> label <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>)classType.InvokeMember(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Label"</span>,
bindingFlags, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>,
queueInfoDcom, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>[]
{ });     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> label;
}</span>
          <font color="#008000" size="2">
            <font color="#008000" size="2">
            </font>
          </font>
        </pre>
        <img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=88f4de13-40d7-4a54-8f16-8f111169fa9d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>My First Blog via Email</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2009/05/02/MyFirstBlogViaEmail.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,b7c9eab8-bc51-4f3f-8405-05363429db42.aspx</id>
    <published>2009-05-02T13:23:49+01:00</published>
    <updated>2009-05-02T13:25:54.9392091+01:00</updated>
    <content type="html">

&lt;div class=Section1&gt;
&lt;p class=MsoNormal&gt;
Just a quick blog to test the Mail To WebLog feature of DasBlog!&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
This email has been scanned by the MessageLabs Email Security System.&lt;br&gt;
For more information please visit http://www.messagelabs.com/email 
&lt;br&gt;
&lt;br&gt;
&lt;img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=b7c9eab8-bc51-4f3f-8405-05363429db42" /&gt;</content>
  </entry>
  <entry>
    <title>Three (Hutchinson 3G) Mobile Up to Their Old Tricks</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2008/07/27/ThreeHutchinson3GMobileUpToTheirOldTricks.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,f8073431-3090-46e5-be8a-eb110d8bc61b.aspx</id>
    <published>2008-07-27T18:57:32.8401718+01:00</published>
    <updated>2008-07-27T18:57:32.8401718+01:00</updated>
    <author>
      <name>Scott Hill</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here was me thinking I'd escaped the complete ineptness of three mobile 5 years ago
but unfortunately its back to haunt me! After closing my account back in December
2003 (and paying the remaining 6 months line rental up front to do so!) I've just
recieved a letter from Lowell Portfolio indicating that they have been sold the outstounding
debt of £20.07 that I owe on my three account. I was shocked to say the least! The
account was fully closed and is marked as settled in my credit report. In addittion,
i have never recieved any requests from 3 for this so-caled balance! I contacted three
straight away and after being passed around one of their useless indian call centres
no one could explain where this additional money had come from - but obviously its
left to me to spend my time and money sorting this mess out.
</p>
        <p>
Anyway, clearly the money isn't really the issue but I'm prepared to fight this issue
on behalf of all the other ex-three customers out there who are probably being screwed
in much the same way! If anyone's considering switching to three and has stumbled
accross this site please take one piece of advice from me....
</p>
        <p>
If you value your sanity - *never* enter into any dealings with this company. Their
customer service is appauling. If one good thing can come out of this incident it's
the hope that at least one potential customer will be swayed away from three by this
post :o) Let me know if you've had any similar problems.
</p>
        <img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=f8073431-3090-46e5-be8a-eb110d8bc61b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Attaching to console from windows application in .NET</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2008/07/02/AttachingToConsoleFromWindowsApplicationInNET.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,0a7a6221-e459-4f78-826b-5c30b853a199.aspx</id>
    <published>2008-07-02T16:31:56.571+01:00</published>
    <updated>2008-07-03T21:31:02.6191988+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,NET.aspx" />
    <category term="C#" label="C#" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,C.aspx" />
    <category term="Software Development" label="Software Development" scheme="http://www.scott-hill.co.uk/blog/CategoryView,category,SoftwareDevelopment.aspx" />
    <author>
      <name>Scott Hill</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The other day I had to update a existing windows GUI application to enable it to be
called via the command line. In order to do this, you need to add the following import
to your .NET application (C# example shown):
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
AttachConsole gives the ability for a GUI application to write to the console window
of the console from which it was started.</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span> [System.Runtime.InteropServices.DllImport(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"kernel32.dll"</span>)] <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">extern</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> AttachConsole(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">uint</span> dwProcessId); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Flag indicating that we should attach to parent console</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">const</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">uint</span> ATTACH_PARENT_PROCESS <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 0x0ffffffff; </span>
        </pre>
        <p>
          <font size="2">After adding these declarations to your main class, its a simple case
of adapting your Main method to detect if you're running in console or GUI mode
and acting accordingly. E.g:</font>
        </p>
        <font size="2">
          <pre>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
The main entry point for the application.</span>
              <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span> [STAThread] <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Main(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
args) { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Are we in console mode</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> isConsole <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> args.Length
&gt; 0; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (!isConsole)
{ RunVisual(); } <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span> { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Attach to console</span> AttachConsole(ATTACH_PARENT_PROCESS); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Run console app</span> RunConsole(args); } }</span>
          </pre>
        </font>
        <img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=0a7a6221-e459-4f78-826b-5c30b853a199" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Welcome to my new look site!</title>
    <link rel="alternate" type="text/html" href="http://www.scott-hill.co.uk/blog/2008/06/28/WelcomeToMyNewLookSite.aspx" />
    <id>http://www.scott-hill.co.uk/blog/PermaLink,guid,137b0ad0-91c5-4c21-b12a-eabbb2583409.aspx</id>
    <published>2008-06-28T09:50:54.391+01:00</published>
    <updated>2008-06-28T14:54:50.8961092+01:00</updated>
    <author>
      <name>Scott Hill</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Hi and welcome to scott-hill.co.uk.
</p>
        <p>
After months of neglect I've decided to give the web site an overhaul and a brand
new look. I've now migrated to dasBlog 2.1 and so far things are looking good. Some
of my older articles won't be available from now on but I'll try and repost the most
popular ones shortly. 
</p>
        <p>
Enjoy!
</p>
        <img width="0" height="0" src="http://www.scott-hill.co.uk/blog/aggbug.ashx?id=137b0ad0-91c5-4c21-b12a-eabbb2583409" />
      </div>
    </content>
  </entry>
</feed>