Get Computer name (char * parameter) : Native Windows Function : Windows C# Examples


C# Examples » Windows » Native Windows Function »

 

Get Computer name (char * parameter)









    
using  System;
using  System.Runtime.InteropServices;

class  MainClass
{
    [  DllImport(  "kernel32.dll"  )  ]
    static  extern  unsafe  bool  GetComputerNameW(  char*  name,  ref  ulong  size  );

    [STAThread]
    static  unsafe  void  Main(string[]  args)
    {
        ulong  size  =  256;
        char*  name  =  stackalloc  char[  (int)size  ];

        bool  success  =  GetComputerNameW(  name,  ref  size  );

        for  (  uint  i  =  0;  i  <  size;  i++,  name++  )
        {
            System.Console.Write(  *name  );
        }
    }
}
    
   
  
   



Output

navioo


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Windows
» Native Windows Function