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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top