int re=0;
string buf=new String('\0',1024);
int siz=1024;
re=WinApi.GetComputerName(buf,siz);//在这句时出错
buf.Substring(0,buf.IndexOf('\0'));
Debug.WriteLine(buf);
...全文
615打赏收藏
未将对象引用设置到对象的实例,怎么解决??
int re=0; string buf=new String('\0',1024); int siz=1024; re=WinApi.GetComputerName(buf,siz);//在这句时出错 buf.Substring(0,buf.IndexOf('\0')); Debug.WriteLine(buf);
1. you need to declare GetComputerName as static
2. GetComputerName will fill the name in the first parameter you pass in, so you need to give it a StringBuilder or a byte[]
3. it also changes the last parameter to let you know how many long the name is