jump to navigation

Let’s Build A Compiler For The CLR March 9, 2007

Posted by suniljagadish in .NET, Programming.
add a comment

Wow, only now I realized that Raj has mentioned my name in the context of his book which is titled – “Let’s Build A Compiler For The CLR“. Thanks Raj! His book is a wonderful piece of writing. Raj has struck a very nice balance between the geek-ness and simplicity. Do read it if stuff like Compilers fascinates you.

Windows Dev Live Beta launched June 10, 2006

Posted by suniljagadish in Microsoft, Programming.
1 comment so far

When everything is going the Live way (Mail Live, Windows Live, Live Messenger etc.), why not something for Developers?

http://dev.live.com

Maximum identifier length in .NET June 4, 2006

Posted by suniljagadish in .NET, Programming.
add a comment

I was just curious to know the maximum length of the name of an identifier in the .NET world, which would be acceptable to the compiler. It happens to be 518. I wonder, if there is a funda behind it.

This is what I tried-

static void Main(string[] args)
{
string xxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaaaaaqqqqqqqqqqqqqccc
cccczzzzzzwwwwwlllllllllllfffffffffffddddddddddddddddddddddddddk
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
dddddddddddddddddddddddddddddddddddddddddddddkddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddd = "Hello!";

Console.WriteLine(xxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaaaaaqqqqqqqqqqqqqccc
cccczzzzzzwwwwwlllllllllllfffffffffffddddddddddddddddddddddddddk
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
dddddddddddddddddddddddddddddddddddddddddddddkddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddd);
Console.Read();
}

LINQ – Language INtegrated Query June 4, 2006

Posted by suniljagadish in .NET, C#, Programming.
add a comment

