Phone application and hardware buttons

Hi,

I am stuck with my first VB.Net and Compact Framework project (I come from Delphi) and need a little help to get started.

Requirements:
My Application has to replace the provider dependent phone application on the MDA III and MDA Compact. At first it has to provide the basic functionality, which shouldn't be too much:

- dial a number with the touchscreen
- catch incoming calls
- start the application when the green phone-button is pressed

Well, I am already stuck at the beginning:

a) Replacing cprog.exe
At first I tried to replace the original phone application with my self-written program, but without success. I couldn't delete, rename or replace the file. On the internet I found the information that the cprog.exe lies in ROM and therefore can't be deleted.

b) Catching the phone buttons
The green and red phone buttans can't be catched viaMicrosoft.WindowsCE.Forms.HardwareButton... After a few tries I found out that they must beVK_F3 andVK_F4 - but the handling doesn't work stable (cprog.exe is started even when I "eat" the event withKeyEventArgs.Handled, sometimes the events arent sent etc.)
After searching the Internet for a long time I found references to the functionGetAsyncKeyState, but don't know how to implement it - I think I need a working VB.Net example here.

c) Registry
In the registry, the cprog.exe is associated a few times, but when I change a value (try to point to my application) it is ignored


A possible solution to my problems with a complete different approach is mentioned by the user mamaich in a web forum:

http://forum.xda-developers.com/viewtopic.php?p=140351

Quote:
"As you know OS communicates with GSM device through a COM-port. It sends normal AT-commands. You can hook the COM-port, parse ATDxxx and modem's responces and hide unneeded commands."

This leads to my next problem:

d) Serial port
The following code lists the Com-ports 1-6 and 8-9, but it doesn't tell me what port I can/must use:

For Each sp As String In System.IO.Ports.SerialPort.GetPortNames
CB_COMPORTS.Items.Add(sp)
Next

How can I detectrobust of which type a Com-port is (Bluetooth, virtual, Irda etc) and use it then? Is a.Close() followed by a.Open()sufficient?


Sorry it's much text, but I hope that somebody of you can point me in the right direction. Since, as I already mentioned, this is my first VB.Net project I appreciate every piece of code.

TIA

[3212 byte] By [tonda] at [2007-12-16]
# 1
Replacing CProg.exe is not supported.
However, there is some information from the Windows Mobile team blog posted at http://blogs.msdn.com/windowsmobile/archive/2005/09/02/460327.aspx.
JonPul at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 2

Hi Tonda,

I am trying to do much the same as you - did you ever manage to catch the red and green keys?

eiger at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 3

Imports TAPI3Lib

Public Class Form2

Dim TestTAPI As TAPI3Lib.TAPI

Const TAPI3ALLEVENTS = TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION Or TAPI3Lib.TAPI_EVENT.TE_CALLSTATE Or TAPI3Lib.TAPI_EVENT.TE_CALLMEDIA Or TAPI3Lib.TAPI_EVENT.TE_CALLINFOCHANGE Or TAPI3Lib.TAPI_EVENT.TE_PHONEEVENT

Public WithEvents TAPIEvents As TAPI3Lib.TAPI

Dim TAPIEvent As TAPI3Lib.TAPI_EVENT

Dim FoundAddress As TAPI3Lib.ITAddress

'For Event Registration

Dim fOwner As Boolean = True, fMonitor As Boolean = False

Dim lMediaTypes As Long = TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO, lCallbackInstance As Long = 1

Dim TAPIRegister As Long

'For Outgoing Call

Dim TestCall As TAPI3Lib.ITBasicCallControl

Dim PhoneNumber As String

Dim lAddressType As Long = TAPI3Lib.TapiConstants.LINEADDRESSTYPE_PHONENUMBER

'For Incoming Call

Dim TestAnswer As TAPI3Lib.ITBasicCallControl

Dim CallNotification As TAPI3Lib.ITCallNotificationEvent

Dim CallInfo As TAPI3Lib.ITCallInfo

Dim CallToAnswer As Boolean = False

'For Event Handling

Dim GlobalNotEvent As TAPI3Lib.ITCallInfo

Private Function Register()

Dim fOwner As Boolean, fMonitor As Boolean

Dim lMediaTypes As Long, lCallbackInstance As Long

fOwner = True

fMonitor = True

lMediaTypes = TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO

lCallbackInstance = 1

On Error Resume Next

TAPIRegister = TestTAPI.RegisterCallNotifications(FoundAddress, True, True, TAPI3Lib.TapiConstants.TAPIMEDIATYPE_DATAMODEM, 1)

