.net CLR, boost and mixed mode fun

Last week we tried to create a managed C++ DLL that includes another managed library and a library that is purely native. What made matters even more funky was, that the native library extensively made use of the boost library.

I haven’t been a great fan of that particular library (because it quite bloats your debug binaries, take ages to compile and introduces code that you are not in control of and that hardly anyone understands) but the code was there already, so what can you do 🙂

So first trial was to just make a DLL project that compiles with /clr Option and statically link the other two libraries.
Everything works fine, compile and link wise that is. But when you start your C# client application an exception pops up: “BadImageFileException” with hardly any additional information. Forum posts that one of the libs might be complied 64bit whilst the others were 32bit or something similar were in that case misleading, although above differences can also lead to that particular exception.

To cut a long story short, here the steps to take care of when trying to include boost library code into a mixed mode DLL:

  • In our scenario boost threads only work when linked dynamically, that is
    #include <boost/thread.hpp>
  • The second thing that we did in our CLR DLL was to split the 2 “sides” into 2 cpp files giving something like something_native.cpp and something_managed.cpp. In the native part we added references to the native libs with a construct like this:
    #pragma managed(push, off)
    #include <unmanaged_sublib.h> //unmanaged includes
    #pragma comment(lib...)
    #pragma managed(pop)

With above steps we were able to build a mixed mode DLL that delivers all the functionality provided by the two sublibraries, the managed (easy) and also the native library using boost*. Now I can enjoy my holidays 🙂

What the heck have I done last week?

Every Wednesday we’ve got team meeting and I need to find out what the heck I was doing last week :). SVN Repository logs are very helpfull whith that concern. Here a little bash script that extracts the log entries of a given user for the last 7 days…


REPOS="TetraTrans Libraries IDDS IDDS2010"

for repo in $REPOS
	svn log $repo -r {`date --date="7 days ago" +%Y-%m-%d`}:{`date +%Y-%m-%d`} | sed -n "/"$MYSVNUSER"/,/-----$/ p"

xslt to document xml schemas

Here a little XSLT code that transforms the documentation fields of any XSD Schema into a nicely formatted html page. There are several tools (especially commercial ones) that will do the task as well. But what I found was that all of them meant it too well and presented too much information.

This solution tries to keep it simple and presents elements and their attributes; with the appropriate documentation for each of them …

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
<xsl:output method="html" indent="yes" version="4.0"/>
<xsl:strip-space elements="section"/>
<!--exclude-result-prefixes="xs" -->

<xsl:template match="/">
<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
body { font-family: verdana,arial,sans-serif;
.heading { font-family: verdana,arial,sans-serif;
		<basefont size="2" color="#CC00CC" face="Verdana" />
		<h2>Configuration Documentation</h2>
		<br /> <br /> <span> gernerated by document.xslt <br /><xsl:value-of select="ex:date-time()"/></span>

<xsl:template match="xs:element">
<br /> <hr /> <br /> <br />
<xsl:variable name="elname"><xsl:value-of select="@name"/></xsl:variable>
<span class="heading" id="{$elname}">Element <xsl:value-of select="@name"/></span><br />
Description:<xsl:value-of select="xs:annotation/xs:documentation"/>
<xsl:for-each select="xs:complexType">
<!-- list all attributes -->
<xsl:if test="xs:attribute or xs:simpleContent/xs:extension/xs:attribute">
<span class="heading">Attributes:</span>
<table class="gridtable">
<th>Name</th><th>Type</th><th>Description</th><th>Use</th><th>Possible Values</th>
	<xsl:apply-templates select="xs:attribute"/>
<xsl:for-each select="xs:simpleContent/xs:extension">
	<xsl:apply-templates select="xs:attribute"/>

<!-- list all subelements -->
<xsl:if test="xs:all/xs:element or xs:sequence/xs:element">
<p><span class="heading">Subelements: </span>
<xsl:for-each select="xs:all/xs:element">
 <xsl:variable name="elinklname"><xsl:value-of select="@name"/></xsl:variable>
 <a href="#{$elinklname}"><xsl:value-of select="@name"/></a><xsl:if test="position() &lt;  last()"><xsl:text>, </xsl:text></xsl:if>
<xsl:for-each select="xs:sequence/xs:element">
 <xsl:variable name="elinklname"><xsl:value-of select="@name"/></xsl:variable>
 <a href="#{$elinklname}"><xsl:value-of select="@name"/></a><xsl:if test="position() &lt;  last()"><xsl:text>, </xsl:text></xsl:if>

<!-- recurse into all subelements -->
<xsl:for-each select="xs:all"><xsl:text> </xsl:text>
	<xsl:apply-templates select="xs:element"/>
<xsl:for-each select="xs:sequence"><xsl:text> </xsl:text>
	<xsl:apply-templates select="xs:element"/>


<!-- atributes -->
<xsl:template match="xs:attribute">
<tr><td><xsl:value-of select="@name"/></td>
<!-- type, bit dirty since it includes both possibilties without an if statement -->
<td><xsl:value-of select="@type"/><xsl:value-of select="xs:simpleType/xs:restriction/@base"/></td>
<td><xsl:value-of select="xs:annotation/xs:documentation"/></td>
<td><xsl:value-of select="@use"/></td>
<!-- possible values, dirty, but hey :) -->
<td><xsl:for-each select="xs:simpleType/xs:restriction/xs:enumeration">
	<xsl:value-of select="@value"/><xsl:if test="position() &lt;  last()"><xsl:text>, </xsl:text></xsl:if>
<xsl:value-of select="@fixed" />