<?xml version="1.0" encoding="utf-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Phalanger on Mono (part 2)</title>
	<link>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/</link>
	<description>Human Code Generator</description>
	<pubDate>Wed, 14 May 2008 02:32:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: zbowling</title>
		<link>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25723</link>
		<dc:creator>zbowling</dc:creator>
		<pubDate>Sat, 24 Nov 2007 08:05:53 +0000</pubDate>
		<guid>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25723</guid>
		<description>yes. makes sense.</description>
		<content:encoded><![CDATA[<p>yes. makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25712</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Thu, 22 Nov 2007 14:30:41 +0000</pubDate>
		<guid>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25712</guid>
		<description>[quote]
There are also a few typedefs in the headers that compile to two different sizes between 32bit and 64bit platforms so I have to declare two versions of the same p/invoke calls on some occasions and use one or the other if the code is running on 32bit or 64bit.
[/quote]

Well, one trick is to have a native wrapper library which exposes a single API which does not have a change in size between 32bit/64bit platforms and then that native library will interop with your existing C++ code.

The size of 'long' in your C++ code will be the same as in the wrapper library, so you'll have no troubles interoping there, and your wrapper library will just expose it as int32_t or int64_t as required, so you are guaranteed fixed size variables.

Then, the C# code P/Invokes your wrapper library on all platforms, so you only need 1 set of p/Invokes in C# and you don't need runtime detection.

Alternatively, if you don't care about windows64 support, just represent a 'long' as an IntPtr in your C# code and you support all 32bit windows systems and all platforms with sizeof(pointer) == sizeof(long). Which is everything except win64.

Hope that makes sense.</description>
		<content:encoded><![CDATA[<p>[quote]<br />
There are also a few typedefs in the headers that compile to two different sizes between 32bit and 64bit platforms so I have to declare two versions of the same p/invoke calls on some occasions and use one or the other if the code is running on 32bit or 64bit.<br />
[/quote]</p>
<p>Well, one trick is to have a native wrapper library which exposes a single API which does not have a change in size between 32bit/64bit platforms and then that native library will interop with your existing C++ code.</p>
<p>The size of &#8216;long&#8217; in your C++ code will be the same as in the wrapper library, so you&#8217;ll have no troubles interoping there, and your wrapper library will just expose it as int32_t or int64_t as required, so you are guaranteed fixed size variables.</p>
<p>Then, the C# code P/Invokes your wrapper library on all platforms, so you only need 1 set of p/Invokes in C# and you don&#8217;t need runtime detection.</p>
<p>Alternatively, if you don&#8217;t care about windows64 support, just represent a &#8216;long&#8217; as an IntPtr in your C# code and you support all 32bit windows systems and all platforms with sizeof(pointer) == sizeof(long). Which is everything except win64.</p>
<p>Hope that makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zbowling</title>
		<link>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25711</link>
		<dc:creator>zbowling</dc:creator>
		<pubDate>Thu, 22 Nov 2007 10:40:11 +0000</pubDate>
		<guid>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25711</guid>
		<description>Generation of the assemblies with reflection.emit is easy. It's the reversing of the interfaces back and forth. Code generation sucks, plus its not dynamic to each new extension you drop in and you have to have more then just the .NET runtime but the entire SDK. You would assume that the SDK would be there if they are using ASP.NET but not every time. :-)</description>
		<content:encoded><![CDATA[<p>Generation of the assemblies with reflection.emit is easy. It&#8217;s the reversing of the interfaces back and forth. Code generation sucks, plus its not dynamic to each new extension you drop in and you have to have more then just the .NET runtime but the entire SDK. You would assume that the SDK would be there if they are using ASP.NET but not every time. <img src='http://zbowling.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asbjørn Ulsberg</title>
		<link>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25710</link>
		<dc:creator>Asbjørn Ulsberg</dc:creator>
		<pubDate>Thu, 22 Nov 2007 08:54:43 +0000</pubDate>
		<guid>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25710</guid>
		<description>Wow, it almost made me sweat just reading that! Sounds exhausting. :) However, wouldn't it be possible to perform some of the code-generation as an automatic step, perhaps in the (pre-) build process? That would at least help the upstream maintainers and perhaps make them embrace the all-C#-solution you've created (which I think sounds much better, if only just for the cross-platform interoperability, than the managed C++ one).

Anyway, nice work! What would be even more interesting than writing PHP in a .NET environment, though, would be to write C# in a PHP environment. ;-)</description>
		<content:encoded><![CDATA[<p>Wow, it almost made me sweat just reading that! Sounds exhausting. <img src='http://zbowling.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> However, wouldn&#8217;t it be possible to perform some of the code-generation as an automatic step, perhaps in the (pre-) build process? That would at least help the upstream maintainers and perhaps make them embrace the all-C#-solution you&#8217;ve created (which I think sounds much better, if only just for the cross-platform interoperability, than the managed C++ one).</p>
<p>Anyway, nice work! What would be even more interesting than writing PHP in a .NET environment, though, would be to write C# in a PHP environment. <img src='http://zbowling.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pic_micro</title>
		<link>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25709</link>
		<dc:creator>pic_micro</dc:creator>
		<pubDate>Wed, 21 Nov 2007 22:15:35 +0000</pubDate>
		<guid>http://zbowling.com/blog/2007/11/21/phalanger-on-mono-part-2/#comment-25709</guid>
		<description>Nice idea.</description>
		<content:encoded><![CDATA[<p>Nice idea.</p>
]]></content:encoded>
	</item>
</channel>
</rss>


