WM5 problem

T

Tym

Hi guys and gals!

Been trying to program following Maarten Struys' demos on the SMS
intereception and I'm having severe problems.

First of all, I'm a VBer not VC, though for this I have tried to work my way
through VC!!

I took the BASIC code from Marteen's example, and derived this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile;
using Microsoft.WindowsMobile.Status;
using Microsoft.WindowsMobile.PocketOutlook ;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;


namespace DeviceApplication1
{
public partial class Form1 : Form
{
private MessageInterceptor sms;
private SystemState networkConnectionState;
private SystemState cradleState;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
sms = new
MessageInterceptor(InterceptionAction.NotifyAndDelete);
sms.MessageCondition = new MessageCondition(MessageProperty.Body
, MessagePropertyComparisonType.StartsWith , "123456");
sms.MessageReceived += new
MessageInterceptorEventHandler(sms_MessageReceived);
}

void sms_MessageReceived(object sender, MessageInterceptorEventArgs
e)
{
Msgbox("SMS RECEIVED");
}
}
}


Now, the only it here that doesn't work is the Msgbox - why? what's the VC
equivalent??? (in compactframework - there's one in VB!)

That aside, converting this to VB gives:

Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsMobile
Imports Microsoft.WindowsMobile.Status
Imports Microsoft.WindowsMobile.PocketOutlook
Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception



Public partial Class Form1
Inherits Form
Private sms As MessageInterceptor
Private networkConnectionState As SystemState
Private cradleState As SystemState
Public Sub New()
InitializeComponent()
End Sub

Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)
sms = New MessageInterceptor(InterceptionAction.NotifyAndDelete)
sms.MessageCondition = New MessageCondition(MessageProperty.Body
, MessagePropertyComparisonType.StartsWith , "123456")
sms.MessageReceived += New
MessageInterceptorEventHandler(sms_MessageReceived)
End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)
Msgbox("SMS RECEIVED")
End Sub
End Class


'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net)
'----------------------------------------------------------------

[Credit left in obviously! Thanks Kamal!]

Now with this, the "sms.MessageReceived" is underlined blue, with the error
message:

'Public Event MessageReceived(sender As Object, e As
Microsoft.WindowsMobile.PocketOutlook.MessageInterception.MessageInterceptorEventArgs)'
is an event, and cannot be called directly. Use a 'RaiseEvent' statement to
raise an event

I'm afraid that
http://msdn2.microsoft.com/en-us/library/fwd3bwed(vs.80).aspx doesn't
explain it enough for me and I still can't get it to work.


The "sms_MessageReceived" si also underlined blue with:
'Microsoft.WindowsMobile.PocketOutlook.MessageInterception.MessageInterceptorEventHandler'
is a delegate type and requires a single 'addressof' expression as the only
argument to the constructor.

What gets me is that EXACTLY the same code is OK in VC but not VB. Also, the
intellisense in VC is supoerb - why does my VB environment not give
it??!?!?!


Tym
 
S

SvenC

Hi Tym,

Msgbox("SMS RECEIVED");
Now, the only it here that doesn't work is the Msgbox - why? what's the VC
equivalent??? (in compactframework - there's one in VB!)

Use MessageBox::Show
That aside, converting this to VB gives:
sms.MessageReceived += New
MessageInterceptorEventHandler(sms_MessageReceived)
End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)
Msgbox("SMS RECEIVED")
End Sub
End Class

Now with this, the "sms.MessageReceived" is underlined blue, with the
error message:

VB doesn't have a += for setting up events. Use AddHandler instead:

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

HTH,
SvenC
 
T

Tym

Many Thanks!


SvenC said:
Hi Tym,



Use MessageBox::Show


VB doesn't have a += for setting up events. Use AddHandler instead:

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

HTH,
SvenC
 
T

Tym

SvenC said:
Hi Tym,
Use MessageBox::Show

The VC versin oworks fine! Thanks - however, I don't know VC at all really
and don't want to have to learn in to write my app!
AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

The problem I have with this in VB is that the event is not triggered!! even
though it's the same code as VC

Any ideas?
 
S

SvenC

Hi Tym,

