cancel
Showing results for 
Search instead for 
Did you mean: 

Register and use custom .NET DLL functions in ABAP

Former Member
0 Kudos

Dear All,

I have a requirment in my implementation to use a custom DLL functions in my ABAP program? Could anyone tell me how i can use that DLL in my ABAP program?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member197445
Contributor
0 Kudos
  • On the "Compile" tab of the .NET project properties, check the box for "Register for COM interop." 
  • Install the library on your local machine or whatever machine needs to access the DLL. 
  • Register the object in SAP in transaction SOLE.
  • Call it like this in ABAP:

TYPE-POOLS  ole2.

DATA: mydll type ole2_object,
      str   type string VALUE 'Empty'.

   CREATE OBJECT mydll 'MYAPP.LAUNCH'.

   IF mydll-handle > 0.

     CALL METHOD OF mydll 'GetText' = str.

   ENDIF.

   WRITE str.

Email me if you'd like a copy of the .NET code.

Former Member
0 Kudos

hai case, i've problem when register and use custome .NET dll, i've followed the instructions you gave but still no hope, sy-subrc = 2 when call method.

Can u give me copy of the .NET code? and where i can get CLSID when register the object in SAP in transaction SOLE? i already install the library on my local machine.

Thanks before.

Regards,

Kemal

former_member197445
Contributor
0 Kudos

You can generate your own ID using Tools --> Create GUID.  It resides in the implementation object in the .NET project.

Here is what my interface object looks like (VB.NET):

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Namespace HESwipeAx

    <ComVisible(True)> <InterfaceType(ComInterfaceType.InterfaceIsDual)> <Guid("BD8D4391-DBF4-4633-938B-F94281DC8D9D")> _
    Public Interface ILaunch

        Function GetText() As String


    End Interface
End Namespace

And my implementation looks like this.  I've highlighted the CLSID.

Imports System.Runtime.InteropServices

Namespace HESwipeAx
    <ComVisible(True)> _
    <ClassInterface(ClassInterfaceType.None)> _
    <Guid("014320CD-0448-4161-9629-1E3DCA3C6452")> _
    <ProgId("HESwipeAx.Launch")> _
    <ComDefaultInterface(GetType(ILaunch))> _
    Public Class Launch
        Inherits UserControl
        Implements ILaunch, IObjectSafety

        Public Function GetText() As String Implements ILaunch.GetText
            Dim prompt As New MainForm
            If prompt.ShowDialog = DialogResult.OK Then
                Return prompt.textReturnVal.Text
            Else
                Return String.Empty
            End If

                     HERE IS THE MAIN METHOD -- return what you want in this function.
        End Function

        Public Function GetInterfaceSafetyOptions(ByRef riid As System.Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer Implements IObjectSafety.GetInterfaceSafetyOptions
            Dim m_options As ObjectSafetyOptions = ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER Or ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA
            pdwSupportedOptions = CInt(m_options)
            pdwEnabledOptions = CInt(m_options)
            Return 0
        End Function

        Public Function SetInterfaceSafetyOptions(ByRef riid As System.Guid, dwOptionSetMask As Integer, dwEnabledOptions As Integer) As Integer Implements IObjectSafety.SetInterfaceSafetyOptions
            Return 0

        End Function

        Public Enum ObjectSafetyOptions
            INTERFACESAFE_FOR_UNTRUSTED_CALLER = &H1
            INTERFACESAFE_FOR_UNTRUSTED_DATA = &H2
            INTERFACE_USES_DISPEX = &H4
            INTERFACE_USES_SECURITY_MANAGER = &H8
        End Enum

    End Class
End Namespace

Hope that helps.

Former Member
0 Kudos

Hi, Case.

I've tried to implement your code but got the same issue in trace file "|HESwipeAx.Launch.HESwipeAx.Launch     |CREATEOBJECT     |Creation of control "" denied!     |4.0.40305.0     |7300.2.4.1083     |mscoree.dll     |"

Could you please share your SOLE settings and VB.NET project code? Or just mail it to me m.drozdoff (at) gmail.com

Thanx in advance,

Michael.

Former Member
0 Kudos

My problem is solved.

I've disabled SAP security settings for SAP GUI. 

.net COM-object has been created without errors from abap code. Also  sample method from Case's VB.NET code works fine!

former_member197445
Contributor
0 Kudos

Glad to hear it.  Send a few points my way with a "Like," if you can spare a moment.

Former Member
0 Kudos

Hi, everyone.

So with properties and methods now is clear..... But what about events?

I've tried to add event to my .net DLL and then catch it in GUI_CONTROL but not succeed....

Could somebody share working example of COM-object(.NET) with events?

Thanks in advance!