I see one obvious difference:
> Dim myComputerName As String = Space(30)
versus
> string myComputerName = "";
I don't really know how these things work, but I'd try changing that to:
string myComputerName = " ";
and see if it makes a difference.
"Dr. Zharkov" <valery-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello. To define a name of a computer in project VS 2005 after click of
> Button1 on Form1, on Visual Basic such code is used:
>
>
>
> Declare Auto Function GetComputerName Lib "kernel32.dll" _
>
> Alias "GetComputerName" (ByVal buf As String, _
>
> ByRef size As Integer) As Integer
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, _
>
> ByVal e As System.EventArgs) Handles Button1.Click
>
> Dim myComputerName As String = Space(30)
>
> Dim Length As Integer = 30
>
> Dim ReturnValue As Integer
>
> ReturnValue = GetComputerName(myComputerName, Length)
>
> MsgBox("Name of my computer: " & myComputerName)
>
> End Sub
>
>
>
> In other same project VS 2005, I have copied this code on Visual C# as
> follows:
>
>
>
> [System.Runtime.InteropServices.DllImport("kernel32.dll")]
>
> public static extern int GetComputerName(string buf, ref int size);
>
>
>
> private void button1_Click(object sender, EventArgs e)
>
> {
>
> string myComputerName = "";
>
> int Length = 30;
>
> int ReturnValue;
>
> ReturnValue = GetComputerName(myComputerName, ref Length);
>
> MessageBox.Show("Name of my computer: " + myComputerName);
>
> }
>
>
>
> Building this code occurs without errors, however the name of a computer
> is
> not deduced.
>
> Inform, please, where in a code on C# an error?
>
> Beforehand thanks for the answer, Valeriy, Moskva, Russia.
>
>
|