<?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>Marshal-As.NET</title>
  <link rel="alternate" type="text/html" href="http://www.marshal-as.net/" />
  <link rel="self" href="http://www.marshal-as.net/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2007-12-13T17:15:57.8074153-05:00</updated>
  <author>
    <name>Gregory Consulting</name>
  </author>
  <subtitle>Collecting specializations for marshal_as&lt;&gt;</subtitle>
  <id>http://www.marshal-as.net/</id>
  <generator uri="http://dasblog.info/" version="2.3.9074.18820">DasBlog</generator>
  <entry>
    <title>HFONT and System::Drawing::Font</title>
    <link rel="alternate" type="text/html" href="http://www.marshal-as.net/HFONTAndSystemDrawingFont.aspx" />
    <id>http://www.marshal-as.net/PermaLink,guid,db66d8ba-a82c-407c-b4b7-3a8f95a2261e.aspx</id>
    <published>2007-12-13T17:15:57.8074153-05:00</published>
    <updated>2007-12-13T17:15:57.8074153-05:00</updated>
    <category term="Specializations" label="Specializations" scheme="http://www.marshal-as.net/CategoryView,category,Specializations.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
From <a href="http://blog.voidnish.com/?p=150">Nish</a>.
</p>
        <pre>
          <span class="keyword">
            <font color="#0000ff">
              <span class="keyword">
                <font color="#0000ff">
                  <font color="#008000" size="3">//code
starts here</font>
                </font>
              </span>
            </font>
          </span>
        </pre>
        <pre>
          <span class="keyword">
            <font color="#0000ff">
              <span class="keyword">
              </span>
              <font size="3">namespace</font>
            </font>
          </span>
          <font size="3"> msclr
{ <span class="keyword"><font color="#0000ff">namespace</font></span> interop { <span class="keyword"><font color="#0000ff">template</font></span>&lt;&gt; <span class="keyword"><font color="#0000ff">ref</font></span><span class="keyword"><font color="#0000ff">class</font></span> context_node&lt;System::Drawing::Font^,
HFONT&gt; : <span class="keyword"><font color="#0000ff">public</font></span> context_node_base
{ <span class="keyword"><font color="#0000ff">private</font></span>: System::Drawing::Font^
_font; <span class="keyword"><font color="#0000ff">public</font></span>: context_node(System::Drawing::Font^%
to, HFONT from) { to = _font = System::Drawing::Font::FromHfont((IntPtr)from); } ~context_node()
{ <span class="keyword"><font color="#0000ff">this</font></span>-&gt;!context_node();
} <span class="keyword"><font color="#0000ff">protected</font></span>: !context_node()
{ <span class="keyword"><font color="#0000ff">delete</font></span> _font; } }; <span class="keyword"><font color="#0000ff">template</font></span>&lt;&gt; <span class="keyword"><font color="#0000ff">ref</font></span><span class="keyword"><font color="#0000ff">class</font></span> context_node&lt;HFONT,
System::Drawing::Font^&gt; : <span class="keyword"><font color="#0000ff">public</font></span> context_node_base
{ <span class="keyword"><font color="#0000ff">private</font></span>: HFONT _hFont; <span class="keyword"><font color="#0000ff">public</font></span>:
context_node(HFONT&amp; to, System::Drawing::Font^ from) { to = _hFont = (HFONT)from-&gt;ToHfont().ToPointer();
} ~context_node() { <span class="keyword"><font color="#0000ff">this</font></span>-&gt;!context_node();
} <span class="keyword"><font color="#0000ff">protected</font></span>: !context_node()
{ DeleteObject(_hFont); } }; } }</font>
        </pre>
        <pre>
          <font color="#008000" size="3">//code
ends here</font>
        </pre>
        <p>
Wow. Our first use of a context. Instead of writing a function that implements a specialization
of the template function, you write a class that implements a specialization
of the template class. Since it's a class, it can have member variables, which you
clean up when the context goes out of scope.
</p>
        <p>
Here's how you might use it:
</p>
        <pre>HFONT hFont = CreateSampleFont();
	
