<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Jim Lahman's Blog</title>
        <link>http://geekswithblogs.net/jpl/Default.aspx</link>
        <description> .Netting in a real-time world</description>
        <language>en-US</language>
        <copyright>Jim Lahman</copyright>
        <managingEditor>jim.lahman@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Jim Lahman's Blog</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/jpl/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Unmanaged arrays in C# structs</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/07/09/arrays-in-c-structs.aspx</link>
            <description>&lt;span style="font-family: Arial;"&gt;I am creating a Memory Mapped File (MMF) that will act like a circular buffer because it will store "live" 100msec data from a PLC.  The controls engineer wanted to send the data to me as tag arrays.  So, to mimic these tag arrays, I decided to create a structure the reflects these tag arrays.  &lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt;There are ten arrays in the structure.  &lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt;The first array is an array of two short integers (16-bits) that contain a write and read pointer.&lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt;The next three array is an array of 1024 bytes, an array of 1024 short integers and an array of 1024 floats.  This set of three arrays is repeated three times.&lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt;A structLayout attribute is used to place these arrays in sequential order and I specify the size so that I can reserve that amount of space on the disk for the MMF when it is created.  Each array is marshalled as an  &lt;/span&gt;&lt;span style="font-weight: bold; font-family: Arial;"&gt;UnmanagedType.ByValArray.  &lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt;Here is the structure as I first created it:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font size="1" style="font-weight: bold;"&gt;[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 150532)]&lt;/font&gt;
&lt;pre style="font-family: Courier New;"&gt;&lt;font size="1"&gt;&lt;span style="font-weight: bold;"&gt;public struct strL1CmnRec&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;{&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2, ArraySubType = UnmanagedType.I2)] public short[] shtL1Ptrs;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.U1)] public byte[] byEntryBool;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.I2)] public short[] shtEntryInts;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.R4)] public float[] sngEntryReals;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.U1)] public byte[] byProcBool;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.I2)] public short[] shtProcInts;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.R4)] public float[] sngProcReals;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.U1)] public byte[] byDelvBool;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.I2)] public short[] shtDelvInts;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024, ArraySubType = UnmanagedType.R4)] public float[] sngDelvReals;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;}&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-family: Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;To access this structure and its arrays, I declared this variable:&lt;/p&gt;
&lt;pre style="margin-left: 40px;"&gt;&lt;font size="2" style="font-weight: bold;"&gt;&lt;span style="font-family: Courier New;"&gt;strL1CmnRec L1CRec;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;span style="font-family: Arial;"&gt;I then attempted to write into one the arrays as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="font-weight: bold;"&gt;L1CRec.shtL1Ptrs[0] = i;&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;&lt;span style="font-weight: bold;"&gt;L1CRec.shtL1Ptrs[1] = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;And, when &lt;span style="font-style: italic;"&gt;i&lt;/span&gt; was attempted to be placed into &lt;span style="font-style: italic;"&gt;shtL1Ptrs[0]&lt;/span&gt;, I received a runtime error because &lt;span style="font-style: italic;"&gt;shtL1Ptrs[0]&lt;/span&gt; was &lt;span style="font-weight: bold;"&gt;null&lt;/span&gt;!&lt;br /&gt;&lt;br /&gt;What to do?  What to do?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It turns out that in a C# struct, the arrays are declared but its memory is not allocated.  So I wrote a &lt;span style="font-style: italic;"&gt;create&lt;/span&gt; method to allocate memory&lt;br /&gt;for each array in the struct.  The &lt;span style="font-style: italic;"&gt;create&lt;/span&gt; method is part of the C# struct.&lt;br /&gt;&lt;br /&gt;&lt;font size="2" style="font-weight: bold;"&gt;&lt;span style="font-family: Courier New;"&gt;       public static strL1CmnRec create()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;        {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;            return new strL1CmnRec&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;            {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                shtL1Ptrs = new short[2],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                byEntryBool = new byte[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                shtEntryInts = new short[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                sngEntryReals = new float[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                byProcBool = new byte[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                shtProcInts = new short[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                sngProcReals = new float[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                byDelvBool = new byte[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                shtDelvInts = new short[1024],&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;                sngDelvReals = new float[1024]&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;            };&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;So, now to access these arrays, I first declared the variable: &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="2" style="font-weight: bold;"&gt;&lt;span style="font-family: Courier New;"&gt;strL1CmnRec L1CRec;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="font-family: Arial;"&gt;then I call the &lt;span style="font-style: italic;"&gt;create&lt;/span&gt; function.  I place this in the constructor of the class that is using this structure:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New; font-weight: bold;"&gt;L1CRec = strL1CmnRec.create();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
I can now successfully access the arrays in the struct.  &lt;br /&gt;
&lt;br /&gt;
 &lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133393"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133393" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/133393.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/07/09/arrays-in-c-structs.aspx</guid>
            <pubDate>Thu, 09 Jul 2009 21:13:20 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/133393.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/07/09/arrays-in-c-structs.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/133393.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C# Constants &amp; Global Variables</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/07/03/c-constants.aspx</link>
            <description>&lt;font size="2"&gt;&lt;span style="font-family: Arial;"&gt;Moving from C++ to C#, I discovered that constants in the way I was using them are not supported; however, they can be &lt;span style="font-weight: bold;"&gt;emulated&lt;/span&gt;.  they are now defined in their own class as static variables; I go a step further by making them private and only available through a property.  &lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt; Before I show a code example, let's explore &lt;/span&gt;&lt;span style="font-style: italic; font-family: Arial;"&gt;static&lt;/span&gt;&lt;span style="font-family: Arial;"&gt; further.  When a variable is declared as &lt;/span&gt;&lt;span style="font-weight: bold; font-family: Arial;"&gt;static&lt;/span&gt;&lt;span style="font-family: Arial;"&gt;, the variable is essentially global.  All instances of the class share the same static variable.  A static variable is initialized to zero unless an explicit initializer is specified.&lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;br style="font-family: Arial;" /&gt;
