Inside and Out…

An attempt to understand technology better…

Archive for the ‘Tips’ Category

Working with properties in Managed C++?

Posted by Gaurav Khanna on July 6, 2006

Then read this article by someone who knows Managed C++ very well. His blog is here.


Posted in .NET Framework, Articles, Managed C++, Tips | Leave a Comment »

Programming the Windows RSS Platform

Posted by Gaurav Khanna on July 2, 2006

One of the interesting things that has been introduced with Internet Explorer 7 (IE7) is the central repository of RSS feeds that will be maintained on the machine running IE7. This is called as the Common Feed List (CFL) and it can be accessed by any application via the COM based API that is being provided alongside. Infact, I wrote IEFeedManager that leverages this API to manage the CFL and also use it to view the RSS feeds.

In this post, I will explain how you can get started to program for this new RSS platform using the managed world. Note: You will need to have IE7 installed on your machine.

First, you will need to add the reference to the COM API library. Right-click your project->Add Reference.. and select the COM tab. You will see Microsoft Feeds listed as shown below:

Microsoft Feeds in the COM tab

Once you add the reference, you will see Microsoft.Feeds.Interop assembly being referenced in your project. Include the namespace with the same name in your project and your are ready to go.

The starting point in the CFL is the FeedManager object. This will allow you to enumerate all the feeds contained in the root folder of CFL, enumerate subfolders and the feeds contained within them. It implements the IFeedManager interface and a typical instantiation will be like this:

private IFeedsManager feedManager = new FeedsManagerClass();

Once you have the IFeedManager instance, you can access the root CFL folder (of the type IFeedFolder) as shown below:

feedRootFolder = (IFeedFolder)feedManager.RootFolder;

Next, you can enumerate the contained subfolders:

IFeedsEnum colSubFolder = (IFeedsEnum)feedRootFolder.Subfolders;

foreach(IFeedFolder feedFolder in colSubFolder)