<span class="comment"><font color="#008000">//...</font></span> marshal_context
context; System::Drawing::Font^ font = context.<span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;System::Drawing::Font^&gt;(hFont);
HFONT hFontCopy = context.<span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;HFONT&gt;(font); <span class="comment"><font color="#008000">//...</font></span> DeleteObject(hFont);</pre>
        <p>
Kate
</p>
        <img width="0" height="0" src="http://www.marshal-as.net/aggbug.ashx?id=db66d8ba-a82c-407c-b4b7-3a8f95a2261e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>RECT, CRect, and System::Drawing::Rectangle</title>
    <link rel="alternate" type="text/html" href="http://www.marshal-as.net/RECTCRectAndSystemDrawingRectangle.aspx" />
    <id>http://www.marshal-as.net/PermaLink,guid,2ca3bf42-3458-409a-8bce-9cbd60339da0.aspx</id>
    <published>2007-12-13T17:05:57.116-05:00</published>
    <updated>2007-12-13T17:09:34.7474401-05:00</updated>
    <category term="Specializations" label="Specializations" scheme="http://www.marshal-as.net/CategoryView,category,Specializations.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
From <a href="http://blog.voidnish.com/?p=149">Nish</a>.
</p>
        <pre>
          <span class="keyword">
            <font color="#0000ff">
              <font color="#008000" size="3">//code
starts here</font>
            </font>
          </span>
        </pre>
        <pre>
          <font size="3">
            <span class="keyword">
              <font color="#0000ff">namespace</font>
            </span> msclr
{ <span class="keyword"><font color="#0000ff">namespace</font></span> interop { <span class="keyword"><font color="#0000ff">template</font></span>&lt;&gt;
System::Drawing::Rectangle <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;System::Drawing::Rectangle,
RECT&gt; ( <span class="keyword"><font color="#0000ff">const</font></span> RECT&amp;
from) { <span class="keyword"><font color="#0000ff">return</font></span> System::Drawing::Rectangle(from.left,
from.top, from.right - from.left, from.bottom - from.top); } <span class="keyword"><font color="#0000ff">template</font></span>&lt;&gt;
System::Drawing::Rectangle <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;
System::Drawing::Rectangle, CRect&gt; ( <span class="keyword"><font color="#0000ff">const</font></span> CRect&amp;
from) { <span class="keyword"><font color="#0000ff">return</font></span> System::Drawing::Rectangle(from.left,
from.top, from.Width(), from.Height()); } <span class="keyword"><font color="#0000ff">template</font></span>&lt;&gt;
RECT <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;RECT,
System::Drawing::Rectangle&gt;( <span class="keyword"><font color="#0000ff">const</font></span> System::Drawing::Rectangle&amp;
from) { System::Drawing::Rectangle rectangle = from; <span class="comment"><font color="#008000">//remove
const</font></span> RECT rect = {rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom}; <span class="keyword"><font color="#0000ff">return</font></span> rect;
} <span class="keyword"><font color="#0000ff">template</font></span>&lt;&gt; CRect <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;CRect,
System::Drawing::Rectangle&gt;( <span class="keyword"><font color="#0000ff">const</font></span> System::Drawing::Rectangle&amp;
from) { System::Drawing::Rectangle rectangle = from; <span class="comment"><font color="#008000">//remove
const</font></span><span class="keyword"><font color="#0000ff">return</font></span> CRect
(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom); } } }</font>
        </pre>
        <pre>
          <font color="#008000" size="3">//code
ends here</font>
        </pre>
        <p>
Why cast away const? Because System::Drawing::Rect is CLS-compliant and the properties
(Top, Bottom, Left Right) are not flagged as keeping the object const. We know they
don't change it, so we make a copy to use the properties on, thus keeping the compiler
happy about our const ref argument.
</p>
        <p>
To use these, it's as you'd expect:
</p>
        <pre>
          <font size="3">
            <span class="comment">
              <font color="#008000">//To Rectangle</font>
            </span> RECT