&lt;span style="font-family: Arial;"&gt; FIrst, let's look at the class that defines the constants:&lt;/span&gt;&lt;br style="font-family: Arial;" /&gt;
&lt;/font&gt;   &lt;br /&gt;
&lt;div style="margin-left: 40px;"&gt;&lt;font size="2" style="font-family: Times New Roman;"&gt;namespace Globals&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;{&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;    public class clsGlobalDefs&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;    {&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;       &lt;/font&gt;&lt;font size="2" style="font-family: Times New Roman;"&gt; private static string _c1 = "Constant 1";&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        private static string _c2= "This is a constant string";&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        public string c1&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        {&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;            get { return _c1; }&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        }&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        public string c2&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        {&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;            get { return _c2; }&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        }&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        public clsGlobalDefs()&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        {&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt; &lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;        }&lt;/font&gt;&lt;br /&gt;
&lt;font size="2" style="font-family: Times New Roman;"&gt;}&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;font size="2"&gt;&lt;span style="font-family: Arial;"&gt;A few notes on the above class:&lt;/span&gt;&lt;br /&gt;
&lt;/font&gt; &lt;br /&gt;
&lt;ol&gt;
    &lt;li&gt;I like placing the constants in their own namespace and their own DLL.  This allows me to use the same constants across multiple projects.&lt;/li&gt;
    &lt;li&gt;Note the use of the static qualifier&lt;/li&gt;
    &lt;li&gt;Note the use of properties&lt;/li&gt;
&lt;/ol&gt;
&lt;font size="2"&gt;&lt;span style="font-family: Arial;"&gt;To use class &lt;/span&gt;&lt;span style="font-weight: bold; font-family: Arial;"&gt;clsGlobalDefs&lt;/span&gt;&lt;span style="font-family: Arial;"&gt;:&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
    &lt;li&gt;Reference clsGlobalDefs through a using statement : &lt;span style="font-weight: bold;"&gt;using Globals&lt;/span&gt;&lt;/li&gt;
    &lt;li&gt;Instantiate clsGlobalDefs:         &lt;span style="font-weight: bold;"&gt;clsGlobalDefs GlobalDefs = new clsGlobalDefs();&lt;/span&gt;     &lt;/li&gt;
    &lt;li&gt;Access the constant through the class' property:&lt;/li&gt;
&lt;/ol&gt;
&lt;div style="margin-left: 40px;"&gt;&lt;font size="2"&gt;&lt;span style="font-family: Times New Roman; font-weight: bold;"&gt;String s;&lt;/span&gt;&lt;br style="font-family: Times New Roman; font-weight: bold;" /&gt;
&lt;span style="font-family: Times New Roman; font-weight: bold;"&gt; s = GlobalDefs.c1;&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: Times New Roman;"&gt;-or-&lt;/span&gt;&lt;span style="font-family: Times New Roman; font-weight: bold;"&gt;&lt;br /&gt;
&lt;br /&gt;
s = "This is constant #1: " + GlobalDefs.c1&lt;br style="font-family: Times New Roman;" /&gt;
&lt;/span&gt; &lt;/font&gt; &lt;br /&gt;
&lt;span style="font-family: Arial;"&gt;&lt;font size="2" style="font-weight: bold;"&gt;&lt;span style="font-family: Times New Roman;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133236"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133236" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/133236.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/07/03/c-constants.aspx</guid>
            <pubDate>Fri, 03 Jul 2009 12:16:37 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/133236.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/07/03/c-constants.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/133236.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C# - Checking for NULL</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/05/26/c---checking-for-null.aspx</link>
            <description>&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
&lt;meta content="OneNote.File" name="ProgId" /&gt;
&lt;meta content="Microsoft OneNote 12" name="Generator" /&gt;
&lt;p style="margin: 0in; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;
&lt;/p&gt;&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
&lt;meta content="OneNote.File" name="ProgId" /&gt;
&lt;meta content="Microsoft OneNote 12" name="Generator" /&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;If the column you are reading has the potential for a NULL value, then you must use the DBNull object:&lt;/p&gt;

&lt;p style="margin: 0in; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 40px; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;DataRowView dRowView = m_SchedCommentsBindingSource[0] as DataRowView;&lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 40px; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;dsL2DB.SchedulesRow SchedRow = dRowView.Row as dsL2DB.SchedulesRow;&lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 40px; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;sDeleteComment = (SchedRow["DeleteComment"] == DBNull.Value ? "No Delete Comment" : SchedRow.DeleteComment);&lt;/p&gt;
&lt;p style="margin: 0in; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;More generically:&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 40px; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;If (ds.Rows[0]["ColumnName"] == DBNull.Value)&lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 40px; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 0.7884in; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;// Do something for NULL value&lt;/p&gt;
&lt;p style="margin: 0in 0in 0in 40px; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;}&lt;/p&gt;
&lt;p style="margin-top: 0in; margin-right: 0in; margin-bottom: 0in; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9pt;"&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132431"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132431" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/132431.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/05/26/c---checking-for-null.aspx</guid>
            <pubDate>Tue, 26 May 2009 21:04:35 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/132431.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/05/26/c---checking-for-null.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/132431.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Powershell output</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/05/14/powershell-output.aspx</link>
            <description>I'm beginning to write simple scripts in powershell.  One of the things items that really isn't straight forward is the &lt;span style="font-weight: bold;"&gt;write-output&lt;/span&gt; command.  At first glance, one would think that this would simply output a string.  Well, there is a trick I found.&lt;br /&gt;
&lt;br /&gt;
PS&amp;gt;write-output xxxxxxxx yyyyyyyyy&lt;br /&gt;
&lt;br /&gt;
really outputs&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;xxxxxxxx &lt;br /&gt;
yyyyyyyyy&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
PS&amp;gt;write-output "xxxxxxxx yyyyyyyyy"&lt;br /&gt;
&lt;br /&gt;
really outputs&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;xxxxxxxx yyyyyyyyy&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
PS&amp;gt; $A = 10&lt;br /&gt;
PS&amp;gt;$B = 20&lt;br /&gt;
PS&amp;gt;write-output "A = $A   B = $B"&lt;br /&gt;
&lt;br /&gt;
really outputs&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;A = 10  B = 20&lt;/span&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132113"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132113" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/132113.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/05/14/powershell-output.aspx</guid>
            <pubDate>Thu, 14 May 2009 19:30:45 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/132113.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/05/14/powershell-output.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/132113.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C# string formatting</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/04/13/c-replacement-for-sprintf.aspx</link>
            <description>In C++, one uses the sprintf function to build a formatted string like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-left: 40px;"&gt; &lt;font size="2"&gt;&lt;span style="font-family: Courier New;"&gt;char szOutput[256];&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt; sprintf(szOutput, "At loop position %d.\n", i);&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
The C# equivalent is the String.Format method [string.format(string, object)].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-left: 40px;"&gt; &lt;font size="2"&gt; &lt;span style="font-family: Courier New;"&gt;TrkCmnRec.szMillOrderNbr = String.Format("MO #{0}", i);&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt; &lt;span style="font-family: Arial;"&gt; &lt;/span&gt;&lt;/font&gt; &lt;/div&gt;
Each placeholder in the string is numeric, so if we want to have a string with three placeholders, we would use &lt;em&gt;{0}, {1}, {2}&lt;/em&gt;,...{n} as shown in this example:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-left: 40px;"&gt;&lt;span style="font-family: Courier New;"&gt;String sA = "Test string"&lt;br /&gt;
int i = 10;&lt;br /&gt;
Single f = 45.0&lt;br /&gt;
String s = String.Format("String = {0}, int = {1}, Single&lt;/span&gt;= {2}", sA, i, f};&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
String, numeric and date data types have their own formatting specifiers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table cellspacing="1" cellpadding="1" border="2" align="" summary="" style="width: 617px; height: 315px;"&gt;
    &lt;caption style="font-weight: bold;"&gt;Numeric Format Specifiers&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;Specifier&lt;/td&gt;
            &lt;td style="text-align: center;"&gt;Description&lt;/td&gt;
            &lt;td style="text-align: center;"&gt;Example&lt;/td&gt;
            &lt;td style="text-align: center;"&gt;C#&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;c&lt;/td&gt;
            &lt;td&gt;Currency; specify the number of decimal places&lt;/td&gt;
            &lt;td&gt; $12,345.00&lt;/td&gt;
            &lt;td&gt;&lt;font size="2"&gt;string.Format("Currency: {0:c}", iNbr)&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;d&lt;/td&gt;
            &lt;td&gt;Whole numbers; specifies the minimum number of digits - zeroes will be used to pad the result&lt;/td&gt;
            &lt;td&gt; 12345&lt;/td&gt;
            &lt;td&gt;string.Format("Whole: {0:d}", iNbr)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;e&lt;/td&gt;
            &lt;td&gt;Scientific notation; specifies the number of decimal places&lt;/td&gt;
            &lt;td&gt; 1.2345e+004&lt;/td&gt;
            &lt;td&gt;string.Format("Exponential: {0:e}", iNbr)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;f&lt;/td&gt;
            &lt;td&gt;Fixed-point; specifies the number of decimal places&lt;/td&gt;
            &lt;td&gt; 12345.00&lt;/td&gt;
            &lt;td&gt;string.Format("Fixed: {0:f3}", iNbr)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;n&lt;/td&gt;
            &lt;td&gt;Fixed-point with comma separators; specifies the number of decimal places&lt;/td&gt;
            &lt;td&gt; 12,345.00&lt;/td&gt;
            &lt;td&gt;string.Format("Fixed formatted: {0:n3}", iNbr)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;p&lt;/td&gt;
            &lt;td&gt;percentage; specifies the number of decimal places&lt;/td&gt;
            &lt;td&gt; 1,234,500.00%&lt;/td&gt;
            &lt;td&gt;string.Format("Percentage: {0:p2}", iNbr)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="font-weight: bold;"&gt;x&lt;/td&gt;
            &lt;td&gt;Hexadecimal&lt;/td&gt;
            &lt;td&gt; 3039&lt;/td&gt;
            &lt;td&gt;string.Format("Hexadecimal: {0:x}", iNbr)&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130941"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130941" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/130941.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/04/13/c-replacement-for-sprintf.aspx</guid>
            <pubDate>Mon, 13 Apr 2009 19:56:22 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/130941.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/04/13/c-replacement-for-sprintf.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/130941.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using win32 API in C#</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/04/07/using-win32-api-in-c.aspx</link>
            <description>&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
&lt;meta content="BLOCKNOTE.NET" name="GENERATOR" /&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[ODY { FONT-FAMILY:Tahoma; FONT-SIZE:10pt }
P { FONT-FAMILY:Tahoma; FONT-SIZE:10pt }
DIV { FONT-FAMILY:Tahoma; FONT-SIZE:10pt }
TD { FONT-FAMILY:Tahoma; FONT-SIZE:10pt }
]]&gt;&lt;/style&gt;
&lt;basefont size="2" face="Tahoma" /&gt;
When I was working in VC++, it was relatively easy to include a win32 API function.  All we did was include the header file and then made a call to a function like so:
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;        #include &amp;lt;Mailbox.h&amp;gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;                &lt;font face="monospace"&gt;CMailbox::MbxStatus CMailbox::iCreateMbx() {&lt;br /&gt;
        MbxStatus iStatus = mbxSuccess;&lt;br /&gt;
