Inside and Out...

An attempt to understand technology better...

  Home  |   Contact  |   Syndication    |   Login
  160 Posts | 0 Stories | 12 Comments | 181 Trackbacks

News


WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.
Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Twitter





Tag Cloud


Archives

Post Categories

Image Galleries

Links

Thursday, March 29, 2007 #

[Originally posted on 5th June 2006]

I just finished off with TechED 2006 India at Delhi and had sometime at hand today before TechED starts at Pune tomorrow. So, I thought about writing an application I had been waiting to develop.

There are times when we forget our phones at home. However, we continue to get SMS and phone calls on our device while we are at a totally different location. Would it not be great if our phone could email us details of the SMS received and phone calls we missed?

Download NotifyOnEmail which will do just that. It is for PocketPC and requires Windows Mobile 5.0 and .NET Compact Framework 2.0. Screenshot is below:


[Originally posted on 10th July 2006]

WinToolZone.Bluetooth now has authentication support. You can use a BluetoothDevice object (which is used represent a Bluetooth device that has been detected) and use the SendPassKey method to send a pass key for authentication:

.
   1:  bth.Devices[ i ].SendPassKey("123", null);


Also, I have added OnIncomingAuthenticationRequest event handler against a BluetoothDevice object that can be used to setup an event handler, which will be invoked when the Bluetooth device sends an authentication request to the machine running WinToolZone.Bluetooth:

.
   1:  bth.Devices[ i ].OnIncomingAuthenticationRequest += new 
   2:  BluetoothDevice.IncomingAuthenticationRequestHandler(
   3:  Program_OnIncomingAuthenticationRequest);

 

The event handler is implemented as shown below:

.
   1:   static void Program_OnIncomingAuthenticationRequest(
   2:                 BluetoothDevice refDeviceRequestingAuthentication)
   3:   {
   4:    Console.WriteLine("{0} is requesting me to send pass key.", 
   5:      refDeviceRequestingAuthentication.Name);
   6:    
   7:    bool bSentResponse = 
   8:    refDeviceRequestingAuthentication.SendAuthenticationResponse("123", null);
   9:    Console.WriteLine("Sent response: {0}",bSentResponse.ToString());
  10:   }

 

The handler gets as an argument the BluetoothDevice instance representing the device that sent the authentication request. To send the pass key back as part of completing the incoming authentication process, SendAuthenticationResponse method of BluetoothDevice is used.

For a partnership/bonding that has been established with a Bluetooth device, DeleteDeviceAuthentication method has been introduced that should be invoked against the BluetoothDevice instance representing the partnered device to break the partnership.


[Originally posted on 6th July 2006]

WinToolZone.Bluetooth, the managed Bluetooth API for the desktop that I am working on, now has the support for enumerating devices as well. The snippet below exemplifies it:

.
   1:  Bluetooth bth = new Bluetooth();
   2:              
   3:      // EnumRadios(bth);
   4:   
   5:      if (bth.RefreshDevices(false, true, true, true, true, null) == false)
   6:      {
   7:           Console.WriteLine("Unable to enum devices");
   8:           return;
   9:      }
  10:   
  11:      foreach (BluetoothDevice device in bth.Devices)
  12:      {
  13:           Console.WriteLine("Devicename: {0}", device.Name);
  14:           Console.WriteLine("LastSeen: {0}", device.LastSeen.ToString());
  15:           Console.WriteLine("LastUsed: {0}", device.LastUsed.ToString());
  16:           Console.WriteLine("Connected: {0}", device.IsConnected.ToString());
  17:           Console.WriteLine("Remembered: {0}", device.IsRemembered.ToString());
  18:           Console.WriteLine("Authenticated: {0}", device.IsAuthenticated.ToString());
  19:           Console.WriteLine("DeviceClass: {0}", device.DeviceClassID);
  20:           Console.WriteLine("Address: {0}\n", device.Address.ToString());
  21:                  
  22:      }

And below is an output screenshot:

Bluetooth device enumeration output using WinToolZone.Bluetooth