rect = {<span class="number"><font color="#ff0000">10</font></span>, <span class="number"><font color="#ff0000">10</font></span>, <span class="number"><font color="#ff0000">110</font></span>, <span class="number"><font color="#ff0000">110</font></span>};
System::Drawing::Rectangle rectangle = <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;System::Drawing::Rectangle&gt;(rect);
CRect mfcRect(<span class="number"><font color="#ff0000">20</font></span>, <span class="number"><font color="#ff0000">20</font></span>, <span class="number"><font color="#ff0000">220</font></span>, <span class="number"><font color="#ff0000">220</font></span>);
rectangle = <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;System::Drawing::Rectangle&gt;(mfcRect); <span class="comment"><font color="#008000">//From
Rectangle</font></span> RECT rectBack = <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;RECT&gt;(rectangle);
CRect mfcRectBack = <span class="keyword"><font color="#0000ff">marshal_as</font></span>&lt;CRect&gt;(rectangle);</font>
        </pre>
        <p>
Kate
</p>
        <img width="0" height="0" src="http://www.marshal-as.net/aggbug.ashx?id=2ca3bf42-3458-409a-8bce-9cbd60339da0" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Wish List</title>
    <link rel="alternate" type="text/html" href="http://www.marshal-as.net/WishList.aspx" />
    <id>http://www.marshal-as.net/PermaLink,guid,45e4a036-5601-49e5-a274-a225c49906e9.aspx</id>
    <published>2007-11-30T08:24:46.6210015-05:00</published>
    <updated>2007-11-30T08:24:46.6210015-05:00</updated>
    <category term="Wanted" label="Wanted" scheme="http://www.marshal-as.net/CategoryView,category,Wanted.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <content type="html">&lt;p&gt;
