API call returns only first character of data

dcrawford

New member
Joined
Dec 20, 2012
Messages
2
Programming Experience
5-10
Hello,

I am working on creating a console application to interface with our Nortel BCM 50 Call Detail Recording.
Sample code is provided by Nortel; however, it is based in VB6 (I believe) and I am having some trouble getting the API calls to work properly in VB.net
The problem is that I am supposed to receive a long string of text which includes incoming phone numbers and time stamps; however I am only receiving the very first character. An example string is supposed to look like "*121912 161428 0126 394 9999999999 UNKNOWN U R" where 9999999999 is a phone number, my code though only returns "*". The application is also supposed to receive multiple lines of this information in rapid succession, but it seems as though the API stops after the first character.

The API in question is "VBCdrOpenConnection" which is supposed to call the function "CDRRecord" with new data.

Another (possibly unrelated) question is how would I go about keeping a console application constantly running and waiting for input from the API without using something like "Console.ReadLine()" (the console app will never have user interaction).

Please find below my VB.net code. If it is required I can provide the original VB6 sample code.

VB.NET:
Option Explicit OnImports System.Threading
Imports System.Windows.Forms


Module CDR
    Declare Function VBCdrOpenConnection Lib "CDRClient.dll" (ByVal IPAddressOrMachineName As String, ByVal usernameOfCDRUserGroup As String, ByVal Password As String, ByVal CDRRecord As CDRRecordHandler, ByVal CDRStop As CDRStopHandler, ByVal applicationData As Integer) As Short
    Public Delegate Sub CDRRecordHandler(ByVal bStrMsg As String, ByVal applicationData As Integer)
    Public Delegate Sub CDRStopHandler(ByVal Reason As Integer, ByVal applicationData As Integer)
    Declare Function CdrCloseConnection Lib "CDRClient.dll" (ByVal Handle As Short) As Short
    Declare Function CdrClipFile Lib "CDRClient.dll" (ByVal Handle As Short) As Short


    'variables emptied for security purposes
    Const MAX_COUNT = 50
    Const BCM_ADDRESS = ""
    Const BCM_USER = ""
    Const BCM_PASS = ""


    Public CDRCount As Integer
    Public Handle As Integer


    Public Sub CDRRecord(ByVal bStrMsg As String, ByVal applicationData As Integer)
        CDRCount = CDRCount + 1
        MessageBox.Show(applicationData)
        appendText(bStrMsg)
    End Sub


    Public Sub CDRStop(ByVal Reason As Integer, ByVal applicationData As Integer)
        CDRCount = 0
        appendText(" stop reason " & CStr(Reason) & vbCrLf & "Disconnected" & vbCrLf)
    End Sub


    Public Sub appendText(ByVal msg As String)
        If (CDRCount > MAX_COUNT) Then
            Console.Clear()
        End If
        'MessageBox.Show(msg)


        Console.WriteLine(msg)
        Console.ReadLine()
    End Sub


    Declare Function SetConsoleCtrlHandler Lib "kernel32.dll" (ByVal HandlerRoutine As ControlEventHandler, ByVal Add As Int32) As Int32
    Public Delegate Sub ControlEventHandler(ByVal consoleEvent As ConsoleEvent)


    Public Enum ConsoleEvent
        CTRL_C = 0
        CTRL_BREAK = 1
        CTRL_CLOSE = 2
        CTRL_LOGOFF = 5
        CTRL_SHUTDOWN = 6
    End Enum


    Public Sub OnControlEvent(ByVal consoleEvent As ConsoleEvent)
        Handle = CdrCloseConnection(Handle)
        appendText("Disconnected" & vbCrLf)
        Handle = -1
    End Sub


    Sub Main()
        SetConsoleCtrlHandler(New ControlEventHandler(AddressOf OnControlEvent), True)


        CDRCount = 0
        Handle = VBCdrOpenConnection(BCM_ADDRESS, BCM_USER, BCM_PASS, New CDRRecordHandler(AddressOf CDRRecord), New CDRStopHandler(AddressOf CDRStop), 0)


        If Handle <> -1 Then
            appendText("Connected to " & BCM_ADDRESS & vbCrLf)
            'Thread.Sleep(10000)
        Else
            appendText("Failed to connect to " & BCM_ADDRESS & vbCrLf)
        End If
    End Sub

End Module


Any help with this would be greatly appreciated!

Thank you,
Daniel
 
What sort of debugging have you done? have you dropped a breakpoint in, for example, CDRRecord(), and then stepped through to see what's happening with the data?

My guess is that you've got one of your vars set to the wrong type, but then that's a stab in the dark I'm afraid.
 
What sort of debugging have you done? have you dropped a breakpoint in, for example, CDRRecord(), and then stepped through to see what's happening with the data?

My guess is that you've got one of your vars set to the wrong type, but then that's a stab in the dark I'm afraid.

I have done all the debugging I can think of. Putting a breakpoint into the CDRRecord() function I can tell that it is only being passed the single character as well. My believe is it is a problem with my implementation of the API. I had to change a few things to get it to work without errors in my code. The original API looks like this:
VB.NET:
Declare Function VBCdrOpenConnection Lib "CDRClient.dll" (ByVal IPAddressOrMachineName As String, ByVal usernameOfCDRUserGroup As String, ByVal Password As String, ByVal CDRRecord As Long, ByVal CDRStop As Long, ByVal applicationData As Long) As Integer

and I changed it to the following in order to be compatible with VB.net

VB.NET:
Declare Function VBCdrOpenConnection Lib "CDRClient.dll" (ByVal IPAddressOrMachineName As String, ByVal usernameOfCDRUserGroup As String, ByVal Password As String, ByVal CDRRecord As CDRRecordHandler, ByVal CDRStop As CDRStopHandler, ByVal applicationData As Integer) As Short

I am also using delegates now to reference the callback functions as so:

VB.NET:
Handle = VBCdrOpenConnection(BCM_ADDRESS, BCM_USER, BCM_PASS, New CDRRecordHandler(AddressOf CDRRecord), New CDRStopHandler(AddressOf CDRStop), 0)

Whereas the original sample code does the following:

VB.NET:
Handle = VBCdrOpenConnection(address.Text, username.Text, pass.Text, AddressOf CDRRecord, AddressOf CDRStop, 0)

Is there a difference between VB6 and VB.net when it comes to the use of Strings?

Also how do I keep my console app alive while waiting for the different responses of the API?

Any help in the above would be greatly appreciate!

Thank you,
Daniel
 
Back
Top