&lt;br /&gt;
        switch ( m_iType ) {&lt;br /&gt;
        case mbxReceiver:&lt;br /&gt;
        case mbxBoth:&lt;br /&gt;
                // for receive type mailboxes we need to create a&lt;br /&gt;
                // space for the reception of data&lt;br /&gt;
                /* if ( m_hRecvMbx ) CloseHandle( m_hRecvMbx ); */&lt;br /&gt;
                m_hRecvMbx = ::CreateMailslot(&lt;br /&gt;
                        m_strInName,&lt;br /&gt;
                        0,&lt;br /&gt;
                        MAILSLOT_WAIT_FOREVER,&lt;br /&gt;
                        &amp;amp;( SECURITY_ATTRIBUTES )m_saInfo // previously was NULL&lt;br /&gt;
                );&lt;br /&gt;
&lt;br /&gt;
                // if the mailslot already exists, return error&lt;br /&gt;
                if ( m_hRecvMbx == INVALID_HANDLE_VALUE ) {&lt;br /&gt;
                        m_hRecvMbx = NULL;&lt;br /&gt;
                        iStatus = mbxCreateFailure;&lt;br /&gt;
                }&lt;br /&gt;
                /* if ( m_iType == mbxReceiver ) */ break;&lt;br /&gt;
&lt;br /&gt;
        case mbxSender:&lt;br /&gt;
                // for send type mailboxes we need to obtain a&lt;br /&gt;
                // target to send to&lt;br /&gt;
                iStatus = iSetReceiver( m_strOutName );&lt;br /&gt;
                break;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return iStatus;&lt;br /&gt;
&lt;/font&gt;            &lt;font face="monospace"&gt;}&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;But, now, we have to use interop services because the DLL functions are considered to be in &lt;em&gt;unmanaged&lt;/em&gt; code, which does not execute under the control of the CLR.&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The list of DLL functions are listed in the MSDN in the Platform SDK as System Services.&lt;/div&gt;
 