Would you like to try writing a marshal_as&amp;lt;&amp;gt; specialization? They're super simple,
after all. Here's a list of some that we're sure to need:
&lt;/p&gt;
&lt;p b&gt;
&lt;u&gt;Array Conversions&lt;/u&gt;&gt;
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;b&gt;FROM TYPE&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&lt;b&gt;TO TYPE&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
std::vector&amp;lt;std::string&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
std::vector&amp;lt;std::string&amp;gt;&amp;nbsp; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
std::vector&amp;lt;std::wstring&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
std::vector&amp;lt;std::wstring&amp;gt;&amp;nbsp; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;&lt;?xml:namespace prefix = o /&gt;
CArray&amp;lt;ATL::CStringT&amp;lt;char&amp;gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CArray&amp;lt;ATL::CStringT&amp;lt;char&amp;gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;o:p&gt;&lt;/o:p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CArray&amp;lt;ATL::CStringT&amp;lt;wchar_t&amp;gt;&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CArray&amp;lt;ATL::CStringT&amp;lt;wchar_t&amp;gt;&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CSimpleArray&amp;lt;ATL::CStringT&amp;lt;char&amp;gt;&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CSimpleArray&amp;lt;ATL::CStringT&amp;lt;char&amp;gt;&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CSimpleArray&amp;lt;ATL::CStringT&amp;lt;wchar_t&amp;gt;&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CSimpleArray&amp;lt;ATL::CStringT&amp;lt;wchar_t&amp;gt;&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CSimpleArray&amp;lt;CComBSTR&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CSimpleArray&amp;lt;CComBSTR&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CArray&amp;lt;CComBSTR&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CArray&amp;lt;CComBSTR&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;td&gt;
std::vector&amp;lt;T&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
std::vector&amp;lt;T&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CComSafeArray&amp;lt;T,U&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CComSafeArray&amp;lt;T, U&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CArray&amp;lt;T&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CArray&amp;lt;T&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CAtlArray&amp;lt;T&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CAtlArray&amp;lt;T&amp;gt;&lt;/td&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CAtlArray&amp;lt;ATL::CStringT&amp;lt;char&amp;gt;&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CAtlArray&amp;lt;ATL::CStringT&amp;lt;char&amp;gt;&amp;gt;&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CAtlArray&amp;lt;ATL::CStringT&amp;lt;wchar_t&amp;gt;&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CAtlArray&amp;lt;ATL::CStringT&amp;lt;wchar_t&amp;gt;&amp;gt;&lt;/td&gt;
&lt;td&gt;
array&amp;lt;String^&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;td&gt;
CSimpleArray&amp;lt;T&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CSimpleArray&amp;lt;T&amp;gt; 
&lt;/td&gt;
&lt;td&gt;
array&amp;lt;T&amp;gt;^&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&lt;b&gt;&lt;u&gt;Other Conversions:&lt;/u&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;b&gt;FROM TYPE&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&lt;b&gt;TO TYPE&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::IntPtr&lt;/td&gt;
&lt;td&gt;
ATL::CHandle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
ATL::CHandle&lt;/td&gt;
&lt;td&gt;
System::IntPtr&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::DateTime&amp;nbsp; 
&lt;/td&gt;
&lt;td&gt;
SYSTEMTIME&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
SYSTEMTIME&lt;/td&gt;
&lt;td&gt;
System::DateTime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::Object^&lt;/td&gt;
&lt;td&gt;
IUnknown*&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
IUnknown *&lt;/td&gt;
&lt;td&gt;
System::Object^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::Object ^&lt;/td&gt;
&lt;td&gt;
com_ptr&amp;lt;IUnknown&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::Object ^&lt;/td&gt;
&lt;td&gt;
CComPtr&amp;lt;Iunknown&amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::Object^ 
&lt;/td&gt;
&lt;td&gt;
VARIANT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
VARIANT&lt;/td&gt;
&lt;td&gt;
System::Object^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.marshal-as.net/GUIDAndSystemGuid.aspx"&gt;System::Guid &lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://www.marshal-as.net/GUIDAndSystemGuid.aspx"&gt;GUID&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.marshal-as.net/GUIDAndSystemGuid.aspx"&gt;GUID&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://www.marshal-as.net/GUIDAndSystemGuid.aspx"&gt;System::GUID&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::DateTime&lt;/td&gt;
&lt;td&gt;
CTime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
CTime&lt;/td&gt;
&lt;td&gt;
System::DateTime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System::DateTime&lt;/td&gt;
&lt;td&gt;
COleDateTime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
COleDateTime&lt;/td&gt;
&lt;td&gt;
System::DateTime&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
I've pasted the table in as I received it, and linked to things we already have. I'd
like to come back to this list and add links as you send me things.
&lt;/p&gt;
&lt;p&gt;
Kate
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.marshal-as.net/aggbug.ashx?id=45e4a036-5601-49e5-a274-a225c49906e9" /&gt;</content>
  </entry>
  <entry>
    <title>_GUID and System::Guid</title>
    <link rel="alternate" type="text/html" href="http://www.marshal-as.net/GUIDAndSystemGuid.aspx" />
    <id>http://www.marshal-as.net/PermaLink,guid,c45098cc-a605-49f1-b2ca-ef527c8fa7ea.aspx</id>
    <published>2007-11-22T08:41:32.861-05:00</published>
    <updated>2007-11-22T08:44:02.4373827-05:00</updated>
    <category term="Specializations" label="Specializations" scheme="http://www.marshal-as.net/CategoryView,category,Specializations.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
From <a href="http://www.managed-world.com/">Jason Olson</a>.
</p>
        <p>
          <font color="#008000">//code starts here</font>
        </p>
        <font color="#0000ff" size="2">
          <p>
#pragma
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">once<br />
#include</font>
        <font color="#000000" size="2">
        </font>
        <font color="#a31515" size="2">&lt;msclr\marshal.h&gt;<br /></font>
        <font color="#0000ff" size="2">#include</font>
        <font color="#000000" size="2">
        </font>
        <font color="#a31515" size="2">&lt;msclr\marshal_windows.h&gt;
</font>
        <font color="#0000ff" size="2">
          <p>
