Welcome to Windows Workflow Foundation (WF)
Top Tasks :

WF Team Bloggers

Browse by Tags

All Tags » .NET   (RSS)

  • Visual Studio Tip : AutoFormat Your Code

    Has this ever happened to you? You find some code on the Net so you copy and paste it into a source file within Visual Studio and notice that all the formatting is somehow messed up. For example. some lines might be indented while others are not.

    To have Visual Studio fix it all up nice and tidy for you, select the text, hold CTRL and hit K followed by F (CTRL+K-F). What I usually do is do a CTRL-A to select all text then do the CTRL+K-F combo. Voila!

  • C# WebCam User Control Source

    Some people have asked if they could take a look at the source for the WebCam Vista Sidebar gadget. After a little bit of cleaning up, I'm posting it now for you to take a look at. Here are some things worth mentioning:

    1. Uses the DirectShow.NET library

    2. I found some source in VB.NET and used that as a baseline (performed the conversion and cleaned up stuff that really wasn't needed)

    3. I am in no way a DirectX/DirectShow expert. Any questions sent my way will likely result in a blank stare back at you :-) (though fwiw, I do pick up things quickly and might be able to at least get you started on the correct path)

    4. If you look at the source, you might think "I thought this was a Vista Sidebar Gadget. Where is the gadget source?" That's the easy part. At the bottom of this post is a link to my .NET Gadget Creator application that I wrote (with instructions on how to use it with the WebCam control). That application will allow you to take any .NET UserControl and convert it into a Vista Sidebar Gadget. Just compile the WebCamControl2 control, and use the .NET Gadget Creator to create an instant Vista Sidebar gadget.

    5. You may receive an error when you run the provided test application saying something along the lines of "invalid argument". This is a known issue and is happens when more than one application tries to access the same camera. I haven't looked into fixing this so if someone wants to take a stab at it, clue me in on how to fix it.

    When looking through the source (there isn't that much to it) pay attention to the 2 primary methods. The first is the GetInterfaces method which creates all the necessary DirectShow interfaces and then creates the connection between DirectShow and your UserControl window (events are passed to the control via Window messages).

    The FindCaptureDevice method enumerates through your devices looking for the 1st video device it finds that provides an input (FilterCategory.InputDevice). This is done by creating a device class enumerator. Currently, the source will just grab the first device that it sees. If anyone is interested in knowing how to present the user with a list of all input devices, I can write some code to do that as well. Just let me know.

      103 UCOMIEnumMoniker classEnum = null;

      104 UCOMIMoniker[] moniker = new UCOMIMoniker[1];

      105 object source = null;

      106 

      107 ICreateDevEnum devEnum = (ICreateDevEnum)(new CreateDevEnum());

      108 int hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, CDef.None);

      109 DsError.ThrowExceptionForHR(hr);

      110 Marshal.ReleaseComObject(devEnum);

    Once the class enumerator is created, I just grab the first one that was found (assuming one was found) and bind it to an IBaseFilter object which I then return.

      117 int none = 0;

      118 

      119 if (classEnum.Next(moniker.Length, moniker, out none) == 0)

      120 {

      121     Guid iid = typeof(IBaseFilter).GUID;

      122     moniker[0].BindToObject(null, null, ref iid, out source);

      123 }

      124 else

      125 {

      126     throw new ApplicationException("Unable to access video capture device!");

      127 }

      128 

      129 Marshal.ReleaseComObject(moniker[0]);

      130 Marshal.ReleaseComObject(classEnum);

      131 

      132 return (IBaseFilter)source;

    Once the video input device is found and we have our base filter, we associate it with an ICaptureGraphBuilder2 object by telling it render a video stream through the preview pin of the input device(line 68 below of the CaptureVideo method).

    .cf { font-family: consolas; font-size: 10pt; color: black; background: white; font-weight: bold; } .cl { margin: 0px; } .cln { color: #2b91af; font-weight: normal; } .cb1 { color: blue; font-weight: normal; } .cb2 { color: #010001; font-weight: normal; } .cb3 { color: #2b91af; font-weight: normal; } .cb4 { color: green; font-weight: normal; } .cb5 { font-weight: normal; } .cb6 { color: #a31515; font-weight: normal; }

       51 private void CaptureVideo()

       52 {

       53     int hr = 0;

       54     IBaseFilter sourceFilter = null;

       55     try

       56     {

       57         // create the necessary DirectShow interfaces

       58         GetInterfaces();

       59 

       60         hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);

       61         DsError.ThrowExceptionForHR(hr);

       62 

       63         sourceFilter = FindCaptureDevice();

       64 

       65         hr = this.graphBuilder.AddFilter(sourceFilter, "WebCamControl Video");

       66         DsError.ThrowExceptionForHR(hr);

       67 

       68         hr = this.captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, null, null);

       69         Debug.WriteLine(DsError.GetErrorText(hr));

       70         DsError.ThrowExceptionForHR(hr);

       71 

       72         Marshal.ReleaseComObject(sourceFilter);

       73 

       74         SetupVideoWindow();

       75 

       76         hr = this.mediaControl.Run();

       77         DsError.ThrowExceptionForHR(hr);

       78 

       79         this.CurrentState = PlayState.Running;

       80     }

       81     catch (Exception ex)

       82     {

       83         MessageBox.Show("An unrecoverable error has occurred.\r\n" + ex.ToString());

       84     }

       85 }

    Now, if you want to use that control in the Vista Sidebar, just download and install the following application:

    When you launch the application and click Next it will ask you to add .NET assemblies. Click the Add button, navigate to the WebCamTest or WebCamControl2 bin directory and select the WebCamControl2.dll AND the DirectShowLib.dll assemblies as shown below.

    image

    Click Next twice to get to the "Select UserControl to Embed". Select the WebCamControl2.WebCamControl2 type and click Next. The next screen allows you to enter the information about the gadget. I provided an icon for you in the WebCamTest base directory. After you fill in the information, keep clicking Next and the gadget will be built for you. Go into the output directory you specified and you'll see the .gadget file. Simply double click on this and if all goes well, you should be looking at your webcam in the Vista Sidebar. Also, since you used the .NET Gadget Creator application, your gadget will uninstall successfully even while it is running (see .NET Sidebar Gadget Creator Update #2 for more information).

    Without further ado, here's the link to the WebCamControl source code.

    image

  • New & Improved NHL Schedule Importer for Outlook

    Ok, I redid the whole application (since I lost the source code) and added some new features as well. The previous application utilized XML which required you to actually get the NHL schedule in XML format somehow (I used Excel). Needless to say, it was a long and complicated process.

    This new version utilizes good old fashioned screen-scraping to get the job done. Here are some key features that I've added:

    1. Location field will tell if the stations the game is on for national and local (both away and home team) markets

    2. The body for each appointment when you open it up in Outlook contains links to each teams website as well as links to subscribe to that team's RSS feed (see screenshot below)

    3. ** Here's the cool feature ** After you ran the application and import your team's schedule, you can run the application at a later date and it will not create duplicate entries. In fact, if you run it a second time, it will add the game's final score and a link to show the recap of that game (again, see screenshot).

    4. You know have the ability to add an outlook reminder or not for each game

    5. UI is prettier. When you select a team from the drop down list, it will fetch that team's logo from the web and full team name (see screenshot).

    6. Internally everything is different. It would have been easy to allow you to select a year (e.g. 2008-2009) but I'll wait to add that. In any case, whenever a new NHL schedule is created, it's a trivial change to get the application to work with it.

    *NOTE* I tested this using Vista and Outlook 2007. If you have any issues when importing your team(s) schedule(s), let me know. It helps if you can send a screenshot or any error messages word for word. For developer types who know what a call stack is, send that as well if you can.

    Here's some screenshots followed by the link to download the application (complete with installer)

    importing

    appointment

    Download Here

     col GO AVS!!! col

  • .NET Sidebar Gadget Creator 2.0 Release

    Ok, I finally worked out most of the bugs (I hope). I'll post the link and follow up with some tutorials and Sidebar Gadget development using .NET.

    Here's the file...using the new SkyDrive Beta to host the file!!!

  • .NET Sidebar Gadget Creator Update #2

    I had quite the breakthrough today. First off, I totally rewrote major portions of the .NET Sidebar Gadget Creator. It is now a wizard (photos below) that leads you through the steps to create a Vista Sidebar that uses .NET. Here are some of the changes (then I'll explain my breakthrough):

    • You can now create any .NET type. You have the "option" of embedding a UserControl as the UI but it isn't required. Have a cool class you want to use. This makes it easy.
    • A .gadget file is automatically created for you. More often than not, you will need to fiddle around with the final result, but just in case, I went ahead and added this feature anyway
    • Reworked the entire act of copying to temp directory and registering assemblies...this is the breakthrough

    As one reader pointed out, they noticed that I was simply copying the .NET assembly to the temp folder, creating the COM Interop registry keys to point to that location and having sidebar/Trident load it up from there. Was that the ideal solution? No way. He was right. It was the wrong way to do it. The benefit was that it allowed you to uninstall your gadget from the Sidebar UI, but left the file in the temp directory and orphaned registry keys.

    Here's the breakthrough. What if I told you that your .NET assemblies are not copyed over. They remain in your gadget directory. What if I also told you, you don't have to worry about registration. Yeah, so. You didn't with previous versions either right since my tool did it for you. Well, what if I told you that my tool also doesn't have to worry about registering your assemblies for COM interop? You heard right. Nothing about your assembly ever gets registered into the registry (i.e. I don't register your assembly for COM interop). However, you will still be loaded just fine and if you are a UserControl based object, you will be embedded. Additionally, you can still be safely uninstalled and all the gadget files will be deleted just fine.

    If you have a clue as to how I do this...feel free to submit your best guesses. I'm going to put the finishing touches on the tool and send it out. After that, I'll have a series of tutorials and an examination of the code (as well as my solution to how I solved this problem).

  • Hosting .NET Runtime in C++ Tip o' the day or "Where is IAppDomainSetup?"

    Are you hosting the .NET runtime and trying to create another AppDomain? Notice that you need to call CreateDomainSetup and cast the IUnknown to IAppDomainSetup to set properties? Notice also that IAppDomainSetup isn't defined in mscoree.h? Add the following (stdafx.h or anywhere else):

    #import <mscorlib.tlb> raw_interfaces_only no_smart_pointers high_property_prefixes("_get","_put","_putref")

    then you can say:

    CComPtr<mscorlib::IAppDomainSetup> pAppDomainSetup;

    Ta da!

  • Fourth of July Vista Sidebar

    I found a screensaver that plays nicely with my Vista ScreenSaver Sidebar gadget. Just in time for the 4th of July!

     First, go get the ScreenSaver gadget and install it to your sidebar: http://gallery.live.com/liveItemDetail.aspx?li=e321409b-231a-4da0-905c-0580c732223e&bt=1&pl=1

    Next, go grab the SkyRocket ScreenSaver and install it to your C:\Windows\System32 directory: http://www.fileplanet.com/164987/160000/fileinfo/Skyrocket-Screensaver-%5BFREEWARE%5D

     Open the configuration options for the Sidebar gadget and select SkyRocket. Here's a screenshot for ya:

  • ActiveX based Sidebar gadget problem solved!

    Ok, I just ran a test with some new code that creates an ActiveX based sidebar gadget and I was able to get the dll unloaded from the sidebar process so it can uninstall successfully! This is good news for all the people that can't seem to get around this issue (and there's a few of you). I'll get going on a solution and post the results here. If you want to be emailed when its ready, just ping me and I'll add you to a list.

    Want a hint as to how I solved it? Take a look at this post's tags :-)

  • ScreenSaver Gadger hits 20000 downloads

    It's a milestone. My ScreenSaver Vista Sidebar gadget has hit 20000 downloads. Some people have commented that it would be nice to double click it and have it launch the screensaver. The good news is, I have a version that does exactly that (can even lock your workstation should you choose). The bad news...I can't update the gallery with a new build. Why? I'll tell you.

     The gadget uses C# and therefore utilizes COM interop. However, I can't find a way to unload the dll when a user right clicks in the "Add Gadget" window and selects "Uninstall". Triden is keeping hold of my dll even though it isn't visible anymore. If anyone has some hints to force an unload, or to capture the uninstall event so I can at least inform the user or restart sidebar, I'd love to hear it.

     For now you can grab the 1.0 version at:

    http://gallery.live.com/liveItemDetail.aspx?li=e321409b-231a-4da0-905c-0580c732223e&bt=1&pl=1

  • Goodbye WF...My New Role

    You read right, I am leaving the WF team. I have been a WF Programmer Writer (documentation guy) for awhile now and it's been fun. WF is an awesome technology and I whole heartedly agree with the direction Microsoft is taking it. However, I'm done being a Programmer Writer. A transition date is still being discussed, but I will soon be moving into a developer role working in the Windows Live organization. Words cannot convey how excited I am to get going on the new team. I will miss the WF team but I have to move on. I was a developer at a different company before Microsoft and I came to realize that I missed being in that type of role. I will still write, but it will be relgated back to hobby status instead of a career.

  • My Screen Saver Vista Sidebar Gadget

     For some reason, I'm drawn to creating things that are just cool while not altogether useful (see my Animated Activity Designer post, though one could argue that it may in fact be useful). To that end, I decided to create a Vista Sidebar gadget that displays a screen saver of your choosing. Vista has some good screen savers that it shipped with and I've embedded screen savers before (in fact, I show how to do it in one of my books).

    So go ahead and grab it from the Windows Live Gallery (link below). If enough people clamor and beg, I will post the source code. Here's a quick rundown of what I did:

    1. Create a .NET User Control
    2. Embed a screen saver in the user control whenever the ScreenSaverPath property is set (and the control is visible)
    3. Create the HTML page for the sidebar (sidebar controls use Javascript and HTML in case you didn't know already)
    4. Embed the UserControl in the HTML page (using COM interop naturally)
    5. Create a settings page that also uses COM Interop. The settings page calls a .NET component that I wrote that simply returns a collection of screen saver paths on the local system.
    6. Create the installation in Javascript. I had to get some help for this one. Basically, I do what regasm does by using the WSHShell object to set registry entries. I found some code on the Internet to help.

    Here's a screenshot of it in action using the Ribbons screensaver:

    Here's the link:

    Screen Saver Vista Sidebar Gadget

  • What to use Windows Workflow Foundation for?

    We established that Windows Workflow Foundation isn't an end user product in a recent entry . In this entry I want to give my opinions on what software developers should be using WF for. WF is a new capability in the .NET Framework 3.0 that developers...( read more ) Read More...
  • WFPad for Windows Workflow Foundation RTM

    Since a few people have asked, I updated the source for WFPad to work with the latest and greatest Windows Workflow Foundation.

    Click the link to download: WFPad.exe

     Enjoy!

  • How does Windows Workflow Foundation (WF) compare to product X?

    I get asked this question a bit from people who have heard of WF but have not read much about it. This applies to BizTalk Server 2006, Office SharePoint Server 2007, SourceCode K2, Skelta, Captaris, other BPM products, etc. Here's how I explain it. I'll...( read more ) Read More...
  • .NET Framework 3.0 RTM at TechEd Developers in Barcelona

    I'm here in Barcelona and the news is that the .NET Framework 3.0 is released. It's available now for download targetting Windows XP and Windows Server 2003. The Visual Studio extensions for Windows Workflow Foundation are also released. The download...( read more ) Read More...
More Posts Next page »

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us