Project

General

Profile

Native API Emulation

4GL programs often call functions exposed by the operating system to overcome limitations of the OpenEdge runtime. One such example is getCursorPos Windows/User32.dll OS function that returns the actual mouse cursor location.

The Native API Emulation feature allows to streamline 4GL to Java conversion of such OS function calls. There are two conversion rules annotations/native_api.rules and convert/native_api.rules. There is also the class NativeAPIEmulation that declares all the supported native functions. When annotations/native_api.rules encounters an EXTERNAL procedure, it checks NativeAPIEmulation class whether it contains the external procedure declaration. If so it will mark the procedure to be picked up by convert/native_api.rules. convert/native_api.rules then converts the EXTERNAL procedure in a call to the respective method in NativeAPIEmulation.

The methods in NativeAPIEmulation must conform to a specific convention to be correctly matched by the rules above. The following EXTERNAL procedure:

procedure SetParent external "user32.dll":U:
    define input parameter childhwnd as long.
    define input parameter newparent as long.
end.

must be declared in the NativeAPIEmulation class as follows:

public class NativeAPIEmulation
{
   public static class windows
   {
       public static class user32
       {
          public static integer setParent(integer hWndChild, integer hWndNewParent)
          {
           ...
          }
       }
   }
}

Note how the method is scoped in the class user32, which translates to the name of the native library in the EXTERNAL procedure declaration.

To enable this feature for a specific procedure file, ext-hints file must exist with the following content. The ext-hints file must reside in the same directory as its procedure file and must be in the form <procedure file name>.p.ext-hints.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<extension>
   <native-api os="windows"/>
</extension>

The value of the os xml attribute is the target OS platform and translates to the class enclosed in NativeAPIEmulation, see above.

See the list below of the currently supported system functions. Note that many of the functions are implemented only partially. Always make sure that the function satisfies the expected behavior in your project.

Windows

user32

getAsyncKeyState
getFocus
setFocus
getParent
setParent
loadCursorA
getCursor
setCursor
getWindowRect
getClientRect
getCursorPos
screenToClient
showScrollBar
getActiveWindow
getSystemMetrics
getScrollPos
sendMessageA
isWindow
lockWindowUpdate
disableProcessWindowsGhosting

kernel32

getLastError
getUserDefaultUILanguage
getPrivateProfileStringA
getLocaleInfoA
sleep

advapi32

getUserNameA
wsock32
wSAStartup
wSACleanup
gethostname
gethostbyname
inet_ntoa

© 2019 Golden Code Development Corporation. ALL RIGHTS RESERVED.