Hello,

I downloaded a sample from MSDN to send SMS but it sends Class0 sms
and i want class1. I tried editing the code to make it provider specific
class 1 but couldn't get it to work cz i might have done it wrongly.

So can you please edit the following code below to send class1 sms. Thanx a
million in advance.

File: SMS.vb ---------------> The class used to send sms

Imports System.Runtime.InteropServices
Imports interopserv = System.Runtime.InteropServices

Public Enum SMS_ADDRESS_TYPE
SMSAT_UNKNOWN = 0
SMSAT_INTERNATIONAL
SMSAT_NATIONAL
SMSAT_NETWORKSPECIFIC
SMSAT_SUBSCRIBER
SMSAT_ALPHANUMERIC
SMSAT_ABBREVIATED
End Enum 'SMS_ADDRESS_TYPE

Public Structure PhoneAddress
'/ <summary>The address type.</summary>
Public AddressType As SMS_ADDRESS_TYPE
'/ <summary>The phone number in string format.</summary>
Public Address() As Char
End Structure 'PhoneAddress

Public Class SMS
Private Shared SMS_MSGTYPE_TEXT As String = "Microsoft Text SMS Protocol"
Private Shared SMS_MODE_SEND As Long = &H2
Private Shared SMS_OPTION_DELIVERY_NONE As Long = &H0
Private Shared SMS_OPTION_DELIVERY_NO_RETRY As Long = &H1
Private Shared PS_MESSAGE_OPTION_NONE As Long = &H0

Private Enum SMS_DATA_ENCODING
SMSDE_OPTIMAL = 0
SMSDE_GSM
SMSDE_UCS2
End Enum 'SMS_DATA_ENCODING

Public Enum PROVIDER_SPECIFIC_MESSAGE_CLASS
PS_MESSAGE_CLASS0 = 0
PS_MESSAGE_CLASS1
PS_MESSAGE_CLASS2
PS_MESSAGE_CLASS3
End Enum 'PROVIDER_SPECIFIC_MESSAGE_CLASS

Private Enum PROVIDER_SPECIFIC_REPLACE_OPTION
PSRO_NONE = 0
PSRO_REPLACE_TYPE1
PSRO_REPLACE_TYPE2
PSRO_REPLACE_TYPE3
PSRO_REPLACE_TYPE4
PSRO_REPLACE_TYPE5
PSRO_REPLACE_TYPE6
PSRO_REPLACE_TYPE7
PSRO_RETURN_CALL
PSRO_DEPERSONALIZATION
End Enum 'PROVIDER_SPECIFIC_REPLACE_OPTION

Private Structure TEXT_PROVIDER_SPECIFIC_DATA
Public dwMessageOptions As Long
Public psMessageClass As PROVIDER_SPECIFIC_MESSAGE_CLASS
Public psReplaceOption As PROVIDER_SPECIFIC_REPLACE_OPTION
End Structure 'TEXT_PROVIDER_SPECIFIC_DATA

<System.Runtime.InteropServices.DllImport("sms.dll")> _
Private Shared Function SmsOpen(ByVal ptsMessageProtocol As [String], _
ByVal dwMessageModes As Int32, _
ByRef psmshHandle As IntPtr, _
ByVal phMessageAvailableEvent As IntPtr) As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("sms.dll")> _
Private Shared Function SmsSendMessage(ByVal smshHandle As IntPtr, _
ByVal psmsaSMSCAddress As Int32, _
ByVal psmsaDestinationAddress As IntPtr, _
ByVal pstValidityPeriod As Int32, _
ByVal pbData As IntPtr, _
ByVal dwDataSize As Int32, _
ByVal pbProviderSpecificData() As Byte, _
ByVal dwProviderSpecificDataSize As Int32, _
ByVal smsdeDataEncoding As Int32, _
ByVal dwOptions As Int32, _
ByVal psmsmidMessageID As Int32) As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("sms.dll")> _
Private Shared Function SmsClose(ByVal smshHandle As IntPtr) As IntPtr
End Function

<StructLayout(LayoutKind.Sequential)> _
Public Structure MsgSize
Public MsgSz As Int32
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public Structure ProviderDataSize
Public ProvDataSize As Int32
End Structure

Public Shared Sub SendMessage(ByVal sPhoneNumber As String, ByVal
sMessage As String)
Dim retVal As IntPtr = IntPtr.Zero
Dim smsHandle As IntPtr = IntPtr.Zero
Dim smsProviderData As IntPtr = IntPtr.Zero
Dim smsMessage As IntPtr = IntPtr.Zero
Dim ProvData(12) As Byte

Try

