Forum Discussion

snakebyteme2's avatar
16 years ago

Using Interop to embed TestRecorder in your .NET application

Thought this might be helpful for other TestComplete users.

Here is a VB.NET wrapper class to call the TestRecorder functions from your .NET application:



Imports System.Runtime.InteropServices



Public Class TestRecorder



    'Paths of 32-bit and 64-bit TestRecorder DLLs.

    'Use the installed path so that other dependencies of TREngine.dll can be found.

    Public Const path32Bit As String = "C:\Program Files (x86)\Automated QA\TestRecorder 8\Bin\TREngine.dll"

    Public Const path64Bit As String = "C:\Program Files (x86)\Automated QA\TestRecorder 8\x64\Bin\TREngine.dll"



#Region "Interface"



    Public Shared Function StartRecording(ByVal IsTreeModelFlat As Boolean) As Integer

        If Is32Bit() Then

            Return StartRecording32(IsTreeModelFlat)

        Else

            Return StartRecording64(IsTreeModelFlat)

        End If

    End Function



    Public Shared Function StopRecording() As Integer

        If Is32Bit() Then

            Return StopRecording32()

        Else

            Return StopRecording64()

        End If

    End Function



    Public Shared Function PauseRecording() As Integer

        If Is32Bit() Then

            Return PauseRecording32()

        Else

            Return PauseRecording64()

        End If

    End Function



    Public Shared Function ResumeRecording() As Integer

        If Is32Bit() Then

            Return ResumeRecording32()

        Else

            Return ResumeRecording64()

        End If

    End Function



    Public Shared Function SaveDataToFile(ByVal FileName As String) As Integer

        If Is32Bit() Then

            Return SaveDataToFile32(FileName)

        Else

            Return SaveDataToFile64(FileName)

        End If

    End Function



    Public Shared Function Is32Bit() As Boolean

        Return IntPtr.Size * 8 = 32

    End Function



#End Region



#Region "32 bit"



    <DllImport(path32Bit, EntryPoint:="StartRecording")> _

    Private Shared Function StartRecording32(ByVal IsTreeModelFlat As Boolean) As Integer

    End Function



    <DllImport(path32Bit, EntryPoint:="StopRecording")> _

    Private Shared Function StopRecording32() As Integer

    End Function



    <DllImport(path32Bit, EntryPoint:="PauseRecording")> _

    Private Shared Function PauseRecording32() As Integer

    End Function



    <DllImport(path32Bit, EntryPoint:="ResumeRecording")> _

    Private Shared Function ResumeRecording32() As Integer

    End Function



    <DllImport(path32Bit, EntryPoint:="SaveDataToFile", CharSet:=CharSet.Unicode)> _

    Private Shared Function SaveDataToFile32(ByVal FileName As String) As Integer

    End Function



#End Region



#Region "64 bit"



    <DllImport(path64Bit, EntryPoint:="StartRecording")> _

    Private Shared Function StartRecording64(ByVal IsTreeModelFlat As Boolean) As Integer

    End Function



    <DllImport(path64Bit, EntryPoint:="StopRecording")> _

    Private Shared Function StopRecording64() As Integer

    End Function



    <DllImport(path64Bit, EntryPoint:="PauseRecording")> _

    Private Shared Function PauseRecording64() As Integer

    End Function



    <DllImport(path64Bit, EntryPoint:="ResumeRecording")> _

    Private Shared Function ResumeRecording64() As Integer

    End Function



    <DllImport(path64Bit, EntryPoint:="SaveDataToFile", CharSet:=CharSet.Unicode)> _

    Private Shared Function SaveDataToFile64(ByVal FileName As String) As Integer

    End Function



#End Region





End Class
No RepliesBe the first to reply