StevenR
March 17th, 2010, 03:27 AM
Hello,
I'm new to this forum, but i hope somebody can help me.
A couple of weeks ago i started making a com class to manage my incoming calls
on my cell - phone.
Because i was unable to translate parts of the project i made 2 classes: 1 i wrote in
C# and the other one i wrote in vb.net.
Now i want to eliminate 1 of the classes the vb.net class.
Below you can find the code written in vb.net => My problem lies in the event raising i can't
get it translated to C#. I want to generate an event that delivers 2 strings without delivering
sender, object.
Please can somebody help me, or give me an example code in a com class i've found a lot of
examples of event rising in C# but i can't get them to work.
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface Steven_TapiHandler
<DispId(1)> Sub Nieuw()
<DispId(3)> Sub Close()
<DispId(4)> Sub GesprekOpnemen()
<DispId(5)> Sub GesprekVerbreken()
<DispId(6)> Sub InWacht()
<DispId(7)> Sub UitWacht()
End Interface
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface Steven_TapiHandlerEvents
<DispId(20001)> Sub OnIncommingCall(ByVal strBellerNr As String, ByVal strBellerNaam As String)
<DispId(20002)> Sub OnCallStateChanged(ByVal strStatus As String)
<DispId(20003)> Sub OnDigitDialed(ByVal strBellerNr As String, ByVal strBellerNaam As String)
End Interface
Public Sub OnCall(ByVal sender As Object, ByVal e As NewCallEventArgs) Handles _Line.NewCall
Dim strEvent As String
If e.Call.CallState = CallState.Offering Then
If e.Call.CallerId.ToString.Substring(0, 1) <> "+" Then
If e.Call.CallerId.ToString.Length > 2 Then
strEvent = "+32" & e.Call.CallerId.ToString
Else
strEvent = e.Call.CallerId.ToString
End If
RaiseEvent OnIncommingCall(strEvent, e.Call.CallerName)
_CurrentCall = e.Call
End If
End If
End Sub
i've been able to write below code in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace MetaCoat_Tapi
{
[Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
public interface Tapi_Interface
{
[DispId(10001)]
String GeefWoord();
}
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface Tapi_InterfaceEvents
{
[DispId(20001)]
void OnIncommingCall(ByVal strBellerNr As String, ByVal strBellerNaam As String);
}
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(Tapi_InterfaceEvents))]
public class cls_Tapi : Tapi_Interface
{
public String GeefWoord()
{
return "Test 375698";
}
}
}
I'm new to this forum, but i hope somebody can help me.
A couple of weeks ago i started making a com class to manage my incoming calls
on my cell - phone.
Because i was unable to translate parts of the project i made 2 classes: 1 i wrote in
C# and the other one i wrote in vb.net.
Now i want to eliminate 1 of the classes the vb.net class.
Below you can find the code written in vb.net => My problem lies in the event raising i can't
get it translated to C#. I want to generate an event that delivers 2 strings without delivering
sender, object.
Please can somebody help me, or give me an example code in a com class i've found a lot of
examples of event rising in C# but i can't get them to work.
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface Steven_TapiHandler
<DispId(1)> Sub Nieuw()
<DispId(3)> Sub Close()
<DispId(4)> Sub GesprekOpnemen()
<DispId(5)> Sub GesprekVerbreken()
<DispId(6)> Sub InWacht()
<DispId(7)> Sub UitWacht()
End Interface
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface Steven_TapiHandlerEvents
<DispId(20001)> Sub OnIncommingCall(ByVal strBellerNr As String, ByVal strBellerNaam As String)
<DispId(20002)> Sub OnCallStateChanged(ByVal strStatus As String)
<DispId(20003)> Sub OnDigitDialed(ByVal strBellerNr As String, ByVal strBellerNaam As String)
End Interface
Public Sub OnCall(ByVal sender As Object, ByVal e As NewCallEventArgs) Handles _Line.NewCall
Dim strEvent As String
If e.Call.CallState = CallState.Offering Then
If e.Call.CallerId.ToString.Substring(0, 1) <> "+" Then
If e.Call.CallerId.ToString.Length > 2 Then
strEvent = "+32" & e.Call.CallerId.ToString
Else
strEvent = e.Call.CallerId.ToString
End If
RaiseEvent OnIncommingCall(strEvent, e.Call.CallerName)
_CurrentCall = e.Call
End If
End If
End Sub
i've been able to write below code in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace MetaCoat_Tapi
{
[Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
public interface Tapi_Interface
{
[DispId(10001)]
String GeefWoord();
}
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface Tapi_InterfaceEvents
{
[DispId(20001)]
void OnIncommingCall(ByVal strBellerNr As String, ByVal strBellerNaam As String);
}
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(Tapi_InterfaceEvents))]
public class cls_Tapi : Tapi_Interface
{
public String GeefWoord()
{
return "Test 375698";
}
}
}