[Originally posted on 5th July 2006]

One of the communication protocols not present in .NET Framework class libraries is Bluetooth. So today, I started to work on my implementation of a managed API for Bluetooth programming - WinToolZone.Bluetooth. I am authoring it using Managed C++ and leveraging the Microsoft Bluetooth stack APIs.

I just completed implementing the support for enumerating the Bluetooth radios on a machine. Below is a C# program that exemplifies how they can be enumerated:

.
   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using WinToolZone;
   5:   
   6:  namespace BTHCSClient
   7:  {
   8:      class Program
   9:      {
  10:          static void Main(string[] args)
  11:          {
  12:              Bluetooth bth = new Bluetooth();
  13:              if (bth.RefreshRadios())
  14:              {
  15:                  foreach (BluetoothRadio radio in bth.Radios)
  16:                  {
  17:                      Console.WriteLine("RadioName: {0}", radio.Name);
  18:                      Console.WriteLine("Address: {0}", radio.Address.ToString());
  19:                      Console.WriteLine("ManuID: {0}", radio.ManufacturerID);
  20:                      Console.WriteLine("LMPSubversion: {0}", radio.LMPSubversion);
  21:                      Console.WriteLine("DeviceClass: {0}", radio.DeviceClass);
  22:                  }
  23:              }
  24:              else
  25:              {
  26:                  Console.WriteLine("Unable to enumerate BTH radios");
  27:              }
  28:          }
  29:      }
  30:  }

[Originally posted on 31st July 2006]

 

Ever wanted to compose SMS from the ease of desktop instead of the phone? Wanted to be notified on the desktop, while you are working, when a SMS is received and reply to it from there itself?


DesktopSMS, for Windows Mobile 5.0 based SmartPhone and PocketPC devices, will let you do just that! Based upon .NET Framework 2.0, .NET Compact Framework 2.0 and Windows Mobile 5.0, it allows you to compose, receive and reply to SMS while the phone is connected to your machine via ActiveSync. Below are some screenshots of the same:


Main window to send SMS

Likewise, when a SMS is received, a popup comes on your screen that will allow you to reply as well:

Popup on message receipt

You can even select recepients from Microsoft Outlook's Contact folder as message receipient, provided they have mobile phone number specified. It comes with complete documentation and installer.

Download DesktopSMS from http://www.wintoolzone.com/showpage.aspx?url=listdotnet.aspx?Listtype=1


I have updated TransNTFS, my managed implementation for the transactional NTFS APIs that have been introduced with Windows Vista. TransNTFS now also supports the following operations under a transaction:

It comes with complete documentation (as always) and can be downloaded from http://www.wintoolzone.com/ListDotNET.aspx?Listtype=3


Sometime back, I had made a post regarding a native C++ class I had authored for using some of the Transactional NTFS (TxF)APIs introduced in Windows Vista.

Almost two weeks from that post, I just finished my managed implementation, TransNTFS, that enables you to use the TxF APIs from managed code. As always, Managed C++ enabled the implementation with excellent ease. It comes with complete documentation and can be downloaded from http://www.wintoolzone.com/ListDotNET.aspx?Listtype=3.

Below is an example usage of how to copy a file under a transaction:

.
   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using WinToolZone;
   5:   
   6:  namespace ManagedTransactionCopyDemo
   7:  {
   8:  class Program
   9:  {
  10:  static void Main(string[] args)
  11:  {
  12:  TransNTFS refTC = new TransNTFS();
  13:   
  14:  // Init the transaction
  15:  bool fSuccess = refTC.BeginTransaction();
  16:  if (fSuccess)
  17:  {
  18:  fSuccess = refTC.CopyFile("d:\\transcopy.pdb", "d:\\t.pdb", false);
  19:  if (fSuccess)
  20:  {
  21:  fSuccess = refTC.Commit();
  22:  if (fSuccess)
  23:  {
  24:  Console.WriteLine("Copy successful!");
  25:  }
  26:  else
  27:  {
  28:  ShowErrorAndExit("Commit failed!", refTC.LastError);
  29:  }
  30:  }
  31:  else
  32:  {
  33:  ShowErrorAndExit("Copy failed!", refTC.LastError);
  34:  }
  35:  }
  36:  else
  37:  {
  38:  ShowErrorAndExit("Unable to start the transaction!", refTC.LastError);
  39:  }
  40:  }
  41:   
  42:  private static void ShowErrorAndExit(string p, int p_2)
  43:  {
  44:  Console.WriteLine("ERROR: {0}", p);
  45:  Console.WriteLine("CODE: {0}", p_2);
  46:  System.Environment.Exit(1);
  47:  }
  48:  }
  49:  }

