Skip to Content
2
Oct 25, 2010 at 03:01 PM

How to call DLL functions from the client in ABAP programs

1741 Views Last edit Apr 14, 2020 at 03:52 AM 3 rev

It is not ordinary but very easy to use DLL calls in ABAP language. Yuri Popov programmed a module, called DynamicWrapperX. It is an ActiveX component, which allow to call each function in a DLL you want via COM. A great module, you find the module here.

It is necessary before, with the transaction code SOLE, register the OLE application DynamicWrapperX in the SAP system. Type in:

  • OLE Application: DynamicWrapperX
  • CLSID: {89565275-A714-4a43-912E-978B935EDCCC}
  • CLSID Type Lib: {89565275-A714-4a43-912E-978B935EDCCC}
  • OLE-Objectname: DynamicWrapperX
  • Language: EN
  • Text: Component allows to call functions exported by DLLs

And it is necessary to register DynamicWrapperX on the client system too, with regsvr32.exe dynwrapx.dll.

Look at the following example how easy it is to use a Windows function from USER32.DLL:

INCLUDE OLE2INCL.

DATA: IDYes TYPE i VALUE 6,
      IDNo TYPE i VALUE 7.

DATA: Win32 TYPE OLE2_OBJECT,
      ret TYPE i.

CREATE OBJECT Win32 'DynamicWrapperX'.

CALL METHOD OF Win32 'Register'
  EXPORTING
    #1 = 'user32.dll'
    #2 = 'MessageBoxW'
    #3 = 'i=hwwu'
    #4 = 'r=l'.

CALL METHOD OF Win32 'MessageBoxW' = ret
  EXPORTING
    #1 = 0
    #2 = 'Hello World'
    #3 = 'Test'#4 = 4.

  IF ret = IDYes.
    WRITE 'Ja'.
  ELSEIF ret = IDNo.
    WRITE 'Nein'.
  ELSE.
    WRITE '?'.
  ENDIF.

  FREE OBJECT Win32.

Important hint: This method works only with foreground jobs and online processes and not with background jobs and batch processes.

Enjoy the possibilities.