Language INtegrated Query (LINQ) is an extension to the capabilities of .NET languages (currently C# 3.0 and VB 9.0) to perform SQL-like operations on any source of data. The conventional data sources that we’ve been using today are databases, flat files, XML documents etc. LINQ defines certain standard query operators that enable set operations, traversal, projection, selection, join (the relational algebra stuff) to be performed on non-conventional sources of data, which is IEnumerable<T>-based. This means that you can use LINQ to query data from sources such as the enumeration of the list of processes running on your machine. I found this neat example here.

To get started with LINQ, you need to download the LINQ SDK (May 2006). I delivered a session on LINQ at the BDotNETStudent UG meet.

One of my demos included querying a String collection.

Code:

string[] names = {"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David"};
var q = names
           .Where(s => s.Length > 4)
           .OrderBy(s => s.Length)
           .Select(s => s);
foreach(var i in q)
           Console.WriteLine(i);

A simple query which selects those names from the collection which have a length greater than 4 and the same is then ordered based on the length of each string (in ascending order).

The output:

Frank
David
Burke
George
Harris
Connor
Albert
Everett

Here you’d observe that though “Burke” appears before “Frank” in the original collection, after the execution of the query, the order isn’t preserved. This is because; the OrderBy operator implements an unstable sort algorithm to order the elements.The subtle difference between OrderBy in LINQ and SQL is that, in case of SQL, a query like-

select * from tab_names order by len(sname)

would result in:

Burke
Frank
David
Albert
George
Harris
Connor
Everett

Links:

LINQ Project on MSDN
Download LINQ SDK
LINQ Samples
Anders Hejlsberg on LINQ [Channel9 video]
LINQ Intro

Interesting numbers in the Windows Mobile 5.0 Device Emulator February 6, 2006

Posted by suniljagadish in .NET CF, Old posts, Programming, Windows Mobile.
add a comment

Check out Barry Bond's post about a few numbers in the WM 5.0 Device Emulator that can be used to test busy numbers, never answer numbers etc.

Windows Mobile 5.0 Message Interception January 30, 2006

Posted by suniljagadish in .NET CF, Old posts, Programming, Windows Mobile.
4 comments

I delivered a session on Windows Mobile programming with a focus on WM 5.0 in Coimbatore during the MSDN @ Campus event. I demonstrated a Bluetooth application using the 32feet API and Message Interception API in WM 5.0. I am reminded to point out that Peter Foot of the OpenNETCF fame, has separated a few APIs including the Bluetooth library into 32feet, which is worth noting for Bluetooth enthusiasts.

I have uploaded my demos here-

Bluetooth demo (scenario was communication between a PPC and a Desktop machine at a Pizza Company)
[Demo will be upload the shortly]

Download the SMS interception demo

The SMS Interception demo has inline documentation to help you understand its working.

/*
*
* ———————————
* Running the application
* ———————————
*
* 1. Make sure you have VS 2005 and Windows Mobile 5.0 PocketPC SDK installed
* 2. Run the application and use the Windows Mobile 5.0 PocketPC Phone Emulator
* 3. Click on the “Start” button to start the SMS Interceptor
* 4. This application will peek at all SMS’s received henceforth and process them
* if the SMS body is prefixed with the word “ASTRO”
* 5. Valid format for getting prediction: ASTRO dd-mm
* 6. Open the “Messages” in the PocketPC and create a new SMS, say, ASTRO 20-8
* (for 20th Aug) and send it to +14250010001, which is a fake number.
* Any Phone calls or SMS’s to this number is a reference to the emulator itself.
* 7. Once the SMS is sent, it appears in the list box. If it were to be an SMS
* without prefix “ASTRO”, the application will leave it to be read by the user.
* 8. This can be observed when the prediction is sent. This SMS lands in the Inbox.
* 9. To stop the Message Interception, click the Stop button
*
* More reading info on SMS interception API in WM 5.0:
* http://blogs.msdn.com/windowsmobile/archive/2005/07/09/437189.aspx
* http://www.pcquest.com/content/search/showarticle1.asp?arid=75833&mode=disp
*
* Windows Mobile 5.0 PPT – TechEd
* http://download.microsoft.com/download/9/f/a/9fadc29f-8df1-486f-b200-94f79ee7a7de/MED%20303%20New%20Managed%20APIs%20Controls,%20Messaging%20and%20Telephony.ppt
*
*/

I got mails from many people reporting a problem in downloading the code. So, I’ve uploaded it here – http://suniljagadish.googlepages.com/SMSInterception.zip

Visual Studio Power Toys and Code Snippet Editor January 19, 2006

Posted by suniljagadish in .NET, Old posts, Programming.
1 comment so far

I just completed a bluetooth demo for a Windows Mobile presentation that I'd doing at MSDN @ Campus, Coimbatore.

Code snippets is a very good feature which is helpful especially while doing demos. It is good to see the snippets wrapped within a neat XML schema. But, I thought it is slightly cumbersome to create a code snippet. The Powertoys blog has a pointer to a very cool tool – Snippy, which makes snippet creation quite simple.

Creating code snippets [MSDN]
Creating and Using Code Snippets in Visual Studio 2005 [4Guys From Rolla]
Code snippet XML schema reference [MSDN]

You can find some ready-to-use code snippets in GotCodeSnippets. It doesnt contain many snippets, but a cool initiative.

Web Services – Cool demo November 30, 2005

Posted by suniljagadish in .NET, Old posts, Programming.
add a comment

The other demo I showed during the launch of Microsoft Academic Projects was to demonstrate the web services. Though this demo may not have real business application, one will be able to guess the power of Web Services and its extensibility.

I setup my webcam at home and used TinCam, to dump images shot from the webcam into a folder at a given interval. I referred this article and used Binary Serialization to transmit the images from my PC to the Web Service consumer application which is a simple WinForms application.

A very simple application, but cool to watch. Download the source here.

Power Management API in Platform SDK November 30, 2005

Posted by suniljagadish in .NET, Old posts, Programming.
add a comment

I demonstrated the Power Management API of the Microsoft Platform SDK during the launch of Microsoft's Academic Projects Program here in Bangalore.

Microsoft Platform SDK is a colelction of powerful APIs which you can play around with to do a bit of system-level programming. You could use the Microsoft VC++ compiler to compile your programs.

The Power Management Demo I showed is pretty simple and straight-forward. The user is intimated through an alert when there is a change in power source. In a real-time scenario one could perform actions to change the execution state/processor consmption of the application when the computer is running on battery. This is done using one simple function:

BOOL GetSystemPowerStatus(
  LPSYSTEM_POWER_STATUS lpSystemPowerStatus

);

to which you would have to pass the reference of an object of type SYSTEM_POWER_STATUS structure. The power source is indicated by the value of the structure variable ACLineStatus (0 – Battery, 1 – AC Power & 255 – Unknown).

In the main window message processing function (WndProc), you can invoke this function when the WM_POWERBROADCAST message is received.

case WM_POWERBROADCAST:

BOOL ret;

SYSTEM_POWER_STATUS sps;

ret = GetSystemPowerStatus(&sps);

if(sps.ACLineStatus)

MessageBox(hWnd,TEXT("You are on AC power"),TEXT("Power Management Demo"),0);

else

MessageBox(hWnd,TEXT("You are on battery power"),TEXT("Power Management Demo"),0);

By responding to the PBT_APMQUERYSUSPEND message, an application can put off a suspend request from the operating system. The application will need to respond with a BROADCAST_QUERY_DENY, if the application cannot allow the system operations to be suspended. The Power Management API has other useful features to support automatic wake-up using the System Wake-up Events.

[Download Source]

Read about using Microsoft Visual C++ 2005 Express with Platform SDK.