Kbase P14423: How to Call WIN32 API Function: GetComputerName
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  03/03/2004 |
|
Status: Unverified
GOAL:
How to Call WIN32 API Function: GetComputerName
FIX:
The following sample code shows how to call the Win32 API function
called GetComputerName. This function returns the name of the
computer at the time the system was started.
This code has been tested on Windows NT 4.0 Workstation only.
DEFINE VARIABLE chrComputerName AS CHARACTER NO-UNDO FORMAT "X(16)".
DEFINE VARIABLE intBufferSize AS INTEGER NO-UNDO INITIAL 16.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
DEFINE VARIABLE ptrToString AS MEMPTR NO-UNDO.
PROCEDURE GetComputerNameA EXTERNAL "KERNEL32.DLL":
DEFINE OUTPUT PARAMETER ptrToString AS MEMPTR.
DEFINE INPUT-OUTPUT PARAMETER intBufferSize AS LONG.
DEFINE RETURN PARAMETER intResult AS SHORT.
END PROCEDURE.
SET-SIZE(ptrToString) = 16.
RUN GetComputerNameA (OUTPUT ptrToString,
INPUT-OUTPUT intBufferSize,
OUTPUT intResult).
IF intResult = 1 THEN
DO:
ASSIGN chrComputerName = GET-STRING(ptrToString,1).
MESSAGE chrComputerName VIEW-AS ALERT-BOX.
END.
ELSE
MESSAGE "Buffer size is too small. Must be as least " +
STRING(intBufferSize) VIEW-AS ALERT-BOX.
SET-SIZE(ptrToString) = 0.