&lt;div&gt;Use &lt;span style="font-style: italic;"&gt;DLLImport &lt;/span&gt;to specify  an entry point into the DLL for the win32 function that is to be called.  The DLLImport Attribute has four fields: EntryPoint, CharSet, CallingConvention, SetLastError.  From the MSDN library, these are defined as such:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;table width="50%" cellspacing="2" cellpadding="5"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;&lt;strong&gt;DllImportAttribute field&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td&gt;
            &lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;EntryPoint&lt;/p&gt;
            &lt;/td&gt;
            &lt;td&gt;
            &lt;p&gt;Specifies the DLL entry point to be called. The default entry point name is the name of the managed method.&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;CharSet&lt;/p&gt;
            &lt;/td&gt;
            &lt;td&gt;
            &lt;p&gt;Controls the name mangling and the way that String parameters should be marshaled. The .NET Compact Framework only supports CharSet..::.Unicode and CharSet..::.Auto. CharSet..::.Auto equates to CharSet..::.Unicode on Windows CE. The default marshaling on the .NET Compact Framework is CharSet..::.Unicode, unlike the .NET Framework that defaults to CharSet..::.Ansi.&lt;/p&gt;
            &lt;p&gt;Because the .NET Compact Framework does not support the DllImportAttribute..::.ExactSpelling field, the common language runtime automatically searches for an entry point according to the values specified by CharSet.&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;CallingConvention&lt;/p&gt;
            &lt;/td&gt;
            &lt;td&gt;
            &lt;p&gt;Specifies the calling-convention values used in passing method arguments. The default is CallingConvention..::.Winapi, which corresponds to __cdecl on the Windows CE platform.&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;SetLastError&lt;/p&gt;
            &lt;/td&gt;
            &lt;td&gt;
            &lt;p&gt;Enables the caller to use the GetLastWin32Error method to determine whether an error occurred while executing the platform invoke method. In Visual Basic 2005, the default is true; in C#, the default is false.&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Here's an example of using the DLLImport attribute:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;        [DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr CreateFile (&lt;br /&gt;
            String lpFileName, int dwDesiredAccess, int dwShareMode,&lt;br /&gt;
            ref SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition,&lt;br /&gt;
            int dwFlagsAndAttributes, IntPtr hTemplateFile );&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;I want to make a few notes about the way a win32 function is defined:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;   1. Use the &lt;strong&gt;extern&lt;/strong&gt; keywprd as it defines a function as external, meaning it is implemented outside the C# code.&lt;/div&gt;