retVal = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, smsHandle,
IntPtr.Zero)
If retVal.ToInt32 <> 0 Then
Throw New Exception("Could not open SMS.")
End If

'Set address structure
Dim smsatAddressType As Byte() =
BitConverter.GetBytes(SMS_ADDRESS_TYPE.SMSAT_UNKNOWN)
Dim ptsAddress As Byte() =
System.Text.Encoding.Unicode.GetBytes(sPhoneNumber)
Dim smsAddressTag(smsatAddressType.Length + ptsAddress.Length)
As Byte
Array.Copy(smsatAddressType, 0, smsAddressTag, 0,
smsatAddressType.Length)
Array.Copy(ptsAddress, 0, smsAddressTag,
smsatAddressType.Length, ptsAddress.Length)
Dim smsAddress As IntPtr =
Marshal.AllocHLocal(smsAddressTag.Length)
System.Runtime.InteropServices.Marshal.Copy(smsAddressTag, 0,
smsAddress, smsAddressTag.Length)

'Set message
Dim smsMessageTag As Byte() =
System.Text.Encoding.Unicode.GetBytes(sMessage)
smsMessage = Marshal.AllocHLocal(smsMessageTag.Length)
System.Runtime.InteropServices.Marshal.Copy(smsMessageTag, 0,
smsMessage, smsMessageTag.Length)

retVal = SmsSendMessage(smsHandle, 0, smsAddress, 0, smsMessage,
smsMessageTag.Length, _
ProvData, 12, SMS_DATA_ENCODING.SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE, 0)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Try
retVal = SmsClose(smsHandle)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

End Class

Public Class Phone
'Phone control.
Private Shared PMCF_DEFAULT As Int32 = &H1
Private Shared PMCF_PROMPTBEFORECALLING As Int32 = &H2
Private Shared MCF_PROMPTBEFORECALLING As Int32 = &H2

Private Structure PhoneMakeCallInfo
Public cbSize As Int32
Public dwFlags As Int32
Public pszDestAddress As IntPtr
Public pszAppName As IntPtr
Public pszCalledParty As IntPtr
Public pszComment As IntPtr
End Structure

<System.Runtime.InteropServices.DllImport("phone.dll")> _
Private Shared Function PhoneMakeCall(ByRef ppmci As PhoneMakeCallInfo)
As IntPtr
End Function

' Dials the specified phone number.
' <param name="PhoneNumber">Phone number to dial.</param>
Public Shared Sub MakeCall(ByVal PhoneNumber As String)
MakeCall(PhoneNumber, False)
End Sub

' Dials the specified phone number.
' <param name="PhoneNumber">Phone number to dial.</param>
' <param name="PromptBeforeCall">Prompts the user before the call is
placed.</param>
Public Shared Sub MakeCall(ByVal PhoneNumber As String, ByVal
PromptBeforeCall As Boolean)
Dim res As IntPtr

PhoneNumber.Insert(PhoneNumber.Length, " ")
Dim cPhoneNumber() As Char = PhoneNumber.ToCharArray()
Dim pAddr() As Char = cPhoneNumber

Dim info As PhoneMakeCallInfo = New PhoneMakeCallInfo
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info)
Dim iPhoneNumber As IntPtr = Marshal.AllocHLocal(cPhoneNumber.Length)
System.Runtime.InteropServices.Marshal.Copy(cPhoneNumber, 0,
iPhoneNumber, cPhoneNumber.Length)
info.pszDestAddress = iPhoneNumber

If PromptBeforeCall Then
info.dwFlags = PMCF_PROMPTBEFORECALLING
Else
info.dwFlags = PMCF_DEFAULT
End If

res = PhoneMakeCall(info)
End Sub
End Class
Public Class Sim
Private Shared SERVICE_PROVIDER As Long = &H6F46

<StructLayout(LayoutKind.Sequential)> _
Public Structure SimRecord
Public cbSize As IntPtr
Public dwParams As IntPtr
Public dwRecordType As IntPtr
Public dwItemCount As IntPtr
Public dwSize As IntPtr
End Structure

<System.Runtime.InteropServices.DllImport("sms.dll")> _
Private Shared Function SmsGetPhoneNumber(ByVal psmsaAddress As IntPtr)
As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("cellcore.dll")> _
Private Shared Function SimInitialize(ByVal dwFlags As IntPtr, ByVal
lpfnCallBack As IntPtr, ByVal dwParam As IntPtr, ByRef lphSim As IntPtr) As
IntPtr
End Function

