Hello community,

in my last blog posts here, here and here I showed different scenarios of COM development integration – all with ABAP in Eclipse. To increase the integration I developed a library which delivers the complete interfaces of all methods and properties of a COM library. The library calls TypeLibInf.dll.

TypeLibInf library offers three ways of information to the interface information of a COM library:

  1. Via StdCall interface
    Function DLL_TypeLibInf (TypeLibName As String Ptr) Export As Long
    TypeLibName = Path and name of the type library
    Delivers the address to a string with the interface information
  2. Via Java interface
    Delivers a string with the interface information
  3. Via COM interface
    Delivers a string with the interface information

You can use it via Java e.g. like this:

// Begin—————————————————————-

  public class TypeLib

  {


    public native String Inf(String s);

    static

    {

      System.loadLibrary(“TypeLibInf”);

    }

    public static void main(String[] args)

    {

      TypeLib TL = new TypeLib();

      try

      {

        String Interface = TL.Inf(“C:\\Windows\\System32\\wshom.ocx”);

        System.out.println(Interface);

      }

      catch (Exception e)

      {

        System.out.println(e);

      }

    }


  }

// End——————————————————————

Also you can use it via COM e.g. like this:

‘-Begin—————————————————————–


  Set TypeLibInf = CreateObject(“COM_TYPELIBINF”)

  If IsObject(TypeLibInf) Then

    Interface = TypeLibInf.COM_TYPELIBINF(“C:\Dummy\COMBeep.dll”)

    MsgBox Interface

    Set TypeLibInf = Nothing

  End If

‘-End——————————————————————-

Also I developed as example a tiny program which uses the StdCall interface of the library. It shows all methods and properties of a COM/ActiveX library in a tree, below their interfaces. With a double click on the method or property the program generates an associated ABAP code. Also you can see the interface definition with all arguments and their types.

001.JPG

I hope in this way it is much more easier to developing ABAP programs with COM/ActiveX connection.

I integrate the Java interface for a future development, to integrate the same functionality as view for ABAP in Eclipse.

You can download the library and the program with the examples here.

2014/08/25 – Tiny update of the program, now instantiation of OLE object in ABAP code generation with subrc request.

2014/08/28 – Tiny update of the program, small bug fixing in ABAP code generation (Thanks to Holger) and the most variable types are now identified in ABAP code generation.

2014/09/08 – Tiny update of the program, small bug fixing in ABAP code generation and some advances to the program itself.

Enjoy it.

Cheers

Stefan

To report this post you need to login first.

1 Comment

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

  1. Stefan Schnell Post author

    Hello community,

    here two snippets, how to use TypeLibInf in ABAP or Python:

    "-Begin-----------------------------------------------------------------
      Program zTypeLib.
    
      "-Type-Pools----------------------------------------------------------
        Type-Pools OLE2.
    
      "-Variables-----------------------------------------------------------
        Data TypeLibInf Type OLE2_OBJECT.
        Data Interface Type String Value ''.
        Data TabInterface Type Table Of String.
        Data strTemp Type String Value ''.
    
      "-Main----------------------------------------------------------------
        Create Object TypeLibInf 'COM_TYPELIBINF'.
        If sy-subrc = 0 And TypeLibInf-HANDLE <> 0 And
          TypeLibInf-TYPE = 'OLE2'.
    
          Call Method Of TypeLibInf 'COM_TYPELIBINF' = Interface
            Exporting
              #1 = 'C:\Windows\System32\wshom.ocx'.                  "32-bit
             "#1 = 'C:\Windows\SysWOW64\wshom.ocx'.                  "64-bit
    
          Split Interface At ';' Into Table TabInterface.
          Loop At TabInterface Into strTemp.
            Write: / strTemp.
          EndLoop.
    
          Free Object TypeLibInf.
        EndIf.
    
    "-End-------------------------------------------------------------------

    #-Begin-----------------------------------------------------------------
    
    #-Packages--------------------------------------------------------------
    from ctypes import *
    
    #-Main------------------------------------------------------------------
    TypeLibDLL = "C:\\Projects\\TypeLibInf\\TypeLibInf.dll"
    TypeLib = windll.LoadLibrary(TypeLibDLL)
    
    TypeLib.DLL_TypeLibInf.argtypes = [c_char_p]
    TypeLib.DLL_TypeLibInf.restype = c_char_p
    
    Lib = create_string_buffer(b"C:\\Windows\\System32\\wshom.ocx")   #32bit
    #Lib = create_string_buffer(b"C:\\Windows\\SysWOW64\\wshom.ocx")  #64bit
    Interface = TypeLib.DLL_TypeLibInf(Lib)
    
    Interface = str(Interface)
    lstInterface = Interface.split(";")
    for i in range(len(lstInterface)):
      print(lstInterface[i])
    
    del TypeLib
    
    #-End-------------------------------------------------------------------

    Enjoy it.

    Cheers

    Stefan

    (0) 

Leave a Reply