1. Andy Preman
  2. PowerBuilder
  3. Monday, 22 February 2021 14:45 PM UTC

Hello,

How do I get the FQDN of the computer I am running on.  There is a Windows function GetComputerNameEXA, however it uses an enumerated datatype, from which I gathered is not supported in Powerbuilder.

I am looking to get something like 'mycomputer.mydomain.com'

Does anyone have any suggestions?

Thanks,

Andy

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Monday, 22 February 2021 17:08 PM UTC
  2. PowerBuilder
  3. # Permalink

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

Comment
  1. Armeen Mazda @Appeon
  2. Monday, 22 February 2021 20:14 PM UTC
And please mark which answer is correct.
  1. Helpful
  1. Joseph Vendra
  2. Saturday, 4 March 2023 19:09 PM UTC
Should the declaration include REF String lpBuffer, &

ie:

FUNCTION Boolean GetComputerNameEx ( &

Long NameType, &

REF String lpBuffer, &

REF ULong nSize &

) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameExW"

Worked fine after that.
  1. Helpful
  1. John Fauss
  2. Saturday, 4 March 2023 19:29 PM UTC
Yes, Joseph - It should, since the WinAPI documentation shows it to be an output argument. Good catch, and thank you for pointing this out!
  1. Helpful
There are no comments made yet.
Andy Preman Accepted Answer Pending Moderation
  1. Monday, 22 February 2021 16:58 PM UTC
  2. PowerBuilder
  3. # 1

Roland,

Thanks for the reply.  So how would I define the 'GetComputerNameEXA' function in 'Global External Functions'?

Andy

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 22 February 2021 16:33 PM UTC
  2. PowerBuilder
  3. # 2

An enumeration is a number starting at zero for the first value.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.