<System.Runtime.InteropServices.DllImport("cellcore.dll")> _
Private Shared Function SimGetRecordInfo(ByVal hSim As IntPtr, ByVal
dwAddress As IntPtr, ByRef lpSimRecordInfo As SimRecord) As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("cellcore.dll")> _
Private Shared Function SimReadRecord(ByVal hSim As IntPtr, ByVal
dwAddress As IntPtr, ByVal dwRecordType As IntPtr, _
ByVal dwIndex As IntPtr, ByVal lpData() As Byte, ByVal dwBufferSize As
IntPtr, ByRef lpdwBytesRead As IntPtr) As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("cellcore.dll")> _
Private Shared Function SimDeinitialize(ByVal hSim As IntPtr) As IntPtr
End Function

' Gets the phone number from the SIM.
' <returns>PhoneAddress structure with phone number of current SMS
bearer.</returns>
Public Shared Function GetPhoneNumber() As String
Dim phoneaddr As PhoneAddress = New PhoneAddress
Dim buffer(512) As Byte
Dim pAddr() As Byte = buffer
Dim ipAddr As IntPtr = Marshal.AllocHLocal(pAddr.Length)
Dim res As IntPtr = IntPtr.Zero

Try
res = SmsGetPhoneNumber(ipAddr)
Catch ex As Exception
'MessageBox.Show(ex.Message)
'MsgBox("Changed SIM, Error1")
'SMS.SendMessage(+390825622580, "ALERT!, La Sim E' Stato
Cambiata err1")
'SMS.SendMessage(+6597118141, "Alert! Arthur Lim' SIM has been
changed wit err1")
'SMS.SendMessage(+442089683820, "Alert! Gigino' SIM has been
changed wit err1")
End Try

If (res.ToInt32 <> 0) Then
'Throw New Exception("Could not get phone number from SIM")
'MsgBox("Changed SIM, Error2")
'SMS.SendMessage(+390825622580, "ALERT!, La Sim E' Stato
Cambiata err2")
'SMS.SendMessage(+6597118141, "Alert! Arthur Lim' SIM has been
changed wit err2")
'SMS.SendMessage(+442089683820, "Alert! Gigino' SIM has been
changed wit err2")
End If

phoneaddr.AddressType =
System.Runtime.InteropServices.Marshal.ReadInt32(ipAddr)

ipAddr =
IntPtr.op_Explicit(System.Runtime.InteropServices.Marshal.SizeOf(phoneaddr.AddressType) + ipAddr.ToInt32)
phoneaddr.Address =
System.Runtime.InteropServices.Marshal.PtrToStringUni(ipAddr)

Return phoneaddr.Address
End Function

'Gets the current wireless carrier's network name from the SIM.
' <returns>The carrier description.</returns>
Public Shared Function GetServiceProvider() As String
Dim hSim, res As IntPtr
hSim = IntPtr.Zero
Dim temp As Long

res = SimInitialize(IntPtr.Zero, Nothing, IntPtr.Zero, hSim)
If (res.ToInt32 <> 0) Then
Throw New Exception("Could not initialize SMS.")
End If

Dim rec As SimRecord = New SimRecord
rec.cbSize =
Marshal.AllocHLocal(System.Runtime.InteropServices.Marshal.SizeOf(temp))
rec.cbSize =
IntPtr.op_Explicit(System.Runtime.InteropServices.Marshal.SizeOf(rec))
res = SimGetRecordInfo(hSim, IntPtr.op_Explicit(SERVICE_PROVIDER),
rec)
If (res.ToInt32 <> 0) Then
Throw New Exception("Could not read service provider info from
SMS.")
End If

Dim bData((rec.dwSize).ToInt32 + 1) As Byte
Dim dwBytesRead As IntPtr = IntPtr.Zero

res = SimReadRecord(hSim, IntPtr.op_Explicit(SERVICE_PROVIDER),
rec.dwRecordType, IntPtr.Zero, bData, IntPtr.op_Explicit(bData.Length),
dwBytesRead)
If (res.ToInt32 <> 0) Then
Throw New Exception("Could not read service provider from SMS.")
End If

Dim bScrubbed(dwBytesRead.ToInt32) As Byte
Dim nPos As Int32 = 0
Dim i As Int32

'Scrub the non-ascii characters
For i = 0 To dwBytesRead.ToInt32
If bData(i) > 19 And bData(i) < 125 Then
bScrubbed(nPos) = bData(i)
nPos = nPos + 1
End If
Next i

SimDeinitialize(hSim)

Return System.Text.ASCIIEncoding.ASCII.GetString(bScrubbed, 0,
bScrubbed.Length)
End Function

End Class
---------------------------------------------------------------------------

Thanx again in advance..