Hi, Andy -
First, I suggest you use the GetComputerNameExW (Unicode) flavor of this API function instead of the ANSI flavor.
This API function uses a value of the COMPUTER_NAME_FORMAT enumeration, which the online Win API documentation shows is defined as follows:
typedef enum _COMPUTER_NAME_FORMAT {
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
} COMPUTER_NAME_FORMAT;
As Roland points out, an enumeration is a whole-number series that begins at zero. Thus, ComputerNameNetBIOS = 0, ComputerNameDnsHostName = 1, ComputerNameDnsDomain = 2, etc.
I believe an enumerated data type in C/C++ is equivalent to a Long in PB. Therefore, the external function declaration in PB should be something like:
FUNCTION Boolean GetComputerNameEx ( &
Long NameType, &
String lpBuffer, &
REF ULong nSize &
) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameExW"
You must pre-load the string argument with a sufficient string of space characters prior to calling this Windows API function. Typically, this is done via a PowerScript statement such as:
ls_buffer = Space(256) // example
Make sure you load a sufficient number of spaces to handle the longest value that the API function can return (refer to the Win API documentation).
Here is the URL for the Microsoft online documentation on this API function:
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getcomputernameexw
HTH
Regards, John
ie:
FUNCTION Boolean GetComputerNameEx ( &
Long NameType, &
REF String lpBuffer, &
REF ULong nSize &
) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameExW"
Worked fine after that.