Skip to Content

Hello community,

in a normal case it is not possible to register a COM library without admin rights on a presentation server, if you use the command line tool regsvr32. To realize this possibility I build a library which offers two methods. One to registers any COM library and another one to unregister it, without admin rights. With this library, and the program BinFile2ABAP which I presented here, you can store any COM library inside an ABAP function module (FM), unpack if you need it and register it, to use it inside your ABAP program, and all on-the-fly. The library writes all keys to the local user hive in the Windows registry and all files are stored in the users work directory.

Here an example, which uses DynamicWrapperX, look here for an introduction, to call a Win32API function inside ABAP:

"-Begin-----------------------------------------------------------------
  Program ZREGISTERX.

    "-Variables---------------------------------------------------------
      Data oRegisterX Type OLE2_OBJECT.
      Data WorkDir Type String Value ''.
      Data FileName Type String Value ''.
      Data rc Type i Value 0.
      Data oDynWrapX Type OLE2_OBJECT.

    "-Macros------------------------------------------------------------
      Define Flush.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
      End-Of-Definition.

    "-Main--------------------------------------------------------------
      Create Object oRegisterX 'RegisterX'.

      If sy-subrc <> 0 Or  oRegisterX-Handle = 0 Or 
        oRegisterX-Type <> 'OLE2'.
        Call Function 'ZREGISTERXDLL'.
        Create Object oRegisterX 'RegisterX'.
      EndIf.

      If sy-subrc = 0 And oRegisterX-Handle > 0 And oRegisterX-Type = 'OLE2'.

        Call Method Of oRegisterX 'About'.
        Flush.

        Call Function 'ZDYNWRAPXDLL'.

        Call Method cl_gui_frontend_services=>get_sapgui_workdir
          Changing SAPWORKDIR = WorkDir Exceptions Others = 1.
        Concatenate WorkDir '\DynWrapX.dll' Into FileName.

        Call Method Of oRegisterX 'DLLRegisterServer' = rc Exporting
          #1 = '' #2 = '{89565275-A714-4a43-912E-978B935EDCCC}' #3 = ''
          #4 = FileName #5 = 'DynamicWrapperX' #6 = '' #7 = '' #8 = ''.
        Flush.

        If rc = 1.

          Create Object oDynWrapX 'DynamicWrapperX'.

          If sy-subrc = 0 And oDynWrapX-Handle > 0 And oDynWrapX-Type = 'OLE2'.

            Call Method Of oDynWrapX 'Register' Exporting
              #1 = 'user32.dll' #2 = 'MessageBoxW' #3 = 'i=hwwu' 
              #4 = 'r=l'.
            Flush. 

            If sy-subrc = 0.

              Call Method Of oDynWrapX 'MessageBoxW' = rc
              Exporting #1 = 0 #2 = 'This is a test' #3 = 'Test' #4 = 1.
              Flush.

              Write: / rc.

            EndIf.

          EndIf.

          Free Object oDynWrapX.

          Call Method Of oRegisterX 'DLLUnregisterServer' = rc
            Exporting #1= ''
            #2 = '{89565275-A714-4a43-912E-978B935EDCCC}' #3 = '' 
            #4 = 'DynamicWrapperX' #5 = ''.
          Flush.

        EndIf.

        Free Object oRegisterX.

        "-Unregister library--------------------------------------------
          Call Method cl_gui_frontend_services=>execute
            Exporting
              APPLICATION = 'RUNDLL32.EXE'
              PARAMETER = 'RegisterX.dll,UnregisterServer /S'
              DEFAULT_DIRECTORY = WorkDir
              SYNCHRONOUS = 'X'
            Exceptions
              Others = 1.

      EndIf.

"-End-------------------------------------------------------------------

The FM ZREGISTERXDLL contains the RegisterX ActiveX library and the FM ZDYNWRAPXDLL contains the DynamicWrapperX ActiveX library. As you can see I register the DynamicWrapperX library with the ClassID, the library name with path and the ProgID. I use the library to call the Win32API function MessageBoxW.

Here another equivalent example, which uses a PDF library to create a PDF document on the presentation server:

"-Begin-----------------------------------------------------------------
  Program ZREGISTERX.

    "-Variables---------------------------------------------------------
      Data oRegisterX Type OLE2_OBJECT.
      Data WorkDir Type String Value ''.
      Data FileName Type String Value ''.
      Data rc Type i Value 0.
      Data oPDF Type OLE2_OBJECT.

    "-Macros------------------------------------------------------------
      Define Flush.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
      End-Of-Definition.

    "-Main--------------------------------------------------------------
      Create Object oRegisterX 'RegisterX'.

      If sy-subrc <> 0 Or  oRegisterX-Handle = 0 Or oRegisterX-Type <> 'OLE2'.
        Call Function 'ZREGISTERXDLL'.
        Create Object oRegisterX 'RegisterX'.
      EndIf.

      If sy-subrc = 0 And oRegisterX-Handle > 0 And oRegisterX-Type = 'OLE2'.

        Call Method Of oRegisterX 'About'.
        Flush.

        Call Function 'ZDEBENUPDFLIBRARYLITEDLL'.

        Call Method cl_gui_frontend_services=>get_sapgui_workdir
          Changing SAPWORKDIR = WorkDir Exceptions Others = 1.
        Concatenate WorkDir '\DebenuPDFLibraryLite0916.dll' Into FileName.

        Call Method Of oRegisterX 'DLLRegisterServer' = rc Exporting
          #1 = '{7D05356C-1081-4D9A-913A-1561391ACD3D}'
          #2 = '{9BAC3984-751D-41B1-8646-A51C6D78C172}'
          #3 = '{767EA445-F656-42FC-BA17-5701DAA2E827}'
          #4 = FileName #5 = 'DebenuPDFLibraryLite0916.PDFLibrary'
          #6 = 'PDFLibrary' #7 = 'IPDFLibrary' #8 = '9.16'.
        Flush.

        If rc = 1.

          Create Object oPDF 'DebenuPDFLibraryLite0916.PDFLibrary'.

          If sy-subrc = 0 And oPDF-Handle <> 0 And oPDF-Type = 'OLE2'.

            Call Method Of oPDF 'DrawText' = rc
              Exporting #1 = 100 #2 = 400 #3 = 'This is a test'.
            Flush.

            Concatenate WorkDir '\Test.pdf' Into FileName.

            Call Method Of oPDF 'SaveToFile' = rc Exporting
              #1 = FileName.
            Flush.

          EndIf.

          Free Object oPDF.

          Call Method Of oRegisterX 'DLLUnregisterServer' = rc
            Exporting #1 = '{7D05356C-1081-4D9A-913A-1561391ACD3D}'
            #2 = '{9BAC3984-751D-41B1-8646-A51C6D78C172}'
            #3 = '{767EA445-F656-42FC-BA17-5701DAA2E827}' 
            #4 = 'DebenuPDFLibraryLite0916.PDFLibrary' #5 = '9.16'.
          Flush.

        EndIf.

        Free Object oRegisterX.

        "-Unregister library--------------------------------------------
          Call Method cl_gui_frontend_services=>execute
            Exporting
              APPLICATION = 'RUNDLL32.EXE'
              PARAMETER = 'RegisterX.dll,UnregisterServer /S'
              DEFAULT_DIRECTORY = WorkDir
              SYNCHRONOUS = 'X'
            Exceptions
              Others = 1.

      EndIf.

"-End-------------------------------------------------------------------

You can download RegisterX here.

Good register.

 

Cheers

Stefan

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply