SPONSORS:






User Tag List

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Dec 1999
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    API Call not working

    I am using API calls in SILK 2.1 to get the name of the computer. I know SILK supports the GetMachineName function be we're not using it for various reasons. Anyway the DLL looks like this:

    [-] dll "kernel32"
    [ ]
    [ ] LONG GetComputerName (out STRING sBuffer, LONG lSize) alias "GetComputerNameA"

    The function I use to get the computer name is:

    [-] hidecalls STRING ComputerName()
    [ ]
    [ ] STRING sName
    [ ] STRING sReturnValue
    [ ]
    [ ] sName = Replicate(Chr(20), 145)
    [ ] sReturnValue = trim (left(sName, GetComputerName(sName, len(sName))))
    [ ]
    [ ] return (sReturnValue)

    And then I call it by:

    [-] main()
    [ ] STRING sComputerName = ComputerName()

    However every time this runs I get the following error message:

    [ ] *** Error: Exception in DLL call -- Function GetComputerNameA: code 0xc0000005, flags 0x0, address 0x77f05974
    [ ] Occurred in ComputerName

    I have used other kernel32 DLL calls and they work fine but this one does not seem to at all. Does anyone know what I'm doing wrong?

  2. #2
    Senior Member
    Join Date
    Dec 1999
    Location
    Chicago,Illinois,USA
    Posts
    2,537
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Re: API Call not working

    The reason is actually because you are following the API too closely. Your DLL declaration should look like this:

    [-] dll "kernel32"
    [ ]
    [ ] INT GetComputerName (out STRING sBuffer) alias "GetComputerNameA"

    Notice I removed the size parameter. Then you can make your function like this:

    [-] STRING ComputerName()
    [ ]
    [ ] STRING sName
    [ ] LONG lReturnValue
    [ ]
    [ ] sName = Replicate(Chr(20), 145)
    [ ] lReturnValue = GetComputerName(sName)
    [ ]
    [ ]
    [ ] LogError (sName)
    [ ] return (sName)

    This should get you what you need. You would also find this to be the case if you used something like GetUserName however it is not the case for such API calls as getting the Windows system path. It depends on the nature of the API call you are making and what is returned.

    Also: the GetMachineName function in Silk that you mention is not the same thing as what you want here. However, Silk 5.x does have a GetComputerName function built-in.

    Hope this helps.

 

 

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 12:18 PM.

Copyright BetaSoft Inc.