By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

WM5 problem

P: n/a
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.MessageInter ception;
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.NotifyAndDel ete);
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.MessageInter ception

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.NotifyAndDel ete)
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.MessageInter ception.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/lib...ed(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.MessageInte rception.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

Apr 24 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
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

Apr 24 '07 #2

P: n/a
Tym
Many Thanks!
"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microsof t.com...
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
> 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_MessageReceive d)
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

Apr 24 '07 #3

P: n/a
Tym

"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microsof t.com...
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?
Apr 24 '07 #4

P: n/a
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>
"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microsof t.com...
>>
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?
Please read the documentation of WithEvents, maybe that does some extra
stuff to get the event wired up correctly.

--
SvenC

Apr 25 '07 #5

P: n/a
Tym
My VB knowledge isn't as technical as I'd like!

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

"SvenC" <Sv***@community.nospamwrote in message
news:4C**********************************@microsof t.com...
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>>
"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microso ft.com...
>>>
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?

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

--
SvenC

Apr 26 '07 #6

P: n/a
Hi Tym,
"SvenC" <Sv***@community.nospamwrote in message
news:4C**********************************@microsof t.com...
>>>>
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?

Please read the documentation of WithEvents, maybe that does some extra
stuff to get the event wired up correctly.
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?

--
SvenC

Apr 26 '07 #7

P: n/a
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.MessageInter ception

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.NotifyAndDel ete)

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
Apr 26 '07 #8

P: n/a
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>
"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.MessageInter ception

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.NotifyAndDel ete)

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.

--
SvenC

Apr 27 '07 #9

P: n/a
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.MessageInter ception

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
Apr 28 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.