<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Blog</title><link>http://localhost:30321/blog</link><description>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac sapien felis. Cras mattis orci nulla. Vivamus elementum metus ut elit aliquet, et faucibus est laoreet. Quisque non aliquam orci. Nulla ex erat, suscipit at egestas vitae, pharetra aliquet ipsum. Integer fermentum ullamcorper ipsum, at convallis nibh venenatis eget. Morbi fringilla vestibulum neque, at imperdiet leo accumsan ac. Vestibulum semper neque vel tortor tincidunt sagittis. Integer consectetur diam ac hendrerit condimentum.</description><item><title>Voice of America Radiogram</title><link>http://localhost:30321/blog/voice-of-america-radiogram</link><description>&lt;p&gt;About two weeks ago I was lounging around in the backyard drinking an iced tea and reading the July issue of &lt;em&gt;QST&lt;/em&gt; when I stumbled on something I thought was really sweet.&amp;nbsp; The Voice of America is broadcasting weekly &lt;em&gt;radiograms&lt;/em&gt;!&amp;nbsp; I didn't even know the Voice of America was still in existence, so it was awesome to hear they are still around.&amp;nbsp; It's doubly-awesome because the Voice of America Radiogram is an all digital broadcast which means you need to be into digital modes to receive it and I am very into all things digital. My first attempt at googling the website for VOA landed me on the VOA News website here &lt;a href="http://www.voanews.com/" target="_blank"&gt;http://www.voanews.com&lt;/a&gt; - which is not what I was looking for.&amp;nbsp; (I should note however, there is a LISTEN button in the top right corner of the page that will allow you to listen to the VOA over the interwebs which is mildly interesting for a little while.)&amp;nbsp; Further research revealed the radiogram site is located at &lt;a href="http://voaradiogram.net" target="_blank"&gt;http://voaradiogram.net&lt;/a&gt;. Scanning around the page revealed the following transmission schedule (all days and times UTC):&lt;/p&gt;
&lt;blockquote&gt;Sat 0930-1000 5745 kHz Sat 1600-1630 17580 kHz Sun 0230-0300 5745 kHz Sun 1930-2000 15670 kHz&lt;/blockquote&gt;
&lt;p&gt;These seem to be standard times used every weekend (but don't take my word for it, check the VOA website before planning any activities).&amp;nbsp; The page also mentions the radiogram broadcast is transmitted from the Edward R. Murrow transmitting station in North Carolina. After futzing around converting UTC into local time, I discovered the Sunday 0230 UTC broadcast would be 7:30pm AZT which was just perfect!&amp;nbsp; I was less sure about picking up North Carolina from Arizona (a distance of approximately 1,800 miles), but I decided to give it a try.&lt;/p&gt;
&lt;h2&gt;Setting Up&lt;/h2&gt;
&lt;p&gt;My receiver for this experiment is a &lt;a href="https://www.amazon.com/Tecsun-PL-660-Portable-Shortwave-Single/dp/B004H9C4JK/ref=sr_1_1?ie=UTF8&amp;amp;qid=1469383823&amp;amp;sr=8-1&amp;amp;keywords=tecsun+pl-660" target="_blank"&gt;Tecsun PL660 'PLL World Band Receiver'&lt;/a&gt; connected to a 40meter-ish dipole antenna oriented east-west in my attic.&amp;nbsp; I say 40meter-ish because this antenna is approximately 66 feet long, but isn't used for transmitting and is connected to my radio by a rather rube-goldberg-esque run of feed line. The computer used is an old homebrew 2.4GHz Pentium 4 with 1 Gig of RAM running Windows XP SP3. As the Voice of America Radiogram website recommends, I downloaded and installed &lt;em&gt;fldigi&lt;/em&gt; available from &lt;a href="https://sourceforge.net/projects/fldigi/files/fldigi" target="_blank"&gt;https://sourceforge.net/projects/fldigi/files/fldigi&lt;/a&gt; and &lt;em&gt;flmsg&lt;/em&gt; from &lt;a href="https://sourceforge.net/projects/fldigi/files/flmsg" target="_blank"&gt;https://sourceforge.net/projects/fldigi/files/flmsg&lt;/a&gt;. I also found this bit of useful configuration information on the Voice of America Radiogram website:&lt;/p&gt;
&lt;blockquote&gt;"To make Flmsg work with Fldigi, in Fldigi: Configure &amp;gt; Misc &amp;gt; NBEMS &amp;gt; under Reception of flmsg files, select Open with flmsg and Open in browser, and below that indicate where your Flmsg.exe file is located &amp;ndash; probably somewhere in Program Files(x86)."&lt;/blockquote&gt;
&lt;h2&gt;Tuning In&lt;/h2&gt;
&lt;p&gt;My first step was to see (generally) what reception was like.&amp;nbsp; The Voice of America Radiogram was listed as broadcasting on 5745kHz, so I tuned to the &lt;a href="http://www.nist.gov/pml/div688/grp40/wwv.cfm" target="_blank"&gt;WWV&lt;/a&gt; beacon at 5000kHz to listen to Colorado for a little while.&amp;nbsp; WWV was audible but with some pronounced fading in and out, so I wasn't overly optimistic I was going to hear the VOA clearly enough to decode anything.&amp;nbsp; The audio is a little strained, but if you turn up your volume you can hear my reception of WWV in this video. &lt;iframe width="560" height="315" src="https://www.youtube.com/embed/ByplNsgfNOs" frameborder="0" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt; When 7:30 AZT finally rolled around I strained to hear anything and... nothing. I was starting to think I had the time wrong, or my flaky antenna arrangement wasn't up to the task, or the reception conditions weren't right, or... Then I heard the music and the infamous "Voice Of America" introduction and got goose bumps. &lt;iframe width="560" height="315" src="https://www.youtube.com/embed/tTkQXaL8mMc" frameborder="0" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt; After that, the whole shebang was almost idiot proof.&amp;nbsp; &lt;em&gt;fldigi&lt;/em&gt; started decoding &lt;a href="https://en.wikipedia.org/wiki/Multiple_frequency-shift_keying" target="_blank"&gt;MFSK32&lt;/a&gt; and I was kind of amazed how reliable it was.&amp;nbsp; Here you can see everything in action (with a brief shot of my PL660 about halfway through). &lt;iframe width="560" height="315" src="https://www.youtube.com/embed/FGL0Wcqifw8" frameborder="0" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt; As this portion of the program was about to wrap up, it occurred to me that some of the programs in the radiogram contain images.&amp;nbsp; I wanted to be sure I had a video of receiving my first image via MFSK32 but unlike the awesome slow scan television (SSTV) images I received from the ISS last year (&lt;a href="http://devmash.com/files/SSTV_Image1.jpg" target="_blank"&gt;Image1&lt;/a&gt;, &lt;a href="http://devmash.com/files/SSTV_Image6.jpg" target="_blank"&gt;Image6&lt;/a&gt;, &lt;a href="http://devmash.com/files/SSTV_Image8.jpg" target="_blank"&gt;Image8&lt;/a&gt;, &lt;a href="http://devmash.com/files/SSTV_Image9.jpg" target="_blank"&gt;Image9&lt;/a&gt;), the received image was a little underwhelming. I also recorded my reception of two other images from this radiogram.&amp;nbsp; If you are really interested, you can watch them all on YouTube. &lt;a href="https://youtu.be/qSOVv_6TQRE" target="_blank"&gt;VOA Radiogram 173 (4 of 7)&lt;/a&gt; &lt;a href="https://youtu.be/e0sJFwdy-as" target="_blank"&gt;VOA Radiogram 173 (5 of 7)&lt;/a&gt; &lt;a href="https://youtu.be/kfXVfwgiPRA" target="_blank"&gt;VOA Radiogram 173 (6 of 7)&lt;/a&gt; The final portion of the program was an encoded HTML message about the Kepler Space Telescope.&amp;nbsp; This is where &lt;em&gt;flmsg&lt;/em&gt; comes into play.&amp;nbsp; It looks like the message is encoded and transmit as a Base64 string, which is then decoded and launched in your favorite web browser.&amp;nbsp; I'm doing some extrapolation here, I don't know how the data is encoded for sure, but when you see something like this&lt;/p&gt;
&lt;blockquote&gt;&amp;lt;transfer&amp;gt; [b64:start]&lt;/blockquote&gt;
&lt;p&gt;it sure &lt;em&gt;smells&lt;/em&gt; like Base64 encoding.&amp;nbsp; After looking at the received HTML document, its a bit of a cheat.&amp;nbsp; Yes, the HTML was received via MFSK32 but the linked image and (obviously) hyperlinked content point to URLs on the interwebs, which (to me) feels like it violates the spirit of the whole thing.&amp;nbsp; You can see the decoded HTML message thanks to the wonderful folks at YouTube. &lt;a href="https://youtu.be/8qvuxZwqxGY" target="_blank"&gt;VOA Radiogram 173 (7 of 7)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Winding Down&lt;/h2&gt;
&lt;p&gt;I never expected that I would be able to copy the entire program without any data loss.&amp;nbsp; The images looked a bit sketchy, but these days any image that's only 200x180 pixels with artifacts looks pretty bad.&amp;nbsp; You just have to remind yourself &lt;em&gt;how&lt;/em&gt; you received those sketchy looking images.&amp;nbsp; That's the cool part. I made sure to capture my audio with &lt;em&gt;fldigi&lt;/em&gt; and have provided a download link to the audio and the full broadcast text below.&amp;nbsp; I was unable to figure out how to 'save' the received images with &lt;em&gt;fldigi&lt;/em&gt;, so I unfortunately don't have any links for the received images, but trust me, your not missing anything. &lt;a href="http://devmash.com/files/VOA_Radiogram_173.txt" target="_blank"&gt;VOA Radiogram 173 Text&lt;/a&gt; &lt;a href="http://devmash.com/files/VOA_Radiogram_173.wav" target="_blank"&gt;VOA Radiogram 173 Audio&lt;/a&gt; All in all, this was a great first-time experience with receiving MFSK32.&amp;nbsp; If you've never done it, the VOA Radiogram is a fantastic way to get your feet wet.&amp;nbsp; I highly recommend giving it a try! &lt;strong&gt;73&lt;/strong&gt;&lt;/p&gt;</description><pubDate>Sun, 24 Jul 2016 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/voice-of-america-radiogram</guid></item><item><title>Retrocomputing StackExchange</title><link>http://localhost:30321/blog/retrocomputing-stackexchange</link><description>&lt;p&gt;Just a quick note, StackExchange now has a Retrocomputing site in beta.&amp;nbsp; I almost never sign up for anything on the interwebs.&amp;nbsp; I don't face-space or my-book or twit-trist or any of that nonsense.&amp;nbsp; But I &lt;em&gt;had&lt;/em&gt; to join this one... Check it out! &lt;a href="http://retrocomputing.stackexchange.com/" target="_blank"&gt;http://retrocomputing.stackexchange.com/&lt;/a&gt; &amp;nbsp; &amp;nbsp;&lt;/p&gt;</description><pubDate>Fri, 22 Jul 2016 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/retrocomputing-stackexchange</guid></item><item><title>Non-blocking semaphore to avoid reentrancy in&amp;nbsp;.NET</title><link>http://localhost:30321/blog/non-blocking-semaphore-to-avoid-reentrancy-in-nbsp-net</link><description>&lt;p&gt;Here is a small programming tip I thought I would share. Sometimes in .NET / C# I find myself needing to write a pattern similar to this:&lt;/p&gt;
&lt;pre class="lang:c# decode:true " title="A simple semaphore (not thread safe)"&gt;private bool m_bSemaphore = false;

private void DoSomethingCrazy()
{
   if (m_bSemaphore == false)
   {
      m_bSemaphore = true;
      //Do some crazy stuff
      m_bSemaphore = false;
   }
}&lt;/pre&gt;
&lt;p&gt;This intent of this code would be to prevent the DoSomethingCrazy() method from being executed simultaneously.&amp;nbsp; The first thread to invoke DoSomethingCrazy() would set the semaphore and all subsequent calls from other threads would be ignored until the semaphore is reset. The problem with the code above is that it is not thread safe.&amp;nbsp; It is possible two competing threads could both execute the IF clause and decide the semaphore is false at exactly the same time.&amp;nbsp; The entire point of the semaphore is to prohibit this from happening, so the code above is actually a very subtle bug waiting to happen.&amp;nbsp; Most of the time it's going to work, but there is that small chance things are going to go wonky when least expected. A more robust solution which is thread-safe would be to craft the logic similar to this:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="An improved semaphore (thread safe)"&gt;private object m_objSyncLock = new object();

private void DoSomethingCrazy()
{
   if (Monitor.TryEnter(m_objSyncLock))
   {
      //DoCrazyStuff
      Monitor.Exit(m_objSyncLock);
   }
}
&lt;/pre&gt;
&lt;p&gt;By using the .NET static Monitor class makes we make the testing of the lock (TryEnter) &lt;em&gt;and&lt;/em&gt; the acquisition of the lock into a single atomic operation (ie. only 1 thread can do both steps at a time). &amp;nbsp;&lt;/p&gt;
&lt;h6 style="text-align: center;"&gt;&lt;img class="aligncenter size-full wp-image-126" src="http://www.devmash.com/main/wp-content/uploads/2015/08/Pinwheel-48x48.png" alt="devMash.com Pinwheel" width="48" height="48" /&gt;&lt;span style="color: #999999;"&gt;article copyright &amp;copy; 2015 devMash.com&lt;/span&gt; &lt;span style="color: #999999;"&gt; &lt;/span&gt;&lt;/h6&gt;</description><pubDate>Fri, 29 Jan 2016 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/non-blocking-semaphore-to-avoid-reentrancy-in-nbsp-net</guid></item><item><title>Get duration using Media Foundation and C#</title><link>http://localhost:30321/blog/get-duration-using-media-foundation-and-c</link><description>&lt;p&gt;I was sidetracked today by a rather interesting problem; How to get duration using Media Foundation and C#?&amp;nbsp; I've worked on several projects over the years where I needed a simple method to get the duration of a multimedia file.&amp;nbsp; In the past I turned to DirectShow but this time I wanted to get the duration using Media Foundation and I wanted the code to be written in C#. After wandering around the Media Foundation documentation for a while, I discovered an article titled &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd389281%28v=vs.85%29.aspx" target="_blank"&gt;Using the Source Reader to Process Media Data&lt;/a&gt;.&amp;nbsp; The interesting bit was the section called &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd389281%28v=vs.85%29.aspx#getting_file_duration" target="_blank"&gt;Getting the File Duration&lt;/a&gt; which served as a starting point for my implementation.&lt;/p&gt;
&lt;h2&gt;The Method&lt;/h2&gt;
&lt;p&gt;Enough talk.&amp;nbsp; Lets jump straight in.&amp;nbsp; Here is the finished method:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="The GetDuration() method"&gt;public double GetDuration(string filename)
{

    double duration = double.NaN;

    const int S_OK = 0;
    const uint MEDIA_SOURCE = 0xFFFFFFFF;

    int hr;

    //Startup media foundation 
    hr = MFInterop.MFStartup(MFStartupFlags.Full);
    if (hr == S_OK)
    {

        //Create source reader
        IMFSourceReader sourceReader;
        if (S_OK == MFInterop.MFCreateSourceReaderFromURL(filename, null, out sourceReader))
        {

            Guid MF_PD_DURATION = new Guid("6C990D33-BB8E-477A-8598-0D5D96FCD88A");

            //The duration timebase is 100-nanosecond units
            double timebase = 10 * 1000 * 1000;

            //Get the multimedia duration 
            PropVariant propVariant;
            sourceReader.GetPresentationAttribute(MEDIA_SOURCE, MF_PD_DURATION, out propVariant);
            if (propVariant.Type == System.Runtime.InteropServices.VarEnum.VT_UI8)
            {
                duration = ((ulong)propVariant.Value) / timebase;
            }
            propVariant.Clear();

        }

        //Shutdown media foundation
        MFInterop.MFShutdown();

    }
    return duration;
}&lt;/pre&gt;
&lt;p&gt;The method itself is relatively simple, but gathering the supported enumerations, interfaces, and structures takes a bit of research and know-how.&amp;nbsp; I am going to discuss how I found each of these required elements in due course, but if you are on a deadline and want to push the easy button you can find a working example solution for Visual Studio 2013 at the bottom of this article.&lt;/p&gt;
&lt;h2&gt;Startup and Shutdown&lt;/h2&gt;
&lt;p&gt;You can see in the GetDuration method that we are required to startup and shutdown Media Foundation.&amp;nbsp; If we neglect this step our method will fail to work properly.&amp;nbsp; I like to create a static utility class named MFInterop to house my external function calls.&amp;nbsp; I find this a handy way to group all my external calls together and I can easily add more declarations when needed.&amp;nbsp; It looks like this:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="MFInterop"&gt;using System.Security;

public static class MFInterop
{

    [DllImport("mfplat.dll", ExactSpelling = true), SuppressUnmanagedCodeSecurity]
    public static extern int MFShutdown();

    [DllImport("mfplat.dll", ExactSpelling = true), SuppressUnmanagedCodeSecurity]
    private static extern int MFStartup
    (
        int Version,
        MFStartupFlags dwFlags
    );

    public static int MFStartup(MFStartupFlags objFlags)
    {
        int MF_VERSION = 0x20070;
        return MFInterop.MFStartup(MF_VERSION, objFlags);
    }

}&lt;/pre&gt;
&lt;p&gt;and the MFStartupFlags enumeration:&lt;/p&gt;
&lt;pre class="lang:c# decode:true " title="MFStartupFlags"&gt;public enum MFStartupFlags
{
    Full = 0,
    Lite = 1,
    NoSocket = 1
}&lt;/pre&gt;
&lt;p&gt;I had to scrounge around the header files to figure out the values for MF_VERSION and MFStartupFlags.&amp;nbsp; Instead of making MFStartup public, I instead chose to write a small wapper method that encapsulated the version information.&amp;nbsp; You can find the documentation for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702238%28v=vs.85%29.aspx" target="_blank"&gt;MFStartup&lt;/a&gt; and &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms694273%28v=vs.85%29.aspx" target="_blank"&gt;MFShutdown&lt;/a&gt; in the Microsoft Media Foundation Programming Reference. It is worth pointing out that you would probably want to initialize Media Foundation one time in your startup logic, and correspondingly shutdown when your application exits.&amp;nbsp; Putting the startup and shutdown logic directly into our method isn't terribly efficient.&lt;/p&gt;
&lt;h2&gt;IMFSourceReader&lt;/h2&gt;
&lt;p&gt;To get the media duration we are going to need an &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; interface and according to the documentation, we can use &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd388110%28v=vs.85%29.aspx" target="_blank"&gt;MFCreateSourceReaderFromURL&lt;/a&gt; to get one.&amp;nbsp; Let's add another static external declaration to our MFInterop class, like this:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="MFCreateSourceReaderFromURL"&gt;[DllImport("mfreadwrite.dll", ExactSpelling = true), SuppressUnmanagedCodeSecurity]
public static extern int MFCreateSourceReaderFromURL
(
    [In, MarshalAs(UnmanagedType.LPWStr)] string pwszURL,
    IMFAttributes pAttributes,
    out IMFSourceReader ppSourceReader
);&lt;/pre&gt;
&lt;p&gt;This is where things start to get interesting.&amp;nbsp; You will discover very quickly that Media Foundation methods expect to work with Media Foundation interfaces, and Media Foundation interfaces will reference various enumerations, structures, and further interfaces.&amp;nbsp; Each time you declare one you create a need to declare three more.&amp;nbsp; It feels almost viral trying to get everything declared properly.&amp;nbsp; Fortunately for the purposes of this article, we only have to declare a few things.&lt;/p&gt;
&lt;h2&gt;Jiggery Pokery&lt;/h2&gt;
&lt;p&gt;But where do we look to find a C# declaration for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; or &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt;? It took me a while to figure this part out.&amp;nbsp; The answer lies in understanding IDL files, type libraries and interop assemblies.&amp;nbsp; I don't pretend to be a C++ guru, and when people start throwing around terms like interop, IDL, and type libraries my eyes start to go a little out of focus.&amp;nbsp; But after a bit of jiggery pokery, I discovered it's actually not that difficult to get the IDE to do the heavy lifting for us.&lt;/p&gt;
&lt;p class=""&gt;The first thing we need to locate is a file called Mfobjects.idl.&amp;nbsp; On my machine, this file was located at&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include&lt;/p&gt;
&lt;p&gt;If you open the Mfobjects.idl file in your favorite text editor and snoop around, you will find the interface declaration for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt;.&amp;nbsp; Everything you need to know is right there; but it is unfortunately written in the wrong language.&amp;nbsp; What we need is an easy way to convert the IDL version of the interface into a C# version we can use in our project.&amp;nbsp; After a few hits and misses I discovered that we can use some of the command line tools included with Visual Studio to generate a type library (TLB) from the IDL and then generate an interop assembly from the type library.&amp;nbsp; Finally, we can use our favorite reflection tool to examine the interop assembly and look at the C#. Still with me?&amp;nbsp; Excellent.&amp;nbsp; Everyone get out your command lines...&lt;/p&gt;
&lt;h2&gt;MIDL&lt;/h2&gt;
&lt;p&gt;Start by opening the Visual Studio Native Tools Command Prompt.&amp;nbsp; If you use a standard Command Prompt you will have to add the path for the Microsoft tools manually or change directory to the location of the tools on your hard drive.&amp;nbsp; Try typing MIDL at the command prompt and you should get some output like this:&lt;/p&gt;
&lt;pre class="nums:false lang:batch highlight:0 decode:true" title="MIDL"&gt;C:\&amp;gt;midl
Microsoft (R) 32b/64b MIDL Compiler Version 8.00.0603
Copyright (c) Microsoft Corporation. All rights reserved.
midl : command line error MIDL1000 : missing source-file name&lt;/pre&gt;
&lt;p&gt;As I understand it, IDL is an Interface Definition Language developed by Microsoft to define interfaces for COM objects.&amp;nbsp; It has always been one of those technologies that dances on the periphery of my skill set.&amp;nbsp; I won't pretend to explain or even understand IDL but I will tell you that with a bit of tweaking to the Mfobjects.idl file we can easily create our type library. My approach was to first make a copy of the Mfobjects.idl so I could safely screw things up without permanent damage.&lt;/p&gt;
&lt;pre class="nums:false lang:batch highlight:0 decode:true" title="MIDL"&gt;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include&amp;gt;mkdir c:\temp
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include&amp;gt;copy mfobjects.idl c:\temp
     1 file(s) copied.
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include&amp;gt;cd c:\temp
c:\temp&amp;gt;&lt;/pre&gt;
&lt;p&gt;For some reason, the MIDL tool can only generate a type library for IDL files that conform to a specific format.&amp;nbsp; Of course, all the IDL files we are going to play with don't seem to have the magic bits that the MIDL tool requires, so we are going to add them manually.&amp;nbsp;&amp;nbsp; It's dead simple, here is all we need to do:&lt;/p&gt;
&lt;pre class="lang:default mark:10 decode:true" title="IDL Wrapper"&gt;[
uuid(4A3AE19D-C636-44B2-B554-10B87BF7E6EE),
lcid(0x00),
version(1.0),
helpstring("devMash mfobjects type library")
]
library dm_mfobjects
{
    INSERT ORIGINAL FILE CONTENTS HERE 
}&lt;/pre&gt;
&lt;p&gt;As you can see, we simply place the original file contents in between the curly braces.&amp;nbsp; One thing you will want to be cautious about is the UUID.&amp;nbsp; Use the Create Guid tool in Visual Studio to create a unique Guid for each type library you decide to generate.&amp;nbsp; It is also a good idea to give your type library a unique name and help string so you can easily identify it later. Save the changes to your &lt;em&gt;&lt;span style="color: #000000;"&gt;copy &lt;/span&gt;&lt;/em&gt;of Mfobjects.idl (we don't want any accidents!) and let's generate our type library:&lt;/p&gt;
&lt;pre class="nums:false trim-whitespace:false lang:batch mark:5 highlight:0 decode:true" title="MIDL"&gt;c:\temp&amp;gt;midl Mfobjects.idl /tlb Mfobjects.tlb
Microsoft (R) 32b/64b MIDL Compiler Version 8.00.0603
Copyright (c) Microsoft Corporation. All rights reserved.
    MIDL OUTPUT REMOVED FOR BREVITY
c:\temp&amp;gt;dir
08/25/2015  04:42 AM           153,410 Mfobjects.idl
08/25/2015  04:46 AM            81,260 Mfobjects.tlb&lt;/pre&gt;
&lt;p&gt;After entering the MIDL command above you will see some output scroll by.&amp;nbsp; You can safely ignore it as it appears to be nothing more than a list of external IDL files and headers that were referenced by Mfobjects.idl.&amp;nbsp; Do a directory and if all is well you will see we have created a new file called Mfobjects.tlb.&lt;/p&gt;
&lt;h2&gt;TLBIMP&lt;/h2&gt;
&lt;p&gt;Now that we have a type library we need to generate an interop assembly.&amp;nbsp; This step is pretty easy:&lt;/p&gt;
&lt;pre class="nums:false lang:c# mark:5 highlight:0 decode:true" title="TLBIMP"&gt;c:\temp&amp;gt;tlbimp Mfobjects.tlb /out:Mfobjects.dll
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.0.30319.33440
Copyright (C) Microsoft Corporation.  All rights reserved.
    TLBIMP OUTPUT REMOVED FOR BREVITY
c:\temp&amp;gt;dir
08/25/2015  04:42 AM           153,410 Mfobjects.idl
08/25/2015  04:46 AM            81,260 Mfobjects.tlb
08/25/2015  05:09 AM            42,496 Mfobjects.dll&lt;/pre&gt;
&lt;p&gt;You will probably see a lot of warnings scroll by when generating the interop assembly.&amp;nbsp; I happily ignored this and pressed on into the fog bank with absolute confidence.&amp;nbsp; You can too.&lt;/p&gt;
&lt;h2&gt;Reflection&lt;/h2&gt;
&lt;p&gt;For our next step you are going to need a reflection tool like &lt;a href="http://www.red-gate.com/products/dotnet-development/reflector/" target="_blank"&gt;Red Gate's .NET Reflector&lt;/a&gt; or &lt;a href="http://www.telerik.com/products/decompiler.aspx" target="_blank"&gt;Telerik's JustDecompile&lt;/a&gt;.&amp;nbsp; I am partial to .NET Reflector because I have used it for years and it is conveniently bundled with other Red Gate products that I own.&amp;nbsp; If you don't already have a favorite reflection tool, JustDecompile is free and is a quality product but you have to create an account and sign up to do the install.&amp;nbsp; I am sure there are other tools out there that would work equally well. Once you have settled on a tool you are happy with, simply open the interop assembly we generated earlier.&amp;nbsp; In .NET Reflector this is done via the usual File-&amp;gt;Open metaphor.&amp;nbsp; If all has gone well, you should be able to see your assembly in a treeview navigation panel, and if you expand a few nodes you will eventually come across the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; interface. In most reflection tools, selecting the node in the tree (clicking on &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt;) will cause the associated code to be displayed in the main window.&amp;nbsp; Some tools offer options about what language (VB, C#, etc.) and what version of .NET you would like to target. You should be able to see something similar to this: [caption id="attachment_84" align="aligncenter" width="1243"]&lt;a href="http://www.devmash.com/main/wp-content/uploads/2015/08/Reflector.png"&gt;&lt;img class="wp-image-84 size-full" src="http://www.devmash.com/main/wp-content/uploads/2015/08/Reflector.png" alt="Using .NET Reflector to display the IMFMediaAttributes interface" width="1243" height="907" /&gt;&lt;/a&gt; Using .NET Reflector to display the IMFMediaAttributes interface[/caption] Simply select the decompiled code for the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; interface and paste it into your Visual Studio project.&amp;nbsp; Viola!&amp;nbsp; Well, almost Viola. Don't forget to add the following using clauses:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="Using clauses"&gt;using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;&lt;/pre&gt;
&lt;h2&gt;Stragglers&lt;/h2&gt;
&lt;p&gt;If this code is ever going to compile, we are going to have to cleanup the remaining stragglers.&amp;nbsp; The &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; interface contains methods which in turn make references to &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt;, &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms694854%28v=vs.85%29.aspx" target="_blank"&gt;MF_ATTRIBUTE_TYPE&lt;/a&gt; and &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms703793%28v=vs.85%29.aspx" target="_blank"&gt;MF_ATTRIBUTES_MATCH_TYPE&lt;/a&gt;.&amp;nbsp; The last two are simply enumerations and are easy enough to lookup but we are going to have to ignore &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; for a little while. When I migrate enumerations from C++ to C# I like to do a little refactoring.&amp;nbsp; Generally, I will camel-case the naming and remove any redundant prefixing that made sense in C++ but is out of place in C#.&amp;nbsp; Also, I have a tendency to look up actual values from the headers and incorporate them directly.&amp;nbsp; For example, here is the original enum for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms694854%28v=vs.85%29.aspx" target="_blank"&gt;MF_ATTRIBUTE_TYPE&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="lang:c++ decode:true" title="MF_ATTRIBUTE_TYPE"&gt;typedef enum _MF_ATTRIBUTE_TYPE { 
  MF_ATTRIBUTE_UINT32    = VT_UI4,
  MF_ATTRIBUTE_UINT64    = VT_UI8,
  MF_ATTRIBUTE_DOUBLE    = VT_R8,
  MF_ATTRIBUTE_GUID      = VT_CLSID,
  MF_ATTRIBUTE_STRING    = VT_LPWSTR,
  MF_ATTRIBUTE_BLOB      = VT_VECTOR | VT_UI1,
  MF_ATTRIBUTE_IUNKNOWN  = VT_UNKNOWN
} MF_ATTRIBUTE_TYPE;&lt;/pre&gt;
&lt;p&gt;and here is my version in C#&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="MFAttributeType"&gt;public enum MFAttributeType
{
    UINT32 = 0x13,  // VT_UI4
    UINT64 = 0x15,  // VT_UI8
    DOUBLE = 5,     // VT_R8
    GUID = 0x48,    // VT_CLSID
    STRING = 0x1f,  // VT_LPWSTR
    BLOB = 0x1011,  // VT_VECTOR | VT_UI1
    IUNKNOWN = 13   // VT_UNKNOWN
}&lt;/pre&gt;
&lt;p&gt;This is obviously a matter of style, but you get the general idea. That takes care of the most of the stragglers, but we still have those pesky &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; references.&amp;nbsp; Again, let's defer addressing that particular problem just now.&lt;/p&gt;
&lt;h2&gt;Rinse and Repeat&lt;/h2&gt;
&lt;p&gt;If you remember, we were trying to simply declare interfaces for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; and &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; so we could execute the Media Foundation call &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd388110%28v=vs.85%29.aspx" target="_blank"&gt;MFCreateSourceReaderFromURL&lt;/a&gt;.&amp;nbsp; It's been a long road and we only have a partial &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; interface to show for all of our hard work.&amp;nbsp; But this kind of work is like rolling a snowball down a hill.&amp;nbsp; Once you get started it goes faster and faster. At this point you might be tempted to think copying the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; interface will be a simple matter.&amp;nbsp; Unfortunately you will quickly discover that the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; interface does not appear to be defined in Mfobjects.idl.&amp;nbsp; Instead it is found in Mfreadwrite.idl.&amp;nbsp; So we will need to generate a type library and interop assembly for Mfreadwrite.idl in exactly the same way we did for Mfobjects.idl. After generating an interop assembly for Mfreadwrite.idl, you can open it in your favorite reflection tool and copy/paste the interface declaration for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; into your C# project. Notice that the interface declaration for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; includes several methods which reference to two more interfaces, &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704850%28v=vs.85%29.aspx" target="_blank"&gt;IMFMediaType&lt;/a&gt; and &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702192%28v=vs.85%29.aspx" target="_blank"&gt;IMFSample&lt;/a&gt;, as well as our hanging &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; problem. A quick look in our reflector reveals &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704850%28v=vs.85%29.aspx" target="_blank"&gt;IMFMediaType&lt;/a&gt; was part of Mfreadwrite.idl, and so we can easily copy the interface declaration without have to resort to further conversions.&amp;nbsp; Don't forget to clean up &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms694854%28v=vs.85%29.aspx" target="_blank"&gt;MF_ATTRIBUTE_TYPE&lt;/a&gt; and &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms703793%28v=vs.85%29.aspx" target="_blank"&gt;MF_ATTRIBUTES_MATCH_TYPE&lt;/a&gt; after copying, and please continue to patiently ignore those darn &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; references. The same holds true for &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702192%28v=vs.85%29.aspx" target="_blank"&gt;IMFSample&lt;/a&gt;, simply copy and cleanup.&amp;nbsp; Notice &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702192%28v=vs.85%29.aspx" target="_blank"&gt;IMFSample&lt;/a&gt; makes a reference to &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms696261%28v=vs.85%29.aspx" target="_blank"&gt;IMFMediaBuffer&lt;/a&gt; so we are going to need to get that interface also, which is also conveniently found in our interop assembly. (If you notice the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt; interface can also be found in our interop assembly for Mfreadwrite.idl, but we had no way of knowing that when we started.) You should now have the following interfaces:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598%28v=vs.85%29.aspx" target="_blank"&gt;IMFAttributes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms696261%28v=vs.85%29.aspx" target="_blank"&gt;IMFMediaBuffer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704850%28v=vs.85%29.aspx" target="_blank"&gt;IMFMediaType&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702192%28v=vs.85%29.aspx" target="_blank"&gt;IMFSample&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and the following enumerations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms703793%28v=vs.85%29.aspx" target="_blank"&gt;MFAttributesMatchType&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms694854%28v=vs.85%29.aspx" target="_blank"&gt;MFAttributeType&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;MFStartupFlags&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;with the only remaining errors related to...&lt;/p&gt;
&lt;h2&gt;PROPVARIANT&lt;/h2&gt;
&lt;p&gt;The &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; structure is deserving of it's own article.&amp;nbsp; It's a verbose and ugly looking structure with a C++ Union occupying half the declaration.&amp;nbsp; I was confident that given some time and experimentation the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; could be ported to C#.&amp;nbsp; It would make an interesting topic to write about and much to my delight I discovered an excellent article has already been written titled &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/interop-with-propvariants-in-net.aspx" target="_blank"&gt;Interop with PROPVARIANTs in .NET&lt;/a&gt; by Adam Root. After reading through Adam's article a few times to get the gist of it, we can copy his &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/propvariant-cs.aspx" target="_blank"&gt;PropVariant&lt;/a&gt; structure without modification directly into out project.&amp;nbsp; All that should remain is refactoring the &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" target="_blank"&gt;PROPVARIANT&lt;/a&gt; references found in our copied interfaces to use &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/propvariant-cs.aspx" target="_blank"&gt;PropVariant&lt;/a&gt;. With some luck, your code should now compile but we aren't done yet.&lt;/p&gt;
&lt;h2&gt;Getting the Duration, Finally!&lt;/h2&gt;
&lt;p&gt;We had to do a lot of work to create an instance of a new &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; but it's about to pay off. The &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374655%28v=vs.85%29.aspx" target="_blank"&gt;IMFSourceReader&lt;/a&gt; exposes a method called &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374662%28v=vs.85%29.aspx" target="_blank"&gt;GetPresentationAttribute&lt;/a&gt; which according to the Media Foundation documentation, "gets an attribute from the underlying media source".&amp;nbsp; To call &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374662%28v=vs.85%29.aspx" target="_blank"&gt;GetPresentationAttribute&lt;/a&gt; we will need to pass two parameters; the stream index and a presentation descriptor attribute. For our purposes the stream index is quite simple and according to the documentation it is easily declared:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="MEDIA_SOURCE"&gt;const uint MEDIA_SOURCE = 0xFFFFFFFF;&lt;/pre&gt;
&lt;p&gt;For the second parameter we will need to consult the documentation and examine the list of possible &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa367736%28v=vs.85%29.aspx" target="_blank"&gt;Presentation Descriptor Attributes&lt;/a&gt; that we can use with &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374662%28v=vs.85%29.aspx" target="_blank"&gt;GetPresentationAttribute&lt;/a&gt;.&amp;nbsp;&amp;nbsp; A quick look will reveal &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702060%28v=vs.85%29.aspx" target="_blank"&gt;MF_PD_DURATION&lt;/a&gt; can be used to get the duration in 100-nanosecond units. &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa367736%28v=vs.85%29.aspx" target="_blank"&gt;Presentation Descriptor Attributes&lt;/a&gt; are declared as Guids so we have to look in mfidl.h to find the actual definition:&lt;/p&gt;
&lt;pre class="lang:c++ decode:true" title="MF_PD_DURATION"&gt;EXTERN_GUID( MF_PD_DURATION, 0x6c990d33, 0xbb8e, 0x477a, 0x85, 0x98, 0xd, 0x5d, 0x96, 0xfc, 0xd8, 0x8a );&lt;/pre&gt;
&lt;p&gt;converting this to C# gives us:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="MF_PD_DURATION"&gt;Guid MF_PD_DURATION = new Guid("6C990D33-BB8E-477A-8598-0D5D96FCD88A");&lt;/pre&gt;
&lt;p&gt;The output from &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374662%28v=vs.85%29.aspx" target="_blank"&gt;GetPresentationAttribute&lt;/a&gt; will be a &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/propvariant-cs.aspx" target="_blank"&gt;PropVariant&lt;/a&gt; containing the duration in 100-nanosecond units.&amp;nbsp; A nanosecond is a billionth of a second or 10&lt;sup&gt;&amp;minus;9&lt;/sup&gt; seconds.&amp;nbsp; Therefore a 100-nanosecond unit is actually one ten-millionth of a second or&amp;nbsp;10&lt;sup&gt;&amp;minus;7&lt;/sup&gt; seconds.&amp;nbsp; We can express the timebase like this:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="Defining the timebase"&gt;double timebase = 10 * 1000 * 1000;&lt;/pre&gt;
&lt;p&gt;and finally invoke&amp;nbsp;&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374662%28v=vs.85%29.aspx" target="_blank"&gt;GetPresentationAttribute&lt;/a&gt; like this:&lt;/p&gt;
&lt;pre class="lang:c# decode:true" title="GetPresentationAttribute"&gt;PropVariant propVariant;
sourceReader.GetPresentationAttribute(MEDIA_SOURCE, MF_PD_DURATION, out propVariant);
if (propVariant.Type == System.Runtime.InteropServices.VarEnum.VT_UI8)
{
    duration = ((ulong)propVariant.Value) / timebase;
}
propVariant.Clear();&lt;/pre&gt;
&lt;p&gt;If all has gone according to plan &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374662%28v=vs.85%29.aspx" target="_blank"&gt;GetPresentationAttribute&lt;/a&gt; should return a valid &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/propvariant-cs.aspx" target="_blank"&gt;PropVariant&lt;/a&gt; structure with a Type of &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms221170%28v=vs.85%29.aspx" target="_blank"&gt;VT_UI8&lt;/a&gt;, which is really just a 64-bit unsigned long.&amp;nbsp; Dividing the returned value by our timebase will yield the duration in seconds.&amp;nbsp; Lastly we should release our &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/propvariant-cs.aspx" target="_blank"&gt;PropVariant&lt;/a&gt; by calling the Clear method. You now have the duration in seconds! Huzzah!&lt;/p&gt;
&lt;h2&gt;Source Code&lt;/h2&gt;
&lt;p&gt;I've created an example project in Visual Studio 2013 targeting the .NET framework 4.5 called &lt;a href="http://devmash.com/files/GetDuration.zip" target="_blank"&gt;GetDuration.zip&lt;/a&gt;.&amp;nbsp; This example contains all the source code discussed in this article; including the &lt;a href="http://blogs.msdn.com/b/adamroot/archive/2008/04/11/propvariant-cs.aspx" target="_blank"&gt;PropVariant&lt;/a&gt; structure written by Adam Root.&amp;nbsp; The project is released under the &lt;a href="http://mit-license.org/" target="_blank"&gt;MIT License&lt;/a&gt; so you can use it as a starting point for your own Media Foundation projects in C#.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hopefully this article has helped you to learn how you can get duration using Media Foundation and C#.&amp;nbsp; We have covered how to reference external Media Foundation methods, how to look up and translate Media Foundation enumerations and how generate Media Foundation interface definitions using various Visual Studio Native Command Line tools and reflection.&amp;nbsp; You should now have a good foundation to build on while developing your own Media Foundation applications using C#. &amp;nbsp;&lt;/p&gt;
&lt;h6 style="text-align: center;"&gt;&lt;img class="aligncenter size-full wp-image-126" src="http://www.devmash.com/main/wp-content/uploads/2015/08/Pinwheel-48x48.png" alt="devMash.com Pinwheel" width="48" height="48" /&gt;&lt;span style="color: #999999;"&gt;article copyright &amp;copy; 2015 devMash.com&lt;/span&gt; &lt;span style="color: #999999;"&gt;example project released under the MIT License &lt;/span&gt;&lt;/h6&gt;</description><pubDate>Sat, 29 Aug 2015 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/get-duration-using-media-foundation-and-c</guid></item><item><title>FLEX-1500 Software Defined Radio</title><link>http://localhost:30321/blog/flex-1500-software-defined-radio</link><description>&lt;p&gt;I have been exposed to amateur radio all of my life.&amp;nbsp; Some of my earliest memories are of myself and my Dad playing with his old Hallicrafters SX 110.&amp;nbsp; When I was 13 (with a lot of encouragement and help) I managed to get my Novice license and I have been continuously licensed ever since.&amp;nbsp; However, I also discovered the magic of computer programming about the same time.&amp;nbsp; The latter became an obsession while the former faded into background noise. &amp;nbsp; [caption id="attachment_100" align="aligncenter" width="640"]&lt;a href="http://www.devmash.com/main/wp-content/uploads/2015/08/Wayback-Shack.jpg"&gt;&lt;img class="wp-image-100 size-full" src="http://www.devmash.com/main/wp-content/uploads/2015/08/Wayback-Shack.jpg" alt="A picture of my father in the Wayback Shack listening to his Hallicrafters SX-110 receiver. Also pictured is his original Heathkit DX-60 transmitter." width="640" height="486" /&gt;&lt;/a&gt; Dad in the Wayback Shack[/caption] About 2 years ago I decided to upgrade my hopelessly out-of-date Novice license to Technician and even more recently upgraded to General.&amp;nbsp; I even managed to convince my Dad to come along and get his General at the same time, which was great fun!&amp;nbsp; This flourish of activity has naturally left us both thinking about getting a new rig.&amp;nbsp; While we seem to have lots of radios kicking around, even some transmitters, nothing quite fits the bill.&amp;nbsp; We do have the Heathkit my Dad built in the early 1980's, but it never quite worked properly.&amp;nbsp; It's on my list as an "electronics" &amp;amp; "retrotech" project someday. &amp;nbsp; [caption id="attachment_101" align="aligncenter" width="640"]&lt;a href="http://www.devmash.com/main/wp-content/uploads/2015/08/Heathkit-Tranceiver.jpg"&gt;&lt;img class="wp-image-101" src="http://www.devmash.com/main/wp-content/uploads/2015/08/Heathkit-Tranceiver.jpg" alt="A picture of my Dad's original Heathkit HW-101 transceiver." width="640" height="480" /&gt;&lt;/a&gt; Heathkit HW-101 Transceiver[/caption] So we are on the lookout for a new radio.&amp;nbsp; We've been flipping through QST and reading blog posts but so far the vision is still a bit foggy. I'm slowly assembling a mental inventory of attributes like power and frequencies and modes and...&amp;nbsp; well, there is a lot to consider.&amp;nbsp; Anyway, I randomly found this video on Youtube yesterday.&amp;nbsp; It's a short &lt;a href="http://www.arrl.org/" target="_blank"&gt;ARRL&lt;/a&gt; review of the &lt;a href="http://www.flexradio.com/amateur-products/flex-series/flex-1500/" target="_blank"&gt;FLEX-1500 SDR&lt;/a&gt; (&lt;a href="https://en.wikipedia.org/wiki/Software-defined_radio" target="_blank"&gt;software defined radio&lt;/a&gt;).&amp;nbsp; If you are new to the idea of SDR don't worry you are not alone, but as a computer guy the idea of SDR makes perfect sense to me.&amp;nbsp; I find this little QRP (low power operation) transceiver to be fascinating.&amp;nbsp; I don't think it's quite what we are looking for, but I would love to have one to play with anyway! &lt;span style="color: #ffffff;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div align="center"&gt;&lt;iframe width="640" height="360" src="https://www.youtube.com/embed/uozpOaKnsog" frameborder="0" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;/div&gt;</description><pubDate>Thu, 27 Aug 2015 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/flex-1500-software-defined-radio</guid></item><item><title>EAARS Broadcastify Live Autio Feed</title><link>http://localhost:30321/blog/eaars-broadcastify-live-autio-feed</link><description>&lt;p&gt;I just wanted to jot off a quick post regarding the &lt;a href="http://eaars.com/" target="_blank"&gt;Eastern Arizona Amateur Radio Society (EAARS)&lt;/a&gt;. These guys have a really nice 2 meter repeater network set up covering several thousand square miles in the southwestern United States.&amp;nbsp; If you are interested you can listen to the repeater traffic live via their &lt;a href="http://www.broadcastify.com/listen/feed/18103/web" target="_blank"&gt;Broadcastify Live Audio Feed&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Tue, 25 Aug 2015 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/eaars-broadcastify-live-autio-feed</guid></item><item><title>I have too many computers!</title><link>http://localhost:30321/blog/i-have-too-many-computers</link><description>&lt;p&gt;I have too many computers.&amp;nbsp; There.&amp;nbsp; I said it. My friends and family all tell me to get rid of some of this stuff.&amp;nbsp; They roll their eyes when I get excited about some new piece of &lt;span style="color: #999999;"&gt;&lt;del&gt;junk&lt;/del&gt;&lt;/span&gt; equipment.&amp;nbsp; But I can't help myself, I never saw a computer, radio or television sitting in a dusty corner at the Goodwill that I didn't want to take home and restore or tinker with or disassemble, etc.&amp;nbsp; I can't even go near Ebay without spending $150 on something nobody in their right mind would spend $150 for. So I thought it would be fun to try to enumerate (that's fancy programmer talk for 'list') all my computers.&amp;nbsp; I am going to take a shot at it now, off the top of my head.&amp;nbsp; Hang on, here we go...&lt;/p&gt;
&lt;h2&gt;Commodore&lt;/h2&gt;
&lt;p&gt;I love commodore.&amp;nbsp; The first computer I ever actually owned was a Commodore 64.&amp;nbsp; I think I got it for Christmas in 1982 or 1983, and I spent a large chunk of my youth programming, calling bulletin boards, and playing games.&amp;nbsp; I got my Amiga 1000 for Christmas in 1986 and it was nirvana.&amp;nbsp; Nothing has ever come close to the awe I had for my first Amiga.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1ea Commodore VIC-20&lt;/li&gt;
&lt;li&gt;2ea Commodore 64&lt;/li&gt;
&lt;li&gt;1ea Commodore SX-64&lt;/li&gt;
&lt;li&gt;3ea Amiga 1000&lt;/li&gt;
&lt;li&gt;1ea Amiga 3000&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Apple&lt;/h2&gt;
&lt;p&gt;My school district bought Apple ][+ computers in either 1980 or 1981 and they had no idea what to do with them.&amp;nbsp; Some educational professional must have reasoned that if computers have a keyboard and electric typewriters have a keyboard it therefore makes sense that computers belong in the typing lab.&amp;nbsp; Which is where the new Apples landed.&amp;nbsp; It is also what we did with them; learned how to type.&amp;nbsp; However, I was not satisfied with merely typing random letters on the keyboard.&amp;nbsp; Within a week I was learning BASIC and shortly after that I dove straight into Machine Language.&amp;nbsp; I still have my first ever Floppy Disk.&amp;nbsp; &lt;a href="https://en.wikipedia.org/wiki/Elephant_Memory_Systems" target="_blank"&gt;Elephant Memory Systems&lt;/a&gt; - Elephant Never Forgets.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1ea Apple //e&lt;/li&gt;
&lt;li&gt;1ea Apple //c&lt;/li&gt;
&lt;li&gt;1ea Laser 128&lt;/li&gt;
&lt;li&gt;1ea Mac 512K (?)&lt;/li&gt;
&lt;li&gt;1ea Mac SE/30 (?)&lt;/li&gt;
&lt;li&gt;1ea Mac Performa (?)&lt;/li&gt;
&lt;li&gt;1ea Mac Power Book 150 (?)&lt;/li&gt;
&lt;li&gt;1ea Mac Ruby G3&lt;/li&gt;
&lt;li&gt;1ea Mac iBook G3&lt;/li&gt;
&lt;li&gt;1ea Mac Mini G4&lt;/li&gt;
&lt;li&gt;2ea Power Mac G4&lt;/li&gt;
&lt;li&gt;1ea Mac PowerBook G4 (Titanium)&lt;/li&gt;
&lt;li&gt;2ea Power Mac G5&lt;/li&gt;
&lt;li&gt;2ea Mac RAID&lt;/li&gt;
&lt;li&gt;1ea Power Mac (Intel 8 core)&lt;/li&gt;
&lt;li&gt;1ea MacBook Pro (i7 2010)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Radio Shack&lt;/h2&gt;
&lt;p&gt;The first computer I ever touched was a TRS-80 Model I.&amp;nbsp; My Dad was managing a Radio Shack store when the first Model I arrived.&amp;nbsp; To my 10 year old mind it was absolutely the coolest thing ever (well, short of Star Wars anyway).&amp;nbsp; I remember my Dad struggling to get the tape player to load a game called 23 matches, which I played endlessly in the store.&amp;nbsp; It was about this same time I read Issac Asimov's book "&lt;a href="https://en.wikipedia.org/wiki/Adding_a_Dimension" target="_blank"&gt;Adding a Dimension&lt;/a&gt;" and being fascinated by the chapter "One, Ten, Buckle my Shoe" which was about binary number systems.&amp;nbsp; Unfortunately, I didn't connect binary math and computers until I started programming on the Apple ][+.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1ea TRS-80 Model 100&lt;/li&gt;
&lt;li&gt;1ea TRS-80 Color Computer&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;PC (Brand-name)&lt;strong&gt; &lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I loathed PC's.&amp;nbsp; Hated them.&amp;nbsp; It was a religion.&amp;nbsp; PC's sucked and only idiots bought them.&amp;nbsp; Of course, back in 1990, if you were cruising along on your U.S. Robotics Courier 9600 HST with your multi-tasking Amiga 3000 while playing MOD files in the background and someone showed you a PC running Windows 3.0 it was easy to snort in derision.&amp;nbsp; With supreme irony I somehow ended up turning programming PC's into a career.&amp;nbsp; I also managed to collect quite a few along the way.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1ea Epson PS2 L40 SX&lt;/li&gt;
&lt;li&gt;1ea Acer Notebook (?)&lt;/li&gt;
&lt;li&gt;1ea Panasonic CF-41 Notebook (486)&lt;/li&gt;
&lt;li&gt;6ea Dell Desktop (P60) (?)&lt;/li&gt;
&lt;li&gt;1ea Dell Inspirion (?)&lt;/li&gt;
&lt;li&gt;1ea Intel ThinkPad (P60) (?)&lt;/li&gt;
&lt;li&gt;3ea Gateway Notebooks (?)&lt;/li&gt;
&lt;li&gt;1ea Compaq Presario V4000&lt;/li&gt;
&lt;li&gt;1ea Dell Desktop (P4)&lt;/li&gt;
&lt;li&gt;1ea HP Pavillion (P4)&lt;/li&gt;
&lt;li&gt;1ea HP Pavillion (AMD A8)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;PC (Homebrew)&lt;/h2&gt;
&lt;p&gt;Maybe the single greatest thing about PCs is that you can build your own.&amp;nbsp; You have ultimate control over speed, memory, storage, peripherals, operating system, etc.&amp;nbsp; Back when Computer Shopper was an inch thick and mail order clones were in vogue, I worked for a company called Fast Micro as a technical support representative.&amp;nbsp; During that period of my life I built, configured, and repaired thousands of 386 and 486 systems.&amp;nbsp; I hated doing technical support, but I have a huge library of technical documentation for motherboards and multi-i/o cards from those days.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1ea "Bridgette" P3&lt;/li&gt;
&lt;li&gt;1ea "Gaming Rig" I7&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Concluson&lt;/h2&gt;
&lt;p&gt;Whew!&amp;nbsp; I think that's all of them.&amp;nbsp; I didn't even bother to try listing peripherals or the associated piles of junk I have collected (cases, motherboards, disk drives, hard drives, audio cards, video cards, cd-roms, etc.).&amp;nbsp; I've got a mountain of books and manuals, and (quite literally) a dozen legal boxes full of software.&amp;nbsp; It's quite a lot to store, and even harder to actually get stuff out and set it up but I am slowly getting organized.&amp;nbsp; In the future I hope to add a Comodore 128 and an Amiga 2000 to my collection.&amp;nbsp; I would also very much like to get some Atari gear; maybe a nice 800 XL with some disk drives.&amp;nbsp; Anyway, thanks for taking a trip down "inventory lane" with me.&amp;nbsp; Cheers!&lt;/p&gt;</description><pubDate>Mon, 24 Aug 2015 03:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/i-have-too-many-computers</guid></item><item><title>Compute!'s Gazette</title><link>http://localhost:30321/blog/compute-s-gazette</link><description>&lt;p&gt;&lt;img class="alignright wp-image-38 size-full" src="http://www.devmash.com/main/wp-content/uploads/2014/08/ComputesGazette.png" alt="A picture of the cover of Compute!s Gazette." width="220" height="293" /&gt;When I was just a kid, I loved computers.&amp;nbsp; Everything was 8 bit back then, and everything was comprehensible by a 14 year old.&amp;nbsp; 65xx assembler wasn't very difficult, and you could apply your knowledge to Commodore, Apple and Atari products; which was the lions share of what you and your friends probably had access too.&amp;nbsp; Of course, before we even knew there was such a thing as an 'Internet' and before we got our first 300 baud modems, information was somewhat tricky to come by.&amp;nbsp; Finding good code examples usually meant scrounging around the school library for terribly written and hopelessly out of date books.&amp;nbsp; Sometimes my friends and I would go to the mall just to slum at &lt;a href="http://en.wikipedia.org/wiki/Waldenbooks"&gt;Waldenbooks&lt;/a&gt; where we would endlessly drool over the 10 books in the 'computer section'.&amp;nbsp; I remember we did a lot of disassembling and arguing and experimenting, and consequently a lot of frustrated swearing. But for a Commodore 64 Junkie like myself, there was a shining beacon of digital enlightenment, guaranteed to arrive monthly.&amp;nbsp; Compute!'s Gazette was like Manna from Heaven.&amp;nbsp; I don't exactly remember the first time I ever saw this magazine, but I think it was when my parents blindly bought me a subscription.&amp;nbsp; My Dad was an electronics and amateur radio enthusiast, but I think my passion for computers had both my parents mystified.&amp;nbsp; Whatever the circumstances, at some point I started reading the Gazette...&amp;nbsp; Every single page....&amp;nbsp; Over and over and over...&amp;nbsp; I would type in the programs... I would read the articles... I would pour over the letters to the editor...&amp;nbsp; I would drool over hardware advertisements for things I knew I would never afford...&amp;nbsp; It's safe to say, I obsessed over that magazine and the precious bits of data it contained. I often wish I still had my hard copies of Compute!'s Gazette.&amp;nbsp; Like an idiot, I junked my entire stash one year in a rash decision to try and save a relationship with an Ex.&amp;nbsp; (She said I keep too much junk, but I don't see it?). - So now, gentle reader, we reach the point of this post, which is that now anyone can read the Gazette in all it's original glory. Thanks to the &lt;a href="https://archive.org"&gt;Internet Archive&lt;/a&gt;, and God-Knows-Who taking the time to scan every single page of every issue, everyone can sample this wonderful magazine and experience, just for a moment, the simple beauty of retro computing. If you are interested in old computers (and even if you aren't) I invite you to &lt;a href="https://archive.org/search.php?query=%28collection%3Acompute-gazette+OR+mediatype%3Acompute-gazette%29+AND+-mediatype%3Acollection&amp;amp;sort=-reviewdate&amp;amp;page=1"&gt;visit the Internet Archive&lt;/a&gt; collection of Compute!'s Gazette magazines and sample a few. Issues are available in a variety of formats, including PDF.&amp;nbsp; Try to imagine the thrill of typing in a FREE word processor, or getting your computer to display 80 columns, or lusting after that new 9 pin dot matrix printer...&amp;nbsp; I hope you can, maybe for a little while, find as much joy in those pages as a certain young programmer did all those years ago.&lt;/p&gt;</description><pubDate>Thu, 21 Aug 2014 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/compute-s-gazette</guid></item><item><title>NTSC Demystified</title><link>http://localhost:30321/blog/ntsc-demystified</link><description>&lt;p&gt;&lt;img class="alignright wp-image-27 size-medium" src="http://www.devmash.com/main/wp-content/uploads/2014/07/TestPattern-300x187.jpg" alt="TestPattern" width="300" height="187" /&gt;I was browsing through posts on &lt;a href="http://hackaday.com/" target="_blank"&gt;Hackaday&lt;/a&gt; and found a link to an excellent series of articles by Sagar GV entitled "NTSC Demystified".&amp;nbsp; If you enjoy electronics and have wanted to learn more about NTSC video but could never seem to find the right resource, these articles are for you!&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2011/04/ntsc-demystified-part-1-b-video-and.html" target="_blank"&gt;B&amp;amp;W Video and Sync&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2011/04/ntsc-demystified-part-2-color-encoding.html" target="_blank"&gt;Color Encoding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2011/04/ntsc-demystified-nuances-and-numbers.html" target="_blank"&gt;Nuances and Numbers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2011/04/ntsc-demystified-math-part-4.html" target="_blank"&gt;Math&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2011/06/ntsc-demystified-implementation-part-5.html" target="_blank"&gt;Implementation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2011/06/ntsc-demystified-cheats-part-6.html" target="_blank"&gt;Cheats&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sagargv.blogspot.in/2014/07/ntsc-demystified-color-demo-with.html" target="_blank"&gt;Color palette demo with simplified progressive and interlace scanning&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;em&gt;Disclaimer: To be clear, I take no credit for any of the work done in this series of articles.&amp;nbsp; All credit should go to the original author(s).&lt;/em&gt;&lt;/p&gt;</description><pubDate>Fri, 18 Jul 2014 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/ntsc-demystified</guid></item><item><title>Machine Language for Beginners</title><link>http://localhost:30321/blog/machine-language-for-beginners</link><description>&lt;p&gt;&lt;img class="alignright wp-image-30" src="http://www.devmash.com/main/wp-content/uploads/2014/07/MachineLanguageForBeginners-208x300.jpg" alt="MachineLanguageForBeginners" width="139" height="200" /&gt;Like a gazillion other people, I now have a WordPress site.&amp;nbsp; Unlike a gazillion other people, this site is (currently) has no point.&amp;nbsp; It is simply a playground for me to get my feet wet.&amp;nbsp; I wanted to learn more about WordPress, so it seemed like a logical thing to do... I figure if I am going to do anything, it will probably be related to my hobbies and interests, so for my first post I would like to mention I recently located a book called Machine Language for Beginners that I read when I was in high school.&amp;nbsp; This book might be the most influential book I ever read (well at least in relation to my career as a computer programmer).&amp;nbsp; I've linked it &lt;a title="Machine Language for Beginners" href="http://devmash.com/files/machinelanguageforbeginners.pdf" target="_blank"&gt;here&lt;/a&gt; for you to download and enjoy.&lt;/p&gt;</description><pubDate>Sun, 22 Jun 2014 15:00:00 GMT</pubDate><guid isPermaLink="true">http://localhost:30321/blog/machine-language-for-beginners</guid></item></channel></rss>