December 2005 - Posts
Thanks for all who sent me seasonal wishes. I never knew I have
this much of friends. My phone is full of sms’s and my inbox full with
greetings. I receive more wishes this year compare to last year. Maybe last year
was the first Christmas for me in Sri Lanka after three years. So they
might have forgotten me that time. But this year, boy I had a wonderful time. I
really enjoyed my self.
I know that F# has been availalbe for some time now. But today only i had a chance to keep my hands on it. more:
http://research.microsoft.com/projects/ilx/fsharp.aspx
If you want to find out new features, enhacements for the CLR Loader
this is a place to start. I highly recommending you to read it
regulary.
http://blogs.msdn.com/suzcook/
One of my friends forward me this link. Its about the language popularity.
http://www.tiobe.com/index.htm?tiobe_index .Will
C# catch the JAVA soon?? any ideas guyss?? Recently i installed
JBuilder in my system coz i wanted to do a project in java(for my
sister). Jbuilder IDE is damn slow compare to VS 2005(with running
512mb Ram). At least it needs 1 GB. :| So i just asked from a java guy
the reason, he just told me "Its java man..". I was wondering
what does he mean.. If its taking more hardware resources does it mean
its a good language?? Java guys no offense meant ;). I still prefer VS
2005 for my developement. I used JBuilder for some time, but defently
its not my type.. Since im not expert in Java and its features i will
refrain commenting the language features... but C# Enum and Properties
will defently comes to mind. ;) if anybody has an idea about the cool
features java has over c#, pls comment on this.
I’m doing some research on interop programming in these days(System.Runtime.InteropServices).
The requirement was to call some native twain32.dll functions from the managed
code. It’s for a scanner application. After doing some google I found out some
interesting concepts of doing interop programming. So I will outline some of
the important factors of Interop programming. Hope this will helps begin
program in interops.
What is Interop Programming?
It’s a term that used to describe interacting with the native
API’s in the underlying platform.
What are Pointers?
You must have heard the term called pointers before. But for
the beginners, here is a small desc about Pointers. Pointers are special kind
of variable which holds address of other variables.
e.g
int* p;
int x = 10;
p = &x;
So in the above sample p is the pointer for x. We’re putting
x memory address to the p.
Ok let’s go and see a real code sample. In the below code
sample what im trying to do is to get the System(Computer) name from the native
kernel32.dll. I know that we can easily do it in .net library. I just wanted to
show you how to call native methods in managed code. FYI: you have to refer to
the API library documents to get to know about the methods and parameter
values.
[DllImport("kernel32.dll")]
static extern
unsafe bool
GetComputerName(byte* ipBuffer, long* nSize);
public void GetComName()
{
byte[] buffer = new
byte[512];
long size = buffer.Length;
//you have to use this keyword when you calling
unsafe code from the managed code. Set the Project > Property > ConfigurationProperty > Allow Unsafe Code Block to true
unsafe
{
long* pSize = &size;
fixed(byte* pBuffer= buffer)
{
GetComputerName(pBuffer,pSize);
}
}
System.Text.Encoding enc= new System.Text.ASCIIEncoding();
Console.WriteLine("Computer : " + enc.GetString(buffer));
}
So it’s done. Native methods are faster than the .Net
Library. But there are some disadvantages. i.e. Memory Leaks, System Crash and
so forth. Here is another sample code to get the hard drive available
capacity through InteropServices.
[DllImport("kernel32.dll")]
static extern
int GetDiskFreeSpaceEx(string
drive, ref UInt64 FreeBytesAvailableToCaller, ref UInt64 TotalNumberOfBytes, ref UInt64 TotalNumberOfFreeBytes);
public void GetFreeSpace(string path)
{
UInt64 available =0 ;
UInt64 total=0;
UInt64 free=0;
unsafe
{
UInt64 inMb =0;
if(GetDiskFreeSpaceEx(path, ref available, ref
total, ref free) > 0)
{
inMb = (available)/(1024*1024);
}
Console.WriteLine(total.ToString());
Console.WriteLine(inMb.ToString());
}
}
All the comments are highly appreciated.
System.Net.NetworkInformation is a new namespace in .net 2.0 and believe
me there are some interesting classes inside.So i will talk about the Ping class
which is new to the .net 2.0. With this Ping class we can easily
check whether the computer is accessible over the network or not. The
best thing to explain is from a sample. So I will go ahead and
give a code sample for the Ping class which i
have done. You can extend the code and modify it in your own way.
System.Net.NetworkInformation.Ping ping = new
System.Net.NetworkInformation.Ping();
Console.WriteLine("Server Name : ");
System.Net.NetworkInformation.PingReply reply =
ping.Send(Console.ReadLine());
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
{
Console.WriteLine("Server : {0}", reply.Address.ToString());
Console.WriteLine("time to live: {0}", reply.Options.Ttl.ToString());
Console.WriteLine("Time : {0}", reply.RoundtripTime.ToString());
}
else
{
Console.WriteLine("Failed to connect!");
}
Microsoft's research released a free tool (aka SNARF) to help
users slog through e-mail messages in their inbox in the order of importance.
SNARF is available as a free
download. The software requires Microsoft Outlook 2002 or 2003 as a MAPI
(Messaging Application Programming Interface) source, but also has been tested
with Exchange and MAPI servers, Hotmail, and e-mail clients using POP (Post
Office Protocol), IMAP, and the OL Connector (for Lotus Notes).
Goole has added a virus scanning feature to its gmail service. It will
be nice feature specially if we can send .exe files through gmail.
Microsoft has changed the Community technology preview schedule for
Windows Vista. Vista CTP will only be released on an as-needed.
Rather than monthly builds. I think this will result much sharper
system with less bugs.
Ever thought of downloading files with the System.Net.WebClient. While
i was searching for classes in the System.Net, i found the class
WebClient which gives us to download, upload files through http and
more. I never uses that class in real project. Thought to do some
testing on that. You could upload the files from your local system to
web. But remember i never test this on real world app. There are
some security issues. Any comments ???
(remember to give rights to the webapp folder)
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://ludmal/HTTPDownloader/test.txt",
"C:\\test.txt");