How to declare external lib in C#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I would like to retrieve the computer name in C#, here is the piece of code
in VB:

Private Declare Function GetComputerNameAPI Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

How do I translate to C#? thanks!
 
I believe this is the one you wanted to use

[DllImport("kernel32.dll")]
static extern bool GetComputerName(StringBuilder lpBuffer, ref uint
lpnSize);

http://www.pinvoke.net/ is a great source of WinAPI - C# related
information, check it out.
 
[DllImport("kernel32", EntryPoint= "GetComputerNameA")]
private static extern int GetComputerName(StringBuilder lpBuffer, ref int
nSize);
 
Back
Top