Did you have a scenario where you wished you could customize the creation of AppDomains? Or, you could control how many AppDomains any code that runs in your application context (e.g. if you are writing a plugin load framework) could create? Or, how about reusing AppDomains for various assemblies?

I have just finished an article on how any of the above scenarios can be accomplished using the System.AppDomainManager type, introduced in .NET Framework 2.0, by intercept AppDomain creation requests.

You can read the article at http://www.wintoolzone.com/articles/Customizing_AppDomain_Creation.aspx and download associated source code from http://www.wintoolzone.com/downloads/Customizing_AppDomain_Creation_src.zip


One of the best ways to understand how the CLR works internally is to have a look at the SSCLI [a.k.a Rotor] source code.

In How the SSCLI [a.k.a. Rotor] managed "new" works, I have used Rotor source code to discuss what happens behind the scenes when you use the managed new operator to instantiate a managed type, discussing implications of object size, how requests from multiple threads are handled, the different validations that are done, when out-of-memory exception is thrown, etc. If you are a managed code developer, you may learn a thing or two that can help you write better code besides understanding how the managed allocation works internally.


One of the key new features of Windows Vista is a component called the Kernel Transaction Manager (KTM) that brings inherent support for transactional development in not just the kernel-mode but also for user mode. Infact, NTFS has been enhanced to use and support transactions such that couple of new APIs (e.g. CopyFileTransacted, MoveFileTransacted just to name a few) have surfaced up. You can get more details on Transactional NTFS here.

To demonstrate the power of the new APIs, I wrote a C++ class library (unmanaged), CTransCopy, that allows you to:

  • Copy files under a transaction
  • Move files under a transaction
  • Commit or Rollback the transaction
  • Let you wire up a callback handler for copy/move progress

You can download it from http://www.wintoolzone.com/ListWin32.aspx?Listtype=5. The zipped archive also contains a sample client source code. BTW, since the .LIB file containing the class was compiled using VC++ 2005 compiler, you will need the same to link against it and write an application. You can use VC++ 2005 Express Edition. Below is an example usage of the same:

 

CTransCopy tcopy;

if (tcopy.IsOSSupported() == FALSE)
{
printf("This application requires Windows Vista or later.");
return -1;
}

if (tcopy.Init() == FALSE)
{
printf("Init failed with error %08X\n",tcopy.LastError());
return -1;
}

// Setup a callback for progress
tcopy.SetCopyCallback(ProgressCallback);

if (tcopy.CopyFileW(L"D:\\KGK\\Development\\VS\\Windows Vista\\VC\\TransCopy\\debug\\transcopy.pdb",
L"D:\\transcopy.pdb",FALSE) == FALSE)
{
printf("Copy/move failed with error %08X\n",tcopy.LastError());
tcopy.Rollback();
return -1;
}

if (tcopy.Rollback() == FALSE)
{
printf("Rollback failed with error %08X\n",tcopy.LastError());
return -1;
}

if (tcopy.Commit() == FALSE)
{
printf("Commit failed with error %08X\n",tcopy.LastError());
return -1;
}

printf("Copy/move successful!\n");

The ProgressCallback function is implemented as shown below:

void ProgressCallback(LARGE_INTEGER total, LARGE_INTEGER transferred)
{
double percent = (transferred.QuadPart*100.00)/total.QuadPart;
printf("%f%% over\n",percent);
}