<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ken Kopczyk &#187; Interop</title>
	<atom:link href="http://kenkopczyk.com/tag/interop/feed/" rel="self" type="application/rss+xml" />
	<link>http://kenkopczyk.com</link>
	<description>Hurdles in .NET WinForms Development</description>
	<lastBuildDate>Sat, 13 Mar 2010 03:50:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kenkopczyk.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/60348bde5d188332d5268692846b25c7?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ken Kopczyk &#187; Interop</title>
		<link>http://kenkopczyk.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kenkopczyk.com/osd.xml" title="Ken Kopczyk" />
	<atom:link rel='hub' href='http://kenkopczyk.com/?pushpress=hub'/>
		<item>
		<title>Creating COM Interop Assemblies with .NET 2.0</title>
		<link>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/</link>
		<comments>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 03:14:11 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[.NET SDK]]></category>
		<category><![CDATA[COM Interop]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Interop]]></category>
		<category><![CDATA[Strong Naming]]></category>
		<category><![CDATA[tlbimp]]></category>

		<guid isPermaLink="false">http://kenkopczyk.com/?p=189</guid>
		<description><![CDATA[If you work with .NET long enough, sooner or later you&#8217;ll probably need to leverage older Win32 COM components. To allow the CLR managed code of .NET to communicate with the unmanaged code of COM, a &#8220;middleman&#8221; in the form of an interop assembly must be created. This can be done via Visual Studio or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&amp;blog=6344943&amp;post=189&amp;subd=kkopczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you work with .NET long enough, sooner or later you&#8217;ll probably need to leverage older Win32 COM components.  To allow the CLR managed code of .NET to communicate with the unmanaged code of COM, a &#8220;middleman&#8221; in the form of an interop assembly must be created.  This can be done via Visual Studio or the Type Library Importer.</p>
<p><b>Creating an interop assembly with Visual Studio</b><br />
Enter the &#8220;Add reference&#8221; dialog of your project, browse for your registered COM server and select it.  Now take a look at the properties of the newly created reference.  It is actually pointing to a new assembly called Interop.COMServerName.dll:  If your COM server is foo.dll, the resulting assembly is called Interop.foo.dll.  You will find this assembly in your bin directory after you build.</p>
<p>If your project uses an .snk or .pfx for strong naming, the interop assembly will also be strong named using that file.</p>
<p>A major limitation of this method I found was the fact that you can&#8217;t change the version number of the interop assembly.  It is <i>always</i> 1.0.0.0.  Bummer.</p>
<p><b>Creating an interop assembly with Type Library Importer</b><br />
If you need more control, then you should use the <a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(VS.80).aspx">Type Library Importer (tlbimp)</a>.  This application is included with the .NET SDK.</p>
<p>Running the following command will create an interop assembly with a version number of your choosing:<br />
Using our foo.dll example:</p>
<pre class="brush: bash;">
tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0
</pre>
<p>If you need the interop assembly strongly named, you can do that also.  If you are using an .snk, use the following:</p>
<pre class="brush: bash;">
tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0 /keyfile:MyKey.snk
</pre>
<p>If you are using a .pfx for strong naming, it&#8217;s a bit trickier.  You will also need to leverage the <a href="http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.80).aspx">Strong Name Tool (sn)</a> to create a keycontainer:</p>
<pre class="brush: bash;">
echo Prompts you for .pfx password
sn -i MyKey.pfx KeyContainerName

tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0 /keycontainer:KeyContainerName

echo Housecleaning.  Removes the key container from memory.
sn -d KeyContainerName
</pre>
<p>Now add it as a reference and you&#8217;re good to go!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&amp;blog=6344943&amp;post=189&amp;subd=kkopczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>
	</item>
	</channel>
</rss>