namespace
</p>
        </font>
        <font size="2">
          <font color="#000000"> msclr {<br /></font>
        </font>
        <font color="#0000ff" size="2">namespace</font>
        <font size="2"> interop
{</font>
        <font size="2">
          <font size="2">
            <p>
            </p>
          </font>
          <font color="#008000" size="2">////////////////////////////////////////////////////////////////////<br /></font>
          <font color="#008000" size="2">// GUID Conversions<br /></font>
          <font color="#008000" size="2">////////////////////////////////////////////////////////////////////
</font>
          <font size="2">
            <p>
            </p>
          </font>
          <font color="#0000ff" size="2">template</font>
          <font size="2">&lt;&gt;<br /></font>
          <font color="#0000ff" size="2">inline</font>
          <font size="2"> _GUID marshal_as&lt;_GUID,
System::Guid&gt;(</font>
          <font color="#0000ff" size="2">const</font>
          <font size="2"> System::Guid&amp;
from) {
<p>
    System::Guid^ source = from;<br /></p></font>
          <font color="#0000ff" size="2">    array</font>
          <font size="2">&lt;Byte&gt;^
guidData = source-&gt;ToByteArray();<br /></font>
          <font color="#0000ff" size="2">    pin_ptr</font>
          <font size="2">&lt;Byte&gt;
data = &amp;(guidData[ 0 ]);<br /></font>
          <font color="#0000ff" size="2">    return</font>
          <font size="2"> *(_GUID
*)data;
<p>
}
</p><p></p></font>
          <font color="#0000ff" size="2">template</font>
          <font size="2">&lt;&gt;<br /></font>
          <font color="#0000ff" size="2">inline</font>
          <font size="2"> Guid marshal_as&lt;System::Guid,
_GUID&gt;(</font>
          <font color="#0000ff" size="2">const</font>
          <font size="2"> _GUID&amp;
from) {<br />
    </font>
          <font color="#0000ff" size="2">return</font>
          <font size="2"> System::Guid(
from.Data1, from.Data2, from.Data3, from.Data4[ 0 ], from.Data4[ 1 ], 
<br />
                                
from.Data4[ 2 ], from.Data4[ 3 ], from.Data4[ 4 ], from.Data4[ 5 ], 
<br />
                                
from.Data4[ 6 ], from.Data4[ 7 ] );
<p>
}
</p><p>
}
</p><p>
}
</p></font>
        </font>
        <p>
          <font color="#008000">//code ends here</font>
        </p>
        <p>
At first glance the pin_ptr is a little scary, but this code doesn't return it, it
dereferences it. So no "GC hole" to worry about.
</p>
        <p>
Kate
</p>
        <img width="0" height="0" src="http://www.marshal-as.net/aggbug.ashx?id=c45098cc-a605-49f1-b2ca-ef527c8fa7ea" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Some handy file system flags</title>
    <link rel="alternate" type="text/html" href="http://www.marshal-as.net/SomeHandyFileSystemFlags.aspx" />
    <id>http://www.marshal-as.net/PermaLink,guid,83d91757-7064-4361-bb87-dae7d0a55b00.aspx</id>
    <published>2007-11-22T08:35:35.4282475-05:00</published>
    <updated>2007-11-22T08:35:35.4282475-05:00</updated>
    <category term="Specializations" label="Specializations" scheme="http://www.marshal-as.net/CategoryView,category,Specializations.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
From <a href="http://www.managed-world.com/">Jason Olson</a>.
</p>
        <p>
          <font color="#008000" size="2">//code starts here</font>
        </p>
        <font color="#0000ff" size="2">
          <p>
