How To Find Whether The Machine Is of 32-Bit/64-Bit Architecture

13. May 2010 22:22

.NET Framework C# Code Snippets 

The easiest way to find out the processor architecture is to use the Environment class GetEnvironmentVariable method


This will print the processor architecture on the console window i.e. x86 and x64 for 32-bit and 64-bit respectively.

Currently rated 5.0 by 1 person

Windows 7 API Development and Training Kit

15. January 2010 12:21

.NET Framework API Microsoft Windows 

I recently installed Windows 7® Ultimate on my machine and found it more soothing and reliable in terms of preformance than Windows Vista® Ultimate. As a tech enthusiast, I do some serach on the internet and found two links from Microsoft website that will allow developers to develop applications specifically for Windows 7. The Windows API code pack allows developers to develop those features which are not available with .NET Framework. So to get started visit:

  1. Windows® Code Pack API for Windows 7 & Windows Vista

  2. Windows Training Kit

The training kit includes the demos and presentations, hand-on labs for developers. I haven't yet started with Windows 7 development. But as soon as I get started I will blog some demo for Windows 7.

Currently rated 5.0 by 1 person

How to plug-in a DLL into a C# project

7. January 2010 16:58

.NET Framework C# 

John Grove share a code at MSDN on how can we call DLLs methods dynamically using C# code.

The below code can further be modified and a developer can easily extend the functionality of his application to create a application which accepts DLLs as plug-ins. This concept is useful when different users have different requirements in a generalized application like in the case of famous photo editing program Photoshop from Adobe. Here anyone can create a plug-in and hook it up with the host application which further inherits all the functionalities from the DLL.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            Assembly assembly = Assembly.LoadFrom(@"C:\Documents and Settings\john.grove\MyMath.dll");
            Type mathUtility = assembly.GetType("MyMathUtilty");
            Object theInstance = Activator.CreateInstance(mathUtility);
            Int32 result = (Int32)mathUtility.InvokeMember("Add", BindingFlags.InvokeMethod, null, theInstance, new object[] { 56, 26 });
            Console.WriteLine("Dynamically invoking MyMathUtilty Add method");
            Console.WriteLine("56 + 26 = {0}", result);

            // get all public static methods of MyMathUtilty type
            MethodInfo[] methodInfos = mathUtility.GetMethods(BindingFlags.Public | BindingFlags.Static);
            Console.WriteLine("All public/static methods in MyMathUtilty");
            for (Int32 i = 0; i < methodInfos.Count(); i++ )
                Console.WriteLine("{0}.) {1}", i + 1, methodInfos[i].Name);
Currently rated 4.0 by 2 people

Removing Duplicates from a List in C#

24. December 2009 18:25

.NET Framework C# Code Snippets 

For more details and detailed explaination of the code visit this link.

static List removeDuplicates(List inputList)

            Dictionary uniqueStore = new Dictionary();
            List finalList = new List();
	    foreach (string currValue in inputList)

                if (!uniqueStore.ContainsKey(currValue))

                    uniqueStore.Add(currValue, 0);


            return finalList;
 No Rating

Protect your .NET Applications/Libraries from 'Reflection'

23. December 2009 00:18

.NET Framework Utils 

As a programmer, you put a lot of effort to create an application and incorporate some unique features in your application, which in turn makes your application more feature rich and different from other applications. The question here is, how do you feel when you come to know that someone has played with your code and then make a same application with his name...You did all the hard work and some random guy on this blue planet stole your code and takes all the credit.....Cry????

Well the answer lies in Obfuscation. It is a method to prevent your application from being reverse engineered. It makes the code of your application in unreadable form when it is viewed in any reflection tool. You will find many obfuscator tool, but some of them are not free and others are not ease at use. I do some search over the net and found a totally free and reliable tool for obfuscating my applications and libraries. This free obfuscating tool can be downloaded from here. The version here supports obfuscations for .NET framework 3.5 and for .NET framework 4.0, well we have to wait for the final release as it is still in beta but can be downloaded from here.

Let's see Red Gate's Reflector and Eazfuscator.NET (actual name of the obfuscater tool) in action

First I created a basic simple greeting application in Visual Studio 2008 (.NET Framework 3.5). The application has two buttons which greets the user and world respectively. Now take a look how the binary is diassembled by using reflector.

And now we will use Eazfuscator.NET to obfuscate our application. So first download and install the obfuscator tool form the above link and then simple drag-n-drop application on the right segment. I remommend to read the whole documentation before you start obfuscating your application and assemblies and make sure you have a bacup of your original application before you proceed.

Drag and drop your application here.

As soon as you drop your binary here the obfuscation process will start automatically.

And thats it, your code is now safe and you can distribute you applicaion without any more worries and for those who want to use the code just looking into the reflector and dont' want to scratch the heads we have this >>>> Money mouth!!!!

Now try opening your obfuscated application in reflector....and this is what you will see.Cool

 No Rating