&lt;div&gt;   2. Verify that the function definition matches its signature found in the DLL&lt;/div&gt;
&lt;div&gt;   3. Some functions return a handle or pointer.  In this case use the &lt;strong&gt;IntPtr&lt;/strong&gt; type since it represents a pointer/handle in the .Net world.&lt;/div&gt;
&lt;div&gt;   4. On a personal note, I like putting these definitions in its own class.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Once a win32 function is defined, we use it as follows:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;hFile = Win32Api.CreateFile (  &lt;br /&gt;
                fileName,                       // Filename &lt;br /&gt;
                desiredAccess,                  // Open Read/Write&lt;br /&gt;
                desiredShare,                   // Share Reading&lt;br /&gt;
                ref security_attributes,        // NULL Security new 15-May-2007&lt;br /&gt;
                OPEN_ALWAYS,                    // Creation attrib&lt;br /&gt;
                desiredAttrib,                  // File Attributes&lt;br /&gt;
                IntPtr.Zero  );                 // NULL  no template&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130800"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130800" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/130800.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/04/07/using-win32-api-in-c.aspx</guid>
            <pubDate>Tue, 07 Apr 2009 13:51:58 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/130800.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/04/07/using-win32-api-in-c.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/130800.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Adding items to a listview in C#</title>
            <link>http://geekswithblogs.net/jpl/archive/2009/04/05/adding-items-to-a-listview-in-c.aspx</link>
            <description>&lt;p&gt;I created a listview with two columns as part of a text C# solution to test the use of structures. This list was created with the IDE. When creating a list where you want to show multiple columns, set the listview's &lt;strong&gt;view&lt;/strong&gt; property to &lt;strong&gt;Details&lt;/strong&gt;.  I use the IDE to define the columns by selecting columns from the properties list.&lt;/p&gt;