If Err.Number = -2147221500 Then

MsgBox("Connection Not Found, Between Computer and Phone !", MsgBoxStyle.Information, "Tapi")

End

Exit Function

End If

End Function

Function InitTAPI()

TestTAPI = New TAPI3Lib.TAPI

TestTAPI.Initialize()

Dim TestAddresses As TAPI3Lib.ITAddress

Dim TestCollection As TAPI3Lib.ITCollection

TestCollection = TestTAPI.Addresses

Dim TestCurAddress As TAPI3Lib.ITAddress

Dim TestMediaSupport As TAPI3Lib.ITMediaSupport

Dim TestCapabilities As TAPI3Lib.ITAddressCapabilities

Dim Pass As Boolean = False

Dim ITTAPI As TAPI3Lib.ITTAPI

Dim Index As Short = 0

For Index = 1 To TestCollection.Count

TestCurAddress = TestCollection(Index)

TestMediaSupport = TestCurAddress

TestCapabilities = TestCurAddress

If TestMediaSupport.QueryMediaType(TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO) Then

Pass = True

Else

Pass = False

End If

TestCurAddress = Nothing

TestMediaSupport = Nothing

TestCapabilities = Nothing

If Pass = True Then

FoundAddress = TestCollection(Index)

'MsgBox("Passed: " & Index)

'FoundAddress = FoundAddress.AddressName

Exit For

End If

If Pass = False Then

MsgBox("Error: No Index Found. You may not have a voice capable modem or your voice modem is configured incorrectly.")

Exit Function

End If

Next

TestTAPI.EventFilter = TAPI3ALLEVENTS

TAPIEvents = TestTAPI

'Now register

Register()

End Function

Private Function GetCallerID(ByRef oCallInfo As TAPI3Lib.ITCallInfo)

Dim sAddress As String

Dim sName As String

sAddress = oCallInfo.CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER)

sName = oCallInfo.CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNAME)

LblStatus.Text = sAddress & " " & sName

End Function

