Consultor Eletrônico



Kbase P87397: How to Call WIN32 API Function: GetComputerNameA?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   07/07/2004
Status: Unverified

GOAL:

How to Call WIN32 API Function: GetComputerNameA?

GOAL:

How to pass MEMPTR and LONG parameters to a Dynamic Link Library (DLL) Function?

FACT(s) (Environment):

Windows

FACT(s) (Environment):

Progress 8.x

FACT(s) (Environment):

Progress 9.x

FACT(s) (Environment):

OpenEdge 10.x

FIX:

The following code shows how to call the Win32 API function GetComputerNameA that returns the name of the computer at the time the system started.

This code also demonstrates how to pass MEMPTR and LONG parameter to a Dynamic Link Library (DLL) Function:

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.