To call a Windows API function:
Unicode: Implemented as GetUserNameW (Unicode) and GetUserNameA (ANSI) Required DLL: AdvAPI32.DLL
lpBuffer: Pointer to the buffer to receive the null-terminated string containing the user's logon name
nSize: On input, this variable specifies the size of the lpBuffer buffer, in TCHARs. On output, the variable receives the number of TCHARs copied to the buffer, including the terminating null character.
77 user-name PIC X(40). 77 var-size PIC 9(9) COMP-5.
set environment "dll_convention" to 1.
Call "advapi32.dll" On exception go to err-load
Set var-size to size of user-name. call "GetUserNameA" using by reference user-name by reference var-size
Other functions have parameters requiring the use of BY VALUE instead of BY REFERENCE. Read the Microsoft documentation carefully to make sure you pass parameters the proper way.
inspect user-name replacing all low-values by space.
cancel "advapi32.dll"
Note that DLLs loaded with "-y" or SHARED_LIBRARY_LIST cannot be cancelled or unloaded.
These general steps should be enough to get you started.