Private Sub TAPI_Event(ByVal HTapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles TAPIEvents.Event

Dim IDCallInfo As TAPI3Lib.ITCallInfo

Dim CSCallInfo As TAPI3Lib.ITCallInfo

Dim CallNotificationEvent As TAPI3Lib.ITCallNotificationEvent

Dim oCIC As TAPI3Lib.ITCallInfoChangeEvent

Dim NotIC As TAPI3Lib.ITCallInfoChangeEvent

Dim CSEvent As TAPI3Lib.ITCallStateEvent

Dim CallStateEvent As TAPI3Lib.ITCallStateEvent

Dim State As TAPI3Lib.CALL_STATE

'Dim en As String = pEvent'

If HTapiEvent = TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION Then

lblShow.Text = "Incoming Call Detected."

NotIC = pEvent

IDCallInfo = NotIC.Call

CallNotificationEvent = pEvent

CallInfo = CallNotificationEvent.Call

LblActive.Text = LblActive.Text & "Trouble: Callinfo"

GetCallerID(IDCallInfo)

End If

If HTapiEvent = TAPI3Lib.TAPI_EVENT.TE_CALLINFOCHANGE Then

LblActive.Text = LblActive.Text & ": CallInfoChange Detected."

oCIC = pEvent

If oCIC.Cause = TAPI3Lib.CALLINFOCHANGE_CAUSE.CIC_CALLERID Then

IDCallInfo = oCIC.Call

GetCallerID(IDCallInfo)

End If

End If

If HTapiEvent = TAPI3Lib.TAPI_EVENT.TE_CALLSTATE Then

'lblShow.Text = "Incoming Call Detected."

'NotIC = pEvent

'IDCallInfo = NotIC.Call

'CallNotificationEvent = pEvent

'CallInfo = CallNotificationEvent.Call

'LblActive.Text = LblActive.Text & "Trouble: Callinfo"

'GetCallerID(IDCallInfo)

'--

LblActive.Text = LblActive.Text & "CallState: "

' Dim CSEvent As TAPI3Lib.ITCallStateEvent

CSEvent = pEvent

' Dim CSCallInfo As TAPI3Lib.ITCallInfo

CSCallInfo = CSEvent.Call

' Dim State As TAPI3Lib.CALL_STATE

State = CSEvent.State

If State = TAPI3Lib.CALL_STATE.CS_DISCONNECTED Then

LblActive.Text = LblActive.Text & "Disconnected"

'Dim DisControl As TAPI3Lib.ITBasicCallControl

'DisControl = CallInfo

'TestTAPI.Shutdown()

'TestTAPI = CreateObject("TAPI.TAPI.1")

'InitTAPI()

'Register()

'PhoneNumber = TxtPhoneNumber.Text

'LblStatus.Text = "Dialing " & PhoneNumber

'TestCall = FoundAddress.CreateCall(PhoneNumber, lAddressType, lMediaTypes)

'TestCall.Disconnect(TAPI3Lib.DISCONNECT_CODE.DC_NORMAL)

LblStatus.Text = "Ready for Call."

End If

If State = TAPI3Lib.CALL_STATE.CS_CONNECTED Then

LblActive.Text = LblActive.Text & "Connected"

End If

If State = TAPI3Lib.CALL_STATE.CS_OFFERING Then

LblActive.Text = LblActive.Text & "Offering."

' CallNotificationEvent = pEvent

' GlobalNotEvent = CallNotificationEvent.Call

CallToAnswer = True

End If

End If

End Sub

'===================================================================================================================

'Private Sub TAPI_Event(ByVal HTapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles TAPIEvents.Event

' Dim callerID As String

' Select Case TapiEvent

' Case TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION

' Debug.Print("TE_CALLNOTIFICATION")

' Dim objCallNotificationEvent As ITCallNotificationEvent

' objCallNotificationEvent = pEvent

' ' Query ITCallInfo interface.

' Dim objReceivedCallInfo As ITCallInfo

' objReceivedCallInfo = objCallNotificationEvent.Call

' callerID = objReceivedCallInfo.CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER)

' Debug.Print("Caller ID: " & callerID)

' objReceivedCallInfo = Nothing

' objCallNotificationEvent = Nothing

' End Select

'===================================================================================================================

Private Function Disconnect()

If Not (TestCall Is Nothing) Then

LblStatus.Text = "Disconnecting..."

TestCall.Disconnect(TAPI3Lib.DISCONNECT_CODE.DC_NORMAL)

LblStatus.Text = "Ready For Call."

TestCall = Nothing

Else

LblActive.Text = "Nothing to Disconnect."

End If

TestCall = Nothing

FoundAddress = Nothing

TAPIEvents = Nothing

If Not (TestTAPI Is Nothing) Then

TestTAPI.Shutdown()

TestTAPI = CreateObject("TAPI.TAPI.1")

InitTAPI()

Register()

lblShow.Text = ""

LblStatus.Text = ""

End If

'TestTAPI = Nothing

End Function

Private Sub Form2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

InitTAPI()

Register()

colour()

End Sub

Private Function colour()

For i As Integer = Me.Controls.Count - 1 To 0 Step -1

If TypeOf Me.Controls(i) Is TextBox Then

Me.Controls.Item(i).BackColor = Color.White

End If

Next

TxtPhoneNumber.Focus()

End Function

Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed

TestCall = Nothing

FoundAddress = Nothing

TAPIEvents = Nothing

If Not (TestTAPI Is Nothing) Then

TestTAPI.Shutdown()

End If

TestTAPI = Nothing

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

lblShow.Text = ""

LblStatus.Text = ""

End Sub

Private Sub btnDial_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDial.Click

If Not (TestCall Is Nothing) Then

LblStatus.Text = "Previous Call hasn't been cleared yet."

Exit Sub

End If

If Not (TestTAPI Is Nothing) Then

TestTAPI.Shutdown()

End If

TestTAPI = CreateObject("TAPI.TAPI.1")

InitTAPI()

Register()

PhoneNumber = TxtPhoneNumber.Text

LblStatus.Text = "Dialing " & PhoneNumber

TestCall = FoundAddress.CreateCall(PhoneNumber, lAddressType, lMediaTypes)

Try

TestCall.Connect(False)

Catch

LblStatus.Text = "Trouble."

TestCall = Nothing

End Try

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If CallInfo Is Nothing Then

LblStatus.Text = "No Call To Answer."

Exit Sub

End If

Dim nCallState As TAPI3Lib.CALL_STATE

nCallState = CallInfo.CallState

Dim objCallControl As TAPI3Lib.ITBasicCallControl

objCallControl = CallInfo

objCallControl.Answer()

'Dim AnsCallControl As TAPI3Lib.ITBasicCallControl

'AnsCallControl = GlobalNotEvent

'AnsCallControl.Answer()

'AnsCallControl = Nothing

'CallToAnswer = False

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Disconnect()

End Sub

--

BUT INCOMING PHONE NUMBER CAN NOT BE DETECT PLZ HELP ME..............................

saurabhp at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...