Tuesday, 29 September 2015

Working with pointers And addresses in c# /.Net


These points needs to be remember.

1. As pointers are not safe from memory point of view. So they are categories as unsafe/unmanaged code.

2. If you want some work having pointer you must have unsafe keyword with function declaration.

       static unsafe void Check() {}

3. Unsafe code is handled by OS directly not by CLR.

4. Unmanaged object's address can be accessible through it.

An example having string,int points use

static unsafe void Check()
        {
            string s = "saurabh";
            string s1 = "saurabh";
            int x = 10;
            int y = 10;

            fixed (char* pointer = s1)
            {
                Console.WriteLine("dsds");
            }

            fixed (char* pointer1 = s)
            {
                Console.WriteLine("dsds");
            }

            //void* add1 = &s;
            //void* add2 = &y;

            //Console.WriteLine(x, (int)add1, *add1);
        }
    }


Note : To build unmanaged code from c sharp or vs you have to allow build unsafe code from project property build tag.


Wednesday, 24 December 2014

Not able to remove the Window service

There are following ways to remove window service :

1. From visual Studio command Prompt:

Just go to Visual studio command prompt from Start Menu.
Then in visual studio command prompt type as below:
     
     >installutil.exe  /u "Here your service directory with it its exe"          press enter.

Example:    >installutil.exe  /u    "c:/programfiles/myservice/service.exe"

2. If you have installed a window service from a installer then you can remove it from add/remove programs in control panel.

3. This is a case which i face so want to share it with you.

  1. Installed a Windows service from installer but i uninstalled it from command prompt. But its files still exist there in the directory where it was installed.
  2. Then the real problem caused.that service got removed from Services but still available in add/remove programs
  3. Then i want not able to install new version of service coz it say this service already exist and neither i can remove it from add/remove programs.
  4. To resolve this just install the service from the directory files using command prompt with install util command then it will be installed and then you can remove it from add/remove section.
            >installutil.exe "c:/programfiles/myservice/service.exe"