#pragma
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">once<br />
#include</font>
        <font color="#000000" size="2">
        </font>
        <font color="#a31515" size="2">&lt;msclr\marshal.h&gt;<br /></font>
        <font color="#0000ff" size="2">#include</font>
        <font color="#000000" size="2">
        </font>
        <font color="#a31515" size="2">&lt;msclr\marshal_windows.h&gt;<br /></font>
        <font color="#0000ff" size="2">namespace</font>
        <font size="2">
          <font color="#000000"> msclr
{<br /></font>
        </font>
        <font color="#0000ff" size="2">namespace</font>
        <font size="2"> interop
{
<p></p></font>
        <font color="#008000" size="2">////////////////////////////////////////////////////////////////////<br /></font>
        <font color="#008000" size="2">// File I/O Conversions (constants from System::IO)<br /></font>
        <font color="#008000" size="2">///////////////////////////////////////////////////////////////////
</font>
        <font size="2">
          <p>
          </p>
        </font>
        <font color="#0000ff" size="2">template</font>
        <font size="2">&lt;&gt;<br /></font>
        <font color="#0000ff" size="2">inline</font>
        <font size="2"> DWORD marshal_as&lt;DWORD,
System::IO::FileMode&gt;(</font>
        <font color="#0000ff" size="2">const</font>
        <font size="2"> System::IO::FileMode&amp;
from) {
<p></p></font>
        <font color="#0000ff" size="2">if</font>
        <font size="2"> (from != System::IO::FileMode::Append)<br />
    </font>
        <font color="#0000ff" size="2">return</font>
        <font size="2"> (DWORD)from;<br /></font>
        <font color="#0000ff" size="2">else<br />
    </font>
        <font color="#0000ff" size="2">return</font>
        <font size="2"> (DWORD)System::IO::FileMode::OpenOrCreate;
<p>
}
</p><p></p></font>
        <font color="#0000ff" size="2">template</font>
        <font size="2">&lt;&gt;<br /></font>
        <font color="#0000ff" size="2">inline</font>
        <font size="2"> DWORD marshal_as&lt;DWORD,
System::IO::FileAccess&gt;(</font>
        <font color="#0000ff" size="2">const</font>
        <font size="2"> System::IO::FileAccess&amp;
from) {<br /></font>
        <font color="#0000ff" size="2">if</font>
        <font size="2"> (from == System::IO::FileAccess::Read)<br />
    </font>
        <font color="#0000ff" size="2">return</font>
        <font size="2"> GENERIC_READ;<br /></font>
        <font color="#0000ff" size="2">else<br />
    </font>
        <font color="#0000ff" size="2">return</font>
        <font size="2"> GENERIC_WRITE;
<p>
}
</p><p></p></font>
        <font color="#0000ff" size="2">template</font>
        <font size="2">&lt;&gt;<br /></font>
        <font color="#0000ff" size="2">inline</font>
        <font size="2"> DWORD marshal_as&lt;DWORD,
System::IO::FileShare&gt;(</font>
        <font color="#0000ff" size="2">const</font>
        <font size="2"> System::IO::FileShare&amp;
from) {<br />
    </font>
        <font color="#0000ff" size="2">return</font>
        <font size="2"> (DWORD)from;
<p>
}
</p><font size="2"><p>
}
</p><p>
}
</p><p><font color="#008000" size="2">//code ends here</font></p></font></font>
        <p>
Nice and simple.
</p>
        <p>
Kate
</p>
        <img width="0" height="0" src="http://www.marshal-as.net/aggbug.ashx?id=83d91757-7064-4361-bb87-dae7d0a55b00" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Welcome to Marshal-As.NET !</title>
    <link rel="alternate" type="text/html" href="http://www.marshal-as.net/WelcomeToMarshalAsNET.aspx" />
    <id>http://www.marshal-as.net/PermaLink,guid,aa97cb73-38b0-4308-82d7-94f8d3c32a81.aspx</id>
    <published>2007-11-19T10:00:51.512-05:00</published>
    <updated>2007-11-19T10:15:03.7402354-05:00</updated>
    <category term="Meta" label="Meta" scheme="http://www.marshal-as.net/CategoryView,category,Meta.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here we are!
</p>
        <p>
What's going on here? Think pinvoke.net for the marshaling library. Send me your specializations
(my email address isn't hard to find, or comment on this post -- if I use comments
I'll remove them from here as I go) and I'll post them, one post per specialization,
after the barest of quality control (I might make sure your code compiles) and then
others can find them and comment on them. Together we will build a full-size marshaling
library for all the common structs and classes that might pass back and forth across
the managed-native boundary. 
</p>
        <p>
Some of you may have some specializations already written. Great! I'll post them as
I get them and if I can't keep up, I have a volunteer team waiting to help. So let's
go!
</p>
        <p>
Kate Gregory
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.marshal-as.net/aggbug.ashx?id=aa97cb73-38b0-4308-82d7-94f8d3c32a81" />
      </div>
    </content>
  </entry>
</feed>