Tym said:
The problem I have with this in VB is that the event is not triggered!!
even though it's the same code as VC

Any ideas?

Please read the documentation of WithEvents, maybe that does some extra
stuff to get the event wired up correctly.
 
T

Tym

My VB knowledge isn't as technical as I'd like!

Read withevents, but still don't fully understand what's happenning.
 
S

SvenC

Hi Tym,
My VB knowledge isn't as technical as I'd like!
Read withevents, but still don't fully understand what's happenning.

Please show us the VB code you have come up with now.

BTW, do you have a working demo of the SMS component? Can you verify that
the component is fireing its events and the problem is only with handling
the events not with raising them?
 
T

Tym

"> Please show us the VB code you have come up with now.
BTW, do you have a working demo of the SMS component? Can you verify that
the component is fireing its events and the problem is only with handling
the events not with raising them?

In VC# it works perfectly

VB Code:

Imports System

Imports System.Collections.Generic

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports Microsoft.WindowsMobile

Imports Microsoft.WindowsMobile.Status

Imports Microsoft.WindowsMobile.PocketOutlook

Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception





Partial Public Class Form1

Inherits Form

Private sms As MessageInterceptor

Private networkConnectionState As SystemState

Private cradleState As SystemState

Private Event MessageReceived()

Public Sub New()

InitializeComponent()

End Sub

Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)

sms = New MessageInterceptor(InterceptionAction.NotifyAndDelete)

sms.MessageCondition = New MessageCondition(MessageProperty.Body,
MessagePropertyComparisonType.StartsWith, "123456")

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

RaiseEvent MessageReceived()

End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)

MsgBox("SMS RECEIVED")

End Sub

End Class
 
S

SvenC

Hi Tym,

Tym said:
"> Please show us the VB code you have come up with now.
In VC# it works perfectly

VB Code:
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsMobile
Imports Microsoft.WindowsMobile.Status
Imports Microsoft.WindowsMobile.PocketOutlook
Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception

Partial Public Class Form1

Inherits Form

Private sms As MessageInterceptor
Private networkConnectionState As SystemState
Private cradleState As SystemState
Private Event MessageReceived()

That line states that you want to raise an event not handle an event. Do you
want to use it to propagate the sms events to your caller? If not you can
delete that
Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)

sms = New MessageInterceptor(InterceptionAction.NotifyAndDelete)

sms.MessageCondition = New MessageCondition(MessageProperty.Body,
MessagePropertyComparisonType.StartsWith, "123456")

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

This should set up that sms_MessageReceived is called whenever you
MessageInterceptor class raises the MessageReceived event. Do you know if
the MessageInterceptor does fire events?
RaiseEvent MessageReceived()

That fires *your* event which can be caught by some code which added an
event handler for *your* event. That has no connection to the
MessageInterceptor's handler

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)

MsgBox("SMS RECEIVED")

End Sub

The above can only be raised from within the sms-Object.
Does that object maybe have some method to start/stop listening for
messages, so that you would need to call something like sms.Start,
sms.Enabled = true or alike? Please compare that carefully with the C# code.
 
T

Tym

Hi SvenC,

Thanks for your time on this - it still wouldn't work, so I googled on
..messagecondition - found a great site and amended the code as follows:

Imports System

Imports System.Collections.Generic

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports Microsoft.WindowsMobile

Imports Microsoft.WindowsMobile.Status

Imports Microsoft.WindowsMobile.PocketOutlook

Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception

Public Class Form1

Private sms As MessageInterceptor

Private networkConnectionState As SystemState

Private cradleState As SystemState

Public Sub New()

InitializeComponent()

End Sub





Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)

MsgBox("SMS RECEIVED")

End Sub

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

sms = _

New MessageInterceptor( _

InterceptionAction. _

NotifyAndDelete, _

True)

'---set the filter for the

' message

sms. _

MessageCondition = _

New MessageCondition( _

MessageProperty.Body, _

MessagePropertyComparisonType. _

StartsWith, "invoke", True)

'---set the event handler for

' the message interceptor

AddHandler _

sms. _

MessageReceived, _

AddressOf _

sms_MessageReceived

End Sub

End Class



This now appears to work - thanks for your responses



Tym
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top