1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

@winapi

Discussion in 'Support' started by djspits, Oct 29, 2014.

  1. djspits

    Joined:
    Apr 13, 2010
    Messages:
    189
    Likes Received:
    2
    Using:
    TCC 16.03.55 x64 Windows 8.1 [Version 6.3.9600]
    TCC Build 55 Windows 8.1 Build 9600

    See also
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724435(v=vs.85).aspx

    The following call should return the full user name.
    GetUserNameEx(3) is implemented in Secur32.dll

    Works with the following python code:
    Code:
    >>> import win32api
    >>> print(win32api.GetUserNameEx(3))
    Using @WINAPI[] however, I fail to get the desired string.

    I have studied the docs but and tried as many variants as I could think of but none of them work.
    Also, I must admit, I fail to fully understand the syntax of the "BUFFER thingy". When to use and how to use it.

    I would appreciate some clarification.

    Regards, DJ
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,352
    Likes Received:
    39
    How about:
    Code:
    echo %@winapi[C:\WINDOWS\system32\secur32.dll,GetUserNameEx,3,buffer,plong=256]
    
    I don't know how long the actual buffer TCC allocates is. 256 characters seems like a conservative guess.
     
    djspits likes this.
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    Apparently it only works with NameFormat = NameSamCompatible = 2.
    Code:
    v:\> do i=0 to 12 (echo %@winapi[secur32.dll,GetUserNameEx,%i,BUFFER,PDWORD=256])
    ECHO is OFF
    ECHO is OFF
    zz\vefatica
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    ECHO is OFF
    This also works.
    Code:
    v:\> echo %@winapi[advapi32.dll,GetUserName,BUFFER,PDWORD=256]
    vefatica
    If a [a]BUFFER is specified, %WINAPI will output the contents of the buffer (instead of the return value of the function).
     
    djspits likes this.
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    .... which is very peculiar since, in an EXE, this code,
    Code:
        for ( INT i=0; i<13; i++ )
        {
          GetUserNameEx((EXTENDED_NAME_FORMAT) i, szUserName, &(size=256));
          wprintf(L"%s\n", szUserName);
        }
    
    which includes some non-existing formats, produces the following (which includes some odd results)! I have no idea what "lume11" is.
    Code:
    lume11\Projects\test\Release\test.exe
    lume11\Projects\test\Release\test.exe
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
    zz\vefatica
     
  5. djspits

    Joined:
    Apr 13, 2010
    Messages:
    189
    Likes Received:
    2
    Thanks very much, guys. You solved a long standing problem.

    Would you agree with me that the help could use some improvements? A few examples perhaps?

    I mean, I'm very impressed with the apparent ease with which you seem to have decoded the syntax definition of this function, but I wasn't and I'm pretty sure many other customers won't be able to do that.

    Regards, DJ
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    I had that wrong (printing an uninitialized/leftover string when the function failed). If I clear the string every time (as I should have) this function works only when the format arg is 2.
     

Share This Page