{ // Do something with “folder” object }

Likewise, the Feeds property of an IFeedFolder can used to access the feeds (of the type IFeed) contained in the folder and work with them:

IFeedsEnum colFeeds = (IFeedsEnum)feedFolder.Feeds;
foreach (IFeed feed in colFeeds)

{ // Do something with the “feed” object }

Now that you have the IFeedFolder object and the contained IFeed objects, you can use a variety of properties and method to work with them. For example, to refresh the feed, invoke the Download method against the IFeed object. To delete a folder and its contained feeds (and subfolders as well), invoke the Delete method against the IFeedFolder object.

You could also set the auto-refresh (of the feed) interval using the Interval property of the feed. Not just that, you can even wire up for a notification against a feed folder or a feed so that if they are modified externally (e.g. another application) or are updated (or deleted), your application can be notified about all such behavior!

Possibilities are endless. The new RSS platform is quite powerful in terms of the APIs it provides to do a variety of tasks. Check the detailed documentation here.

Technorati : , , , , : , , , ,
Buzznet : , , , ,

Posted in .NET Framework, Tips, Windows API | Leave a Comment »

[Tip] Taking quick inputs in WinForm applications

Posted by Gaurav Khanna on February 2, 2006

There are frequent scenarios when we need to take inputs from the user but which dont warrant designing a form to take the input. For such scenarios, use the Interaction class’s static InputBox method, which is based in Microsoft.VisualBasic assembly. Sample usage is below:

string strServiceMachine = Interaction.InputBox(“Enter the IP Address/Name of the machine running Sudoku Game service:”, this.Text, null,-1,-1);

Very similar to VB6’s InputBox function.

Posted in .NET Framework, Development, Tips | Leave a Comment »

Performance implication of Polling

Posted by Gaurav Khanna on January 25, 2006

Raymond Chen has a nice blog entry that discusses it.

Must read.

Posted in Performance, Tips | Leave a Comment »

Enumerating Managed Processes

Posted by Gaurav Khanna on August 16, 2005

System.Diagnostics.Process class is a managed wrap over a subset of the ToolHelp API – as it enumerates only the process list. Not only that, it will list all the running processes, irrespective of whether they are running unmanaged code or running managed code. What if you wish to identify which of these processes are running managed code?

Unfortunately, neither the ToolHelp API, nor the Process class allow us to identify managed processes from the list they provide us. However, if you have noticed while debugging using Visual Studio, the debugger does identify a managed process in such a list:

VS debugger showing processes running managed code

So, how does the VS debugger do it?

Well, the CLR exposes debugging interfaces, which contain this functionality. These interfaces include ICorPublish, ICorPublishProcess, ICorPublishAppDomain, just to name a few. Infact, if you have installed the .NET Framework 2.0 SDK and navigate to the %SDKRoot%\v2.0\include folder, you will see the relevant header files that contain these interface definitions

The same identification can now also be done using managed code. Under %SDKRoot%\v2.0\bin folder, you will find, amongst others, MdbgCore.dll – the core of the managed debugger. If you ILASM this file (yes, its an assembly), you will see the managed wraps of the unmanaged interfaces mentioned above:

Managed wraps of the unmanaged interfaces

The starting point is Microsoft.Samples.Debugging.CorPublish.CorPublish. This lets us enumerate the managed processes, returning an instance of Microsoft.Samples.Debugging.CorPublish.CorPublishProcess type. Below is a sample that exemplifies doing the same:

using System.Collections.Generic;
using System.Text;
using Microsoft.Samples.Debugging.MdbgEngine;
using Microsoft.Samples.Debugging.CorPublish; namespace ManagedProcessList
    class Program
        static void Main(string[] args)
            CorPublish pub = new CorPublish();
            foreach (CorPublishProcess proc in pub.EnumProcesses())
                Console.WriteLine(“{0} IsManaged: {1}”, proc.DisplayName, proc.IsManaged.ToString());

Posted in .NET Framework, Debugging, Tips | Leave a Comment »

Working with NTFS Access Control using .NET Framework 2.0

Posted by Gaurav Khanna on July 12, 2005

.NET Framework 2.0 (“Whidbey”) has introduced a new set of classes in the Framework Class Library (FCL) that allows you to work with the NTFS Access Control Lists. You can get object owners, security descriptors, create security descriptors, and much more. All of this resides under the System.Security.AccessControl namespace.

Below is a snippet that exemplifies how to use it. Scenario: You need to create a child folder without the permissions inherited by the parent folder, but with only permissions explicitly set on the parent folder.

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Security.AccessControl; 
using System.IO; 
using System.Security.Principal;

namespace AceInheritRemove

    class Program

        static void Main(string[] args)
            // Get the object and its SecDescp

            DirectoryInfodir = newDirectoryInfo("e:\\kgk\\test"); 
            DirectorySecuritysec = dir.GetAccessControl(AccessControlSections.All); 

            // Create an empty Security Descp... 
            DirectorySecuritysecNew = newDirectorySecurity();

            // Get the explicit perms on the object. 
            AuthorizationRuleCollectioncol= sec.GetAccessRules(true, false, typeof(SecurityIdentifier));

            // List all the explicitly set permissions on the object... 
            foreach(FileSystemAccessRulerule in col)

                // Add the explicit permission to the new Security Descp. 
                Console.WriteLine("{0}", rule.FileSystemRights.ToString());

            // Create a child folder with the explicit permissions only... 
            DirectoryInfoinfo2 = newDirectoryInfo("e:\\kgk\\Test\\Child"); 



Posted in .NET Framework, Development, Tips, Windows API | 1 Comment »

Understanding CLR’s Special Threads

Posted by Gaurav Khanna on July 12, 2005

There are multiple special threads which the CLR maintains and executes. Yun Jin talks about them in his blog at

Must read for those who want to understand CLR better!

Posted in .NET Framework, CLR, Tips | Leave a Comment »

Make a phone call within the Emulator

Posted by Gaurav Khanna on May 27, 2005

For PocketPC and SmartPhone emulators with virtual radio support, you can make phone calls from within the emulator by using the number +14250010001. The same number can be used to send SMS within the emulator as well!

Posted in .NET Compact Framework, Tips, Windows CE/Windows Mobile | Leave a Comment »

TIP: Whom are you connected with via ActiveSync?

Posted by Gaurav Khanna on April 1, 2005

There’s no programmatic way to determine if the Windows CE device connected via ActiveSync to the desktop is a PocketPC or a SmartPhone. If you wish to determine the same, open HKEY_CURRENT_USER\Software\Microsoft\Windows CE Services registry key and lookup the value of DeviceType value. Its a REG_SZ and contains the type of device you are connected with.

Posted in Tips, Windows CE/Windows Mobile | Leave a Comment »

Win32 API to .NET Framework Mapping

Posted by Gaurav Khanna on March 1, 2005

Do you want to know which Win32 API maps to what part of the .NET Framework? If yes, visit

Posted in .NET Framework, Tips, Windows API | Leave a Comment »