CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Posts
    87

    GetComputerName() function

    Why is my program doesn't recognize the function
    GetComputerName()? Do I need to include some dll for these to run?

    Please help.
    Thanks.

    cecile


    The more u read, the more u do not know

  2. #2

    Re: GetComputerName() function

    GetComputerName is an API function
    U must declare in declaration zone...

    public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long




    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  3. #3
    Join Date
    Aug 2000
    Location
    Namibia
    Posts
    139

    Re: GetComputerName() function

    The function is part of the API try this:
    Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long


    Note also that there are returned parameters, so you would eventually get the computername from left$(sBuffer,lSize).

    HTH


  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: GetComputerName() function


    'from api-guide (a free tool!)
    'Requires Windows NT 3.1 or later; Requires Windows 95 or later
    'The GetComputerName function retrieves the computer name of the current
    'system.
    'This name is established at system startup, when it is initialized from the
    'registry
    'copy paste this in a form code, or change the api declaration to public
    'to use it from a .bas module
    private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long
    private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim strString as string
    'Create a buffer
    strString = string(255, Chr$(0))
    'get the computer name
    GetComputerName strString, 255
    'remove the unnecessary chr$(0)'s
    strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
    'Show the computer name
    MsgBox strString
    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured