SPONSORS:






User Tag List

Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    API call not working: insufficient buffer size on String parameter

    I am trying to use the GetUserName function declared in advapi32.dll. I have got it so that it runs without raising an exception, but something is going wrong in the function call. Here is the code I am using:
    When I run this testcase, the string is returned unchanged (whatever it's initial contents were, I have tried that); the buffersize variable is set to 6 and the returnedvalue is 0. The zero indicates some kind of error condition (it returns a positive number if everything went well); the buffersize being 6 indicates that it was in some sense trying to return a 5-character string making up a 6-character null-terminated string. The name I was logged in as was "vince", so this is what I was expecting.
    Using another api call GetLastError, it turns out that the error was number 122, ERROR_INSUFFICIENT_BUFFER ("The data area passed to a system call is too small.")

    I have tried padding my username string to more than six characters before submitting it to the GetUserName function, but this doesn't make any difference.

    Is it just not possible to call a function where one of the parameters has to be a "pointer to a buffer"? Or am I doing something wrong here?

    ------------------

  2. #2
    Junior Member
    Join Date
    Nov 1999
    Location
    VIENNA, AUSTRIA, EUROPE
    Posts
    16
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: API call not working: insufficient buffer size on String parameter

    hi, i working with this code, try it.

    ANDALL

    ------------------

  3. #3
    Advanced Member tonymro's Avatar
    Join Date
    Jul 1999
    Location
    Deep in the Coast Range Mountains of Oregon, USA
    Posts
    562
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: API call not working: insufficient buffer size on String parameter

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>I have tried padding my username string to more than six characters before submitting it to the GetUserName function, but this doesn't make any difference.<HR></BLOCKQUOTE>

    You're halfway there. You need to set buffersize to the size of the username string that you have preloaded with spaces. Something like:

    LONG buffersize = 1000
    STRING username = Replicate(" ", buffersize)

    ------------------
    Tony Mrozinski
    Sr. Software Test Automation Engineer
    Sr. Software Test Automation Architect

  4. #4
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: API call not working: insufficient buffer size on String parameter

    Brilliant, thanks both of you.
    P.S. A little bit more experimentation reveals that the contents of the string are irrelevant, it is just the buffersize parameter that matters.

    ------------------

 

 

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 02:30 PM.

Copyright BetaSoft Inc.