&lt;p&gt;To fill in the listview before displaying it, I programmatically add the items in the form's &lt;strong&gt;LOAD&lt;/strong&gt; event.  &lt;/p&gt;
&lt;p&gt;BTW, I'm moving from VB.Net to C# and adding events to the form is different in C# from VB .Net. Rather than selecting the event from a drop-down list (as in VB), the event is pro grammatically defined as shown here:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;     this.Load += new EventHandler(frmL1Cmn_Load);&lt;br /&gt;
this.Activated += new EventHandler(frmL1Cmn_Activated); &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here's the generated callback&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;         void frmL1Cmn_Activated(object sender, EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
                 throw new NotImplementedException();&lt;br /&gt;
} &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But, to add this eventhandler is much different than VB.  After enter &lt;strong&gt;+=&lt;/strong&gt;, let the IDE instruct you to enter the TAB. It is at this point that the TAB key is depressed. Then, let the IDE prompt you one more time to hit the TAB key to generate the callback function. Select the TAB key a 2nd time and the callback function is generated.&lt;/p&gt;
&lt;p&gt;Coming back from this tangent, here's the code in the form's load callback function to populate the listview.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;         void frmL1Cmn_Load(object sender, EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
               try&lt;br /&gt;
               {&lt;br /&gt;
                       // Populate lstReadL1Ints with lngVals&lt;br /&gt;
                      lstReadL1Ints.BeginUpdate();&lt;br /&gt;
                      lstReadL1Ints.Items.Clear();&lt;br /&gt;
                      for (i = 0; i &amp;lt; 50; i++)&lt;br /&gt;
     {&lt;br /&gt;
                               ListViewItem row = new ListViewItem(i.ToString());&lt;br /&gt;
                               int j = i * 2;&lt;br /&gt;
                               row.SubItems.Add(l1CmnRec[i].lngVal[j].ToString());&lt;br /&gt;
                               lstReadL1Ints.Items.Add(row);&lt;br /&gt;
     }&lt;br /&gt;
                     lstReadL1Ints.EndUpdate();&lt;br /&gt;
                     lstReadL1Ints.Refresh();&lt;br /&gt;
              }&lt;br /&gt;
              catch (Exception ex)&lt;br /&gt;
               {&lt;br /&gt;
                      StringBuilder sb = new StringBuilder();&lt;br /&gt;
                      sb.Append("Cannot fill in Int listview. ex = ").Append(ex.Message);&lt;br /&gt;
     Console.WriteLine(sb.ToString());&lt;br /&gt;
   }&lt;br /&gt;
} &lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130763"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130763" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jpl/aggbug/130763.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jim Lahman</dc:creator>
            <guid>http://geekswithblogs.net/jpl/archive/2009/04/05/adding-items-to-a-listview-in-c.aspx</guid>
            <pubDate>Sun, 05 Apr 2009 20:50:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jpl/comments/130763.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jpl/archive/2009/04/05/adding-items-to-a-listview-in-c.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jpl/comments/commentRss/130763.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>