Try OpenEdge Now
skip to main content
Dynamic Call Object
Code examples : Invoking a Windows DLL routine
 

Invoking a Windows DLL routine

The following example demonstrates the use of the RETURN-VALUE-DLL-TYPE attribute and the RETURN-VALUE attribute when invoking a Windows DLL routine. RETURN-VALUE-DLL-TYPE is set to "LONG", which is the value that the DLL routine expects to receive. For example:
FUNCTION GetWinVersion RETURNS INTEGER:
  DEFINE VARIABLE cValue  AS CHARACTER NO-UNDO.
  DEFINE VARIABLE libName AS CHARACTER NO-UNDO.
  DEFINE VARIABLE hCall   AS HANDLE    NO-UNDO.
  
CREATE CALL hCall.
  ASSIGN
    hCall:CALL-NAME             = "GetVersion"
    hCall:LIBRARY               = "kernel32.dll"
    hCall:CALL-TYPE             = DLL-CALL-TYPE
    hCall:RETURN-VALUE-DLL-TYPE = "LONG".
  
hCall:INVOKE( ).
  cValue = hCall:RETURN-VALUE.
  
DELETE OBJECT hCall.
  RETURN cValue.
END FUNCTION.
After the invoke, RETURN-VALUE contains the "INTEGER" data type.