COM wrapper API

As of Jan the 20th, 2006, I have managed to provide some VB binding thru a COM (Component Object Model) wrapper. For short: the ticables2 library is now useable from Visual Basic !
 
The API provided with the wrapper is almost the same as the ticables2 one. This page discuss about the minor changes because COM/Automation defines the use of types and the passing of arguments.

1°) The API's are the same thus the COM/VB developers will refer to the pure-C ticables2 documentation.

2°) The following typedefs have been renamed:
- CablePort => ICablePort,
- CableModel => ICableModel.

3°) The following types have been changed:
- unsigned char => Byte,
- int => short or long or BOOL depending on the usage.

4°) The ticables heaviliy relies on handles. The CableHandle structure has been replaced by a Long handle.

5°) A property named ErrorCode has been added for your convenience. This lets you retrieve the last error code from function call or from this variable.

Examples:

    const char *ticables_model_to_string(CableModel model) => ModelToString(ICableModel model, BSTR *ret)
    int ticables_cable_send(CableHandle* handle, uint8_t *data, uint32_t len) => CableSend(long handle, SAFEARRAY *data, long count, long *ret)

6°) VB sample program (see test_vba.doc):

Private Sub CommandButton1_Click()

' Define COM object interface and load object
    Dim ticable As Cables
    Set ticable = CreateObject("Cticables2.Cables")
 
' Affiche la version de l'objet
    TextBox1.Text = ticable.VersionGet

End Sub

Private Sub CommandButton2_Click()

    Dim SendBuf(4) As Byte
    Dim RecvBuf() As Byte
    Dim err As Long
    Dim old As Integer
    Dim msg As String

' Define COM object and instanciate (same as above)
    Dim ticable As New Cables
   
' Init library
    ticable.LibraryInit
 
' Initialize a BlackLink cable on COM1
    Dim handle As Long
    handle = ticable.HandleNew(ICABLE_SLV, IPORT_1)
    'ticable.HandleShow (handle)

' Optionnal
    'ticable.OptionsSetDelay handle, IDFLT_DELAY
    'ticable.OptionsSetTimeout handle, IDFLT_TIMEOUT

' Does communication
    TextBox2.Text = "Opening..."
    err = ticable.CableOpen(handle)
    If err <> 0 Then
        ticables.ErrorGet err, msg
        TextBox2.Texte = msg
    End If
   
    err = ticable.CableReset(handle)
 
    ' Possible way (CableSend may be better)
    SendBuf(0) = &H8
    'ticable.CablePut handle, SndBuf(0)
    SendBuf(1) = &H87
    'ticable.CablePut handle, SndBuf(1)
    SendBuf(2) = &H41
    'ticable.CablePut handle, SndBuf(2)
    SendBuf(3) = &H0
    'ticable.CablePut handle, SndBuf(3)
   
    TextBox2.Text = "Sending..."
    err = ticable.CableSend(handle, SendBuf, 4)
    If err <> 0 Then
        ticables.ErrorGet err, msg
        TextBox2.Texte = msg
    End If
   
    ' Possible way (CableRecv may be better)
    'ticable.CableGet handle, RecvBuf(0)
    'ticable.CableGet handle, RecvBuf(1)
    'ticable.CableGet handle, RecvBuf(2)
    'ticable.CableGet handle, RecvBuf(3)
   
    TextBox2.Text = "Receiving..."
    err = ticable.CableRecv(handle, RecvBuf, 4)
    If err <> 0 Then
        ticables.ErrorGet err, msg
        TextBox2.Texte = msg
    End If

    TextBox2.Text = "Closing..."
    ticable.CableClose (handle)

' Release handle
    ticable.HandleDel (handle)
 
' Release library
    ticable.LibraryExit
   
    TextBox2.Text = "Success !!!"

End Sub

7°) About registering:

before using this wrapper into you own project, you need to register it. There are 2 ways:
- merge registry entries into the Windows registry,
- type 'regsvr32.exe cticables2.dll /v" because the wrapper is a self-registered component.

-> Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Cticables2.Cables]
@="Cables Class"

[HKEY_CLASSES_ROOT\Cticables2.Cables\CLSID]
@="{EA25011A-AC84-4498-9E50-05EBC57AE012}"

[HKEY_CLASSES_ROOT\Cticables2.Cables\CurVer]
@="Cticables2.Cables.1"

-> Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Cticables2.Cables.1]
@="Cables Class"

[HKEY_CLASSES_ROOT\Cticables2.Cables.1\CLSID]
@="{EA25011A-AC84-4498-9E50-05EBC57AE012}"

-> Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{EA25011A-AC84-4498-9E50-05EBC57AE012}]
@="Cables Class"

[HKEY_CLASSES_ROOT\CLSID\{EA25011A-AC84-4498-9E50-05EBC57AE012}\InprocServer32]
@="C:\\sources\\roms\\TICABL~2\\com\\Debug\\CTICABLES2.DLL"
"ThreadingModel"="Free"

[HKEY_CLASSES_ROOT\CLSID\{EA25011A-AC84-4498-9E50-05EBC57AE012}\ProgID]
@="Cticables2.Cables.1"

[HKEY_CLASSES_ROOT\CLSID\{EA25011A-AC84-4498-9E50-05EBC57AE012}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{EA25011A-AC84-4498-9E50-05EBC57AE012}\TypeLib]
@="{0C0B9EE6-F05D-4519-9086-1E4CCA123A50}"

[HKEY_CLASSES_ROOT\CLSID\{EA25011A-AC84-4498-9E50-05EBC57AE012}\VersionIndependentProgID]
@="Cticables2.Cables"

-> Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{4766347A-54D0-4F60-B43A-8F8F5618ECFE}]
@="Types Class"

[HKEY_CLASSES_ROOT\CLSID\{4766347A-54D0-4F60-B43A-8F8F5618ECFE}\InprocServer32]
@="C:\\sources\\roms\\TICABL~2\\com\\Debug\\CTICABLES2.DLL"
"ThreadingModel"="Free"

[HKEY_CLASSES_ROOT\CLSID\{4766347A-54D0-4F60-B43A-8F8F5618ECFE}\ProgID]
@="Cticables2.Types.1"

[HKEY_CLASSES_ROOT\CLSID\{4766347A-54D0-4F60-B43A-8F8F5618ECFE}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{4766347A-54D0-4F60-B43A-8F8F5618ECFE}\TypeLib]
@="{0C0B9EE6-F05D-4519-9086-1E4CCA123A50}"

[HKEY_CLASSES_ROOT\CLSID\{4766347A-54D0-4F60-B43A-8F8F5618ECFE}\VersionIndependentProgID]
@="Cticables2.Types"

Note: ticables2.dll must be belonged with the cticables2.dll !

Return to the main index