473,383 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to declare external lib in C#?

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!

Nov 17 '05 #1
4 11915
[DllImport("kernel32", EntryPoint= "GetComputerNameA")]
private static extern int GetComputerName(StringBuilder lpBuffer, ref int
nSize);

"cloudx" <cl****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
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!

Nov 17 '05 #2
"cloudx" <cl****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
I would like to retrieve the computer name in C#


Hi. Use System.Environment.MachineName instead.

-- Alan
Nov 17 '05 #3
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.

"cloudx" <cl****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
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!

Nov 17 '05 #4
"cloudx" <cl****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
How do I translate to C#?


In general, you can go to

http://pinvoke.net/

to find many Win32 declarations. They look a lot like VB6.
GetComputerName() is at

http://pinvoke.net/default.aspx/kern...etComputerName

-- Alan
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: b83503104 | last post by:
Previously, when my constructor had no arguments, I used this to declare my objects: MyClass myObject; Now, my constructor has arguments (MyClass::MyClass(int someVariable)), how do I declare...
6
by: rick | last post by:
Noob problem. I prefer to keep all my scripts in an external '.js' file. I am currently loading the external '.js' file from the header. Problem is I would like to declare a global variable in the...
7
by: Brian Sammon | last post by:
According to my programming textbook, "int a;" at the top level of a file is a definition which shouldn't go in a header file. However, I'm running into a lot of online documentation that treats...
7
by: Kobu | last post by:
The code below isn't compiling for me (error message: conflicting types for 'total' - pointing to the extern declaration). Why wouldn't this work, since the types are different, the extern...
6
by: **Developer** | last post by:
Notice below I sometimes used the "A" version. I found by cut-and-try that only the "A" version would work correctly. Anyone have a suggestion of why the "W" version would not work correctly? ...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
4
by: barcaroller | last post by:
I was thinking of buying Scott Meyer's second book (More Effective C++) and noticed that it has not been updated since 1995 (unlike his other two famous books). Does anyone know (rumour or...
27
by: arkmancn | last post by:
Any comments? thanks. Jim
0
by: Amirallia | last post by:
Hi, It is possible to declare the mctest.dll library without defining the c:\Temp path in hard code. Declare Ansi Sub pst_Test Lib "c:\temp\mctest.dll" Alias "pst_Test" (ByVal intNomPtr As...
0
by: constructor | last post by:
Hello NG, I'm having to use a function in an external library that returns a pointer to an array of structs. The function declaration according to library vendor is: device** getList( int...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.