Could Not load sms.dllHi ,<br>I'm using windows mobile 6.0 and VS 2005. I 'm trying to built an application which will send sms.<br>I have tried a lot of things.<br>First I have created a device application in VS 2005<br>I have added references in my project and also I have put the following lines of code in me form<br><br>Imports Microsoft.WindowsMobile.PocketOutlook<br>Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception<br><br>Then I have tried  the following code<br><br>Dim VBMobileSMS As New SmsMessage(&quot;11255888&quot;, &quot;this is a test&quot;)<br>VBMobileSMS.Send()<br><br>But I am always getting an exception . When I run it in the classic emulator I got this<br>Could not load 'sms.dll'<br><br>So after a little search I have downloaded an Example for compact framework and added two classes in my project.<br><br><span style="font-weight:bold">The Marshal class</span><br><br>Imports System<br>Imports interopserv = System.Runtime.InteropServices<br>Imports System.ComponentModel<br><br>'Namespace NetCF.Runtime.InteropServices<br><br>Public NotInheritable Class Marshal<br><br>    Private Class WinApi<br><br>        Public Const LMEM_FIXED As Long = 0<br>        Public Const LMEM_MOVEABLE As Long = 2<br>        Public Const LMEM_ZEROINIT As Long = &amp;H40<br>        Public Const LPTR As Long = LMEM_FIXED Or LMEM_ZEROINIT<br><br>        'private constructor prevents instantiation<br>        Private Sub New()<br>        End Sub<br><br>        ' imported functions<br>        &lt;System.Runtime.InteropServices.DllImport(&quot;coredll.dll&quot;, SetLastError:=True)&gt; _<br>        Public Shared Function LocalAlloc(ByVal uFlags As System.Int32, ByVal uBytes As System.Int32) As IntPtr<br>        End Function<br><br>        &lt;System.Runtime.InteropServices.DllImport(&quot;coredll.dll&quot;, SetLastError:=True)&gt; _<br>        Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr<br>        End Function<br><br>        &lt;System.Runtime.InteropServices.DllImport(&quot;coredll.dll&quot;, SetLastError:=True)&gt; _<br>        Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal uBytes As System.Int64, ByVal fuFlags As System.Int64) As IntPtr<br>        End Function<br>    End Class    'WinApi<br><br>    'private contructor prevents instantiation<br>    Private Sub New()<br>    End Sub<br><br>    'memory allocation / deallocation methods<br>    '/ Allocates a block of memory using LocalAlloc.<br>    '/ &lt;param name=&quot;cb&quot;&gt;The number of bytes in memory required.&lt;/param&gt;<br>    '/ &lt;returns&gt;<br>    '/ An IntPtr to the newly allocated memory. This memory must be <br>    '/ released using the Marshal.FreeHLocal method.<br>    '/ &lt;/returns&gt;<br>    '/ &lt;exception cref=&quot;OutOfMemoryException&quot;&gt;<br>    '/ There is insufficient memory to satisfy the request.<br>    '/ &lt;/exception&gt;<br>    '/ &lt;remarks&gt;<br>    '/ AllocHlocal exposes the LocalAlloc WinCE API from CoreDll.dll.<br>    '/ For additional information about LocalAlloc, see the MSDN Library.<br>    Public Shared Function AllocHLocal(ByVal cb As Int32) As IntPtr<br>        Try<br>            Return WinApi.LocalAlloc(WinApi.LPTR, cb)<br>        Catch ex As Exception<br>        End Try<br>    End Function<br><br>    '/ Frees memory previously allocated from the unmanaged memory<br>    '/ of the process with AllocHLocal.<br>    '/ &lt;param name=&quot;hlocal&quot;&gt;The handle returned by the original matching call to AllocHLocal.&lt;/param&gt;<br>    '/ &lt;exception cref=&quot;Win32Exception&quot;&gt;<br>    '/ Indicates failure. The exception contains the error code obtained from GetLastError.<br>    '/ &lt;/exception&gt;<br>    '/ &lt;remarks&gt;<br>    '/ You can use FreeHlocal to free any memory from the heap allocated by AllocHLocal or <br>    '/ ReAllocHLocal, or any equivalent unmanaged API method. If the hlocal parameter is a <br>    '/ null reference (Nothing in Visual Basic), the method does nothing. FreeHlOCAL exposes<br>    '/ the LocalFree function from CoreDll.DLL, which frees all bytes so that you can no longer <br>    '/ use the memory pointed to by &lt;paramref name=&quot;hLocal&quot;/&gt;. For additional information about <br>    '/ LocalFree, see the MSDN Library.<br>    Public Shared Sub FreeHLocal(ByVal hlocal As IntPtr)<br>        'If hlocal &lt;&gt; IntPtr.Zero Then<br>        If hlocal.ToInt32 &lt;&gt; 0 Then<br>            'If IntPtr.Zero &lt;&gt; WinApi.LocalFree(hlocal) Then<br>            If WinApi.LocalFree(hlocal).ToInt32 &lt;&gt; 0 Then<br>                Throw New Win32Exception(interopserv.Marshal.GetLastWin32Error())<br>            End If<br>            hlocal = IntPtr.Zero<br>        End If<br>    End Sub<br><br>    '/ Resizes a block of memory previously allocated with AllocHLocal.<br>    '/ &lt;param name=&quot;pv&quot;&gt;A pointer to memory allocated with AllocHLocal.&lt;/param&gt;<br>    '/ &lt;param name=&quot;cb&quot;&gt;The new size of the allocated block.&lt;/param&gt;<br>    '/ &lt;returns&gt;<br>    '/ An IntPtr to the reallocated memory. This memory must be released<br>    '/ using Marshal.FreeHLocal.<br>    '/ &lt;/returns&gt;<br>    '/ &lt;exception cref=&quot;OutOfMemoryException&quot;&gt;<br>    '/ There is insufficient memory to satisfy the request.<br>    '/ &lt;/exception&gt;<br>    '/ &lt;remarks&gt;<br>    '/ ReAllocHLocal exposes the LocalRealloc WinCE API method from CoreDll.dll.<br>    '/ The returned pointer can differ from the original. For additional information<br>    '/ about LocalAlloc, see the MSDN Library.<br>    '/ &lt;/remarks&gt;<br>    Public Shared Function ReAllocHLocal(ByVal pv As IntPtr, ByVal cb As Integer) As IntPtr<br>        Dim newMem As IntPtr = WinApi.LocalReAlloc(pv, CType(cb, System.Int64), WinApi.LMEM_MOVEABLE)<br>        'If newMem = IntPtr.Zero Then<br>        If newMem.ToInt32 = 0 Then<br>            Throw New OutOfMemoryException<br>        End If<br>        Return newMem<br>    End Function<br><br>    '/ Copies the contents of a managed String into unmanaged memory.<br>    '/ &lt;param name=&quot;s&quot;&gt;A managed string to be copied.&lt;/param&gt;<br>    '/ &lt;returns&gt;<br>    '/ The address, in unmanaged memory, to where the s was copied, or 0 if a null reference<br>    '/ (Nothing in Visual Basic) string was supplied.<br>    '/ &lt;/returns&gt;<br>    Public Shared Function StringToHLocalUni(ByVal s As String) As IntPtr<br>        If s Is Nothing Then<br>            Return IntPtr.Zero<br>        Else<br>            Dim nc As Integer = s.Length<br>            Dim len As Integer = 2 * (1 + nc)<br>            Dim hLocal As IntPtr = AllocHLocal(len)<br>            'If hLocal = IntPtr.Zero Then<br>            If hLocal.ToInt32 = 0 Then<br>                Throw New OutOfMemoryException<br>            Else<br>                interopserv.Marshal.Copy(s.ToCharArray(), 0, hLocal, s.Length)<br>                Return hLocal<br>            End If<br>        End If<br>    End Function  'StringToHLocalUni<br><br>    Public Shared Function IntToHLocalUni(ByVal s As Int32) As IntPtr<br>        If s = 0 Then<br>            Return IntPtr.Zero<br>        Else<br>            Dim nc As Integer = interopserv.Marshal.SizeOf(s)<br>            Dim len As Integer = 2 * (1 + nc)<br>            Dim hLocal As IntPtr = AllocHLocal(len)<br>            'If hLocal = IntPtr.Zero Then<br>            If hLocal.ToInt32 = 0 Then<br>                Throw New OutOfMemoryException<br>            Else<br>                'interopserv.Marshal.Copy(s.ToString, 0, hLocal, nc)<br>                Return hLocal<br>            End If<br>        End If<br>    End Function  'StringToHLocalUni<br><br>End Class 'Marshal<br>'End Namespace 'NetCF.Runtime.InteropServices<br><br><span style="font-weight:bold">and the SMS Class from the example</span><br>Imports System.Runtime.InteropServices<br>Imports interopserv = System.Runtime.InteropServices<br><br>Public Enum SMS_ADDRESS_TYPE<br>    SMSAT_UNKNOWN = 0<br>    SMSAT_INTERNATIONAL<br>    SMSAT_NATIONAL<br>    SMSAT_NETWORKSPECIFIC<br>    SMSAT_SUBSCRIBER<br>    SMSAT_ALPHANUMERIC<br>    SMSAT_ABBREVIATED<br>End Enum 'SMS_ADDRESS_TYPE<br><br>Public Structure PhoneAddress<br>    '/ &lt;summary&gt;The address type.&lt;/summary&gt;<br>    Public AddressType As SMS_ADDRESS_TYPE<br>    '/ &lt;summary&gt;The phone number in string format.&lt;/summary&gt;<br>    Public Address() As Char<br>End Structure 'PhoneAddress<br><br>Public Class SMS<br>    Private Shared SMS_MSGTYPE_TEXT As String = &quot;Microsoft Text SMS Protocol&quot;<br>    Private Shared SMS_MODE_SEND As Long = &amp;H2<br>    Private Shared SMS_OPTION_DELIVERY_NONE As Long = &amp;H0<br>    Private Shared SMS_OPTION_DELIVERY_NO_RETRY As Long = &amp;H1<br>    Private Shared PS_MESSAGE_OPTION_NONE As Long = &amp;H0<br><br>    Private Enum SMS_DATA_ENCODING<br>        SMSDE_OPTIMAL = 0<br>        SMSDE_GSM<br>        SMSDE_UCS2<br>    End Enum 'SMS_DATA_ENCODING<br><br>    Public Enum PROVIDER_SPECIFIC_MESSAGE_CLASS<br>        PS_MESSAGE_CLASS0 = 0<br>        PS_MESSAGE_CLASS1<br>        PS_MESSAGE_CLASS2<br>        PS_MESSAGE_CLASS3<br>    End Enum 'PROVIDER_SPECIFIC_MESSAGE_CLASS<br><br>    Private Enum PROVIDER_SPECIFIC_REPLACE_OPTION<br>        PSRO_NONE = 0<br>        PSRO_REPLACE_TYPE1<br>        PSRO_REPLACE_TYPE2<br>        PSRO_REPLACE_TYPE3<br>        PSRO_REPLACE_TYPE4<br>        PSRO_REPLACE_TYPE5<br>        PSRO_REPLACE_TYPE6<br>        PSRO_REPLACE_TYPE7<br>        PSRO_RETURN_CALL<br>        PSRO_DEPERSONALIZATION<br>    End Enum 'PROVIDER_SPECIFIC_REPLACE_OPTION<br><br>    Private Structure TEXT_PROVIDER_SPECIFIC_DATA<br>        Public dwMessageOptions As Long<br>        Public psMessageClass As PROVIDER_SPECIFIC_MESSAGE_CLASS<br>        Public psReplaceOption As PROVIDER_SPECIFIC_REPLACE_OPTION<br>    End Structure 'TEXT_PROVIDER_SPECIFIC_DATA<br><br>    &lt;System.Runtime.InteropServices.DllImport(&quot;sms.dll&quot;)&gt; _<br>    Private Shared Function SmsOpen(ByVal ptsMessageProtocol As [String], _<br>    ByVal dwMessageModes As Int32, _<br>    ByRef psmshHandle As IntPtr, _<br>    ByVal phMessageAvailableEvent As IntPtr) As IntPtr<br>    End Function<br><br>    &lt;System.Runtime.InteropServices.DllImport(&quot;sms.dll&quot;)&gt; _<br>    Private Shared Function SmsSendMessage(ByVal smshHandle As IntPtr, _<br>    ByVal psmsaSMSCAddress As Int32, _<br>    ByVal psmsaDestinationAddress As IntPtr, _<br>    ByVal pstValidityPeriod As Int32, _<br>    ByVal pbData As IntPtr, _<br>    ByVal dwDataSize As Int32, _<br>    ByVal pbProviderSpecificData() As Byte, _<br>    ByVal dwProviderSpecificDataSize As Int32, _<br>    ByVal smsdeDataEncoding As Int32, _<br>    ByVal dwOptions As Int32, _<br>    ByVal psmsmidMessageID As Int32) As IntPtr<br>    End Function<br><br>    &lt;System.Runtime.InteropServices.DllImport(&quot;sms.dll&quot;)&gt; _<br>    Private Shared Function SmsClose(ByVal smshHandle As IntPtr) As IntPtr<br>    End Function<br><br>    &lt;StructLayout(LayoutKind.Sequential)&gt; _<br>    Public Structure MsgSize<br>        Public MsgSz As Int32<br>    End Structure<br><br>    &lt;StructLayout(LayoutKind.Sequential)&gt; _<br>    Public Structure ProviderDataSize<br>        Public ProvDataSize As Int32<br>    End Structure<br><br>    Public Shared Sub SendMessage(ByVal sPhoneNumber As String, ByVal sMessage As String)<br>        Dim retVal As IntPtr = IntPtr.Zero<br>        Dim smsHandle As IntPtr = IntPtr.Zero<br>        Dim smsProviderData As IntPtr = IntPtr.Zero<br>        Dim smsMessage As IntPtr = IntPtr.Zero<br>        Dim ProvData(12) As Byte<br><br>        Try<br><br>            retVal = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, smsHandle, IntPtr.Zero)<br>            If retVal.ToInt32 &lt;&gt; 0 Then<br>                Throw New Exception(&quot;Could not open SMS.&quot;)<br>            End If<br><br>            'Set address structure<br>            Dim smsatAddressType As Byte() = BitConverter.GetBytes(SMS_ADDRESS_TYPE.SMSAT_UNKNOWN)<br>            Dim ptsAddress As Byte() = System.Text.Encoding.Unicode.GetBytes(sPhoneNumber)<br>            Dim smsAddressTag(smsatAddressType.Length + ptsAddress.Length) As Byte<br>            Array.Copy(smsatAddressType, 0, smsAddressTag, 0, smsatAddressType.Length)<br>            Array.Copy(ptsAddress, 0, smsAddressTag, smsatAddressType.Length, ptsAddress.Length)<br>            Dim smsAddress As IntPtr = Marshal.AllocHLocal(smsAddressTag.Length)<br>            System.Runtime.InteropServices.Marshal.Copy(smsAddressTag, 0, smsAddress, smsAddressTag.Length)<br><br>            'Set message<br>            Dim smsMessageTag As Byte() = System.Text.Encoding.Unicode.GetBytes(sMessage)<br>            smsMessage = Marshal.AllocHLocal(smsMessageTag.Length)<br>            System.Runtime.InteropServices.Marshal.Copy(smsMessageTag, 0, smsMessage, smsMessageTag.Length)<br><br>            retVal = SmsSendMessage(smsHandle, 0, smsAddress, 0, smsMessage, smsMessageTag.Length, _<br>             ProvData, 12, SMS_DATA_ENCODING.SMSDE_OPTIMAL, SMS_OPTION_DELIVERY_NONE, 0)<br><br>        Catch ex As Exception<br>            MessageBox.Show(ex.Message)<br>        End Try<br><br>        Try<br>            retVal = SmsClose(smsHandle)<br>        Catch ex As Exception<br>            MessageBox.Show(ex.Message)<br>        End Try<br>    End Sub<br><br>End Class<br><br>After that I wrote as the example said the following code.<br><br> SMS.SendMessage(&quot;12121212&quot;, &quot;This is a test&quot;)<br><br>But When I run it in the windows mobile 6.0 classic emulator I'm getting <br>Could not find Pinvoke Dll &quot;sms.dll&quot;<br><br>I know that I am missing something but I don't know what it is.<br>Should I deploy something in the emulator ? If yes what should I deploy and also where am I suppose to find it ?<br>When I want to deploy myApp to the real device should I also include something ?<br>Any Ideas ? I also try to configure emulator. Emulator's port in my pc is COM3 and also when running the classic emulator I went to the configure option and changed the serial port to COM3.<br><br>Any ideas ???<br><br>Thank you <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>© 2009 Microsoft Corporation. All rights reserved.Thu, 11 Dec 2008 23:01:32 Zfe3b2463-2489-453d-a787-eb43e07295bfhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#fe3b2463-2489-453d-a787-eb43e07295bfhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#fe3b2463-2489-453d-a787-eb43e07295bfzakkarhttp://social.msdn.microsoft.com/Profile/en-US/?user=zakkarCould Not load sms.dllHi ,<br>I'm using windows mobile 6.0 and VS 2005. I 'm trying to built an application which will send sms.<br>I have tried a lot of things.<br>First I have created a device application in VS 2005<br>I have added references in my project and also I have put the following lines of code in me form<br><br>Imports Microsoft.WindowsMobile.PocketOutlook<br>Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception<br><br>Then I have tried  the following code<br><br>Dim VBMobileSMS As New SmsMessage(&quot;11255888&quot;, &quot;this is a test&quot;)<br>VBMobileSMS.Send()<br><br>But I am always getting an exception . When I run it in the classic emulator I got this<br>Could not load 'sms.dll'<br><br>So after a little search I have downloaded an Example for compact framework and added two classes in my project.<br><br><span style="font-weight:bold">The Marshal class</span><br><br>Imports System<br>Imports interopserv = System.Runtime.InteropServices<br>Imports System.ComponentModel<br><br>'Namespace NetCF.Runtime.InteropServices<br><br>Public NotInheritable Class Marshal<br><br>    Private Class WinApi<br><br>        Public Const LMEM_FIXED As Long = 0<br>        Public Const LMEM_MOVEABLE As Long = 2<br>        Public Const LMEM_ZEROINIT As Long = &amp;H40<br>        Public Const LPTR As Long = LMEM_FIXED Or LMEM_ZEROINIT<br><br>        'private constructor prevents instantiation<br>        Private Sub New()<br>        End Sub<br><br>        ' imported functions<br>        &lt;System.Runtime.InteropServices.DllImport(&quot;coredll.dll&quot;, SetLastError:=True)&gt; _<br>        Public Shared Function LocalAlloc(ByVal uFlags As System.Int32, ByVal uBytes As System.Int32) As IntPtr<br>        End Function<br><br>        &lt;System.Runtime.InteropServices.DllImport(&quot;coredll.dll&quot;, SetLastError:=True)&gt; _<br>        Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr<br>        End Function<br><br>        &lt;System.Runtime.InteropServices.DllImport(&quot;coredll.dll&quot;, SetLastError:=True)&gt; _<br>        Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal uBytes As System.Int64, ByVal fuFlags As System.Int64) As IntPtr<br>        End Function<br>    End Class    'WinApi<br><br>    'private contructor prevents instantiation<br>    Private Sub New()<br>    End Sub<br><br>    'memory allocation / deallocation methods<br>    '/ Allocates a block of memory using LocalAlloc.<br>    '/ &lt;param name=&quot;cb&quot;&gt;The number of bytes in memory required.&lt;/param&gt;<br>    '/ &lt;returns&gt;<br>    '/ An IntPtr to the newly allocated memory. This memory must be <br>    '/ released using the Marshal.FreeHLocal method.<br>    '/ &lt;/returns&gt;<br>    '/ &lt;exception cref=&quot;OutOfMemoryException&quot;&gt;<br>    '/ There is insufficient memory to satisfy the request.<br>    '/ &lt;/exception&gt;<br>    '/ &lt;remarks&gt;<br>    '/ AllocHlocal exposes the LocalAlloc WinCE API from CoreDll.dll.<br>    '/ For additional information about LocalAlloc, see the MSDN Library.<br>    Public Shared Function AllocHLocal(ByVal cb As Int32) As IntPtr<br>        Try<br>            Return WinApi.LocalAlloc(WinApi.LPTR, cb)<br>        Catch ex As Exception<br>        End Try<br>    End Function<br><br>    '/ Frees memory previously allocated from the unmanaged memory<br>    '/ of the process with AllocHLocal.<br>    '/ &lt;param name=&quot;hlocal&quot;&gt;The handle returned by the original matching call to AllocHLocal.&lt;/param&gt;<br>    '/ &lt;exception cref=&quot;Win32Exception&quot;&gt;<br>    '/ Indicates failure. The exception contains the error code obtained from GetLastError.<br>    '/ &lt;/exception&gt;<br>    '/ &lt;remarks&gt;<br>    '/ You can use FreeHlocal to free any memory from the heap allocated by AllocHLocal or <br>    '/ ReAllocHLocal, or any equivalent unmanaged API method. If the hlocal parameter is a <br>    '/ null reference (Nothing in Visual Basic), the method does nothing. FreeHlOCAL exposes<br>    '/ the LocalFree function from CoreDll.DLL, which frees all bytes so that you can no longer <br>    '/ use the memory pointed to by &lt;paramref name=&quot;hLocal&quot;/&gt;. For additional information about <br>    '/ LocalFree, see the MSDN Library.<br>    Public Shared Sub FreeHLocal(ByVal hlocal As IntPtr)<br>        'If hlocal &lt;&gt; IntPtr.Zero Then<br>        If hlocal.ToInt32 &lt;&gt; 0 Then<br>            'If IntPtr.Zero &lt;&gt; WinApi.LocalFree(hlocal) Then<br>            If WinApi.LocalFree(hlocal).ToInt32 &lt;&gt; 0 Then<br>                Throw New Win32Exception(interopserv.Marshal.GetLastWin32Error())<br>            End If<br>            hlocal = IntPtr.Zero<br>        End If<br>    End Sub<br><br>    '/ Resizes a block of memory previously allocated with AllocHLocal.<br>    '/ &lt;param name=&quot;pv&quot;&gt;A pointer to memory allocated with AllocHLocal.&lt;/param&gt;<br>    '/ &lt;param name=&quot;cb&quot;&gt;The new size of the allocated block.&lt;/param&gt;<br>    '/ &lt;returns&gt;<br>    '/ An IntPtr to the reallocated memory. This memory must be released<br>    '/ using Marshal.FreeHLocal.<br>    '/ &lt;/returns&gt;<br>    '/ &lt;exception cref=&quot;OutOfMemoryException&quot;&gt;<br>    '/ There is insufficient memory to satisfy the request.<br>    '/ &lt;/exception&gt;<br>    '/ &lt;remarks&gt;<br>    '/ ReAllocHLocal exposes the LocalRealloc WinCE API method from CoreDll.dll.<br>    '/ The returned pointer can differ from the original. For additional information<br>    '/ about LocalAlloc, see the MSDN Library.<br>    '/ &lt;/remarks&gt;<br>    Public Shared Function ReAllocHLocal(ByVal pv As IntPtr, ByVal cb As Integer) As IntPtr<br>        Dim newMem As IntPtr = WinApi.LocalReAlloc(pv, CType(cb, System.Int64), WinApi.LMEM_MOVEABLE)<br>        'If newMem = IntPtr.Zero Then<br>        If newMem.ToInt32 = 0 Then<br>            Throw New OutOfMemoryException<br>        End If<br>        Return newMem<br>    End Function<br><br>    '/ Copies the contents of a managed String into unmanaged memory.<br>    '/ &lt;param name=&quot;s&quot;&gt;A managed string to be copied.&lt;/param&gt;<br>    '/ &lt;returns&gt;<br>    '/ The address, in unmanaged memory, to where the s was copied, or 0 if a null reference<br>    '/ (Nothing in Visual Basic) string was supplied.<br>    '/ &lt;/returns&gt;<br>    Public Shared Function StringToHLocalUni(ByVal s As String) As IntPtr<br>        If s Is Nothing Then<br>            Return IntPtr.Zero<br>        Else<br>            Dim nc As Integer = s.Length<br>            Dim len As Integer = 2 * (1 + nc)<br>            Dim hLocal As IntPtr = AllocHLocal(len)<br>            'If hLocal = IntPtr.Zero Then<br>            If hLocal.ToInt32 = 0 Then<br>                Throw New OutOfMemoryException<br>            Else<br>                interopserv.Marshal.Copy(s.ToCharArray(), 0, hLocal, s.Length)<br>                Return hLocal<br>            End If<br>        End If<br>    End Function  'StringToHLocalUni<br><br>    Public Shared Function IntToHLocalUni(ByVal s As Int32) As IntPtr<br>        If s = 0 Then<br>            Return IntPtr.Zero<br>        Else<br>            Dim nc As Integer = interopserv.Marshal.SizeOf(s)<br>            Dim len As Integer = 2 * (1 + nc)<br>            Dim hLocal As IntPtr = AllocHLocal(len)<br>            'If hLocal = IntPtr.Zero Then<br>            If hLocal.ToInt32 = 0 Then<br>                Throw New OutOfMemoryException<br>            Else<br>                'interopserv.Marshal.Copy(s.ToString, 0, hLocal, nc)<br>                Return hLocal<br>            End If<br>        End If<br>    End Function  'StringToHLocalUni<br><br>End Class 'Marshal<br>'End Namespace 'NetCF.Runtime.InteropServices<br><br><span style="font-weight:bold">and the SMS Class from the example</span><br>Imports System.Runtime.InteropServices<br>Imports interopserv = System.Runtime.InteropServices<br><br>Public Enum SMS_ADDRESS_TYPE<br>    SMSAT_UNKNOWN = 0<br>    SMSAT_INTERNATIONAL<br>    SMSAT_NATIONAL<br>    SMSAT_NETWORKSPECIFIC<br>    SMSAT_SUBSCRIBER<br>    SMSAT_ALPHANUMERIC<br>    SMSAT_ABBREVIATED<br>End Enum 'SMS_ADDRESS_TYPE<br><br>Public Structure PhoneAddress<br>    '/ &lt;summary&gt;The address type.&lt;/summary&gt;<br>    Public AddressType As SMS_ADDRESS_TYPE<br>    '/ &lt;summary&gt;The phone number in string format.&lt;/summary&gt;<br>    Public Address() As Char<br>End Structure 'PhoneAddress<br><br>Public Class SMS<br>    Private Shared SMS_MSGTYPE_TEXT As String = &quot;Microsoft Text SMS Protocol&quot;<br>    Private Shared SMS_MODE_SEND As Long = &amp;H2<br>    Private Shared SMS_OPTION_DELIVERY_NONE As Long = &amp;H0<br>    Private Shared SMS_OPTION_DELIVERY_NO_RETRY As Long = &amp;H1<br>    Private Shared PS_MESSAGE_OPTION_NONE As Long = &amp;H0<br><br>    Private Enum SMS_DATA_ENCODING<br>        SMSDE_OPTIMAL = 0<br>        SMSDE_GSM<br>        SMSDE_UCS2<br>    End Enum 'SMS_DATA_ENCODING<br><br>    Public Enum PROVIDER_SPECIFIC_MESSAGE_CLASS<br>        PS_MESSAGE_CLASS0 = 0<br>        PS_MESSAGE_CLASS1<br>        PS_MESSAGE_CLASS2<br>        PS_MESSAGE_CLASS3<br>    End Enum 'PROVIDER_SPECIFIC_MESSAGE_CLASS<br><br>    Private Enum PROVIDER_SPECIFIC_REPLACE_OPTION<br>        PSRO_NONE = 0<br>        PSRO_REPLACE_TYPE1<br>        PSRO_REPLACE_TYPE2<br>        PSRO_REPLACE_TYPE3<br>        PSRO_REPLACE_TYPE4<br>        PSRO_REPLACE_TYPE5<br>        PSRO_REPLACE_TYPE6<br>        PSRO_REPLACE_TYPE7<br>        PSRO_RETURN_CALL<br>        PSRO_DEPERSONALIZATION<br>    End Enum 'PROVIDER_SPECIFIC_REPLACE_OPTION<br><br>    Private Structure TEXT_PROVIDER_SPECIFIC_DATA<br>        Public dwMessageOptions As Long<br>        Public psMessageClass As PROVIDER_SPECIFIC_MESSAGE_CLASS<br>        Public psReplaceOption As PROVIDER_SPECIFIC_REPLACE_OPTION<br>    End Structure 'TEXT_PROVIDER_SPECIFIC_DATA<br><br>    &lt;System.Runtime.InteropServices.DllImport(&quot;sms.dll&quot;)&gt; _<br>    Private Shared Function SmsOpen(ByVal ptsMessageProtocol As [String], _<br>    ByVal dwMessageModes As Int32, _<br>    ByRef psmshHandle As IntPtr, _<br>    ByVal phMessageAvailableEvent As IntPtr) As IntPtr<br>    End Function<br><br>    &lt;System.Runtime.InteropServices.DllImport(&quot;sms.dll&quot;)&gt; _<br>    Private Shared Function SmsSendMessage(ByVal smshHandle As IntPtr, _<br>    ByVal psmsaSMSCAddress As Int32, _<br>    ByVal psmsaDestinationAddress As IntPtr, _<br>    ByVal pstValidityPeriod As Int32, _<br>    ByVal pbData As IntPtr, _<br>    ByVal dwDataSize As Int32, _<br>    ByVal pbProviderSpecificData() As Byte, _<br>    ByVal dwProviderSpecificDataSize As Int32, _<br>    ByVal smsdeDataEncoding As Int32, _<br>    ByVal dwOptions As Int32, _<br>    ByVal psmsmidMessageID As Int32) As IntPtr<br>    End Function<br><br>    &lt;System.Runtime.InteropServices.DllImport(&quot;sms.dll&quot;)&gt; _<br>    Private Shared Function SmsClose(ByVal smshHandle As IntPtr) As IntPtr<br>    End Function<br><br>    &lt;StructLayout(LayoutKind.Sequential)&gt; _<br>    Public Structure MsgSize<br>        Public MsgSz As Int32<br>    End Structure<br><br>    &lt;StructLayout(LayoutKind.Sequential)&gt; _<br>    Public Structure ProviderDataSize<br>        Public ProvDataSize As Int32<br>    End Structure<br><br>    Public Shared Sub SendMessage(ByVal sPhoneNumber As String, ByVal sMessage As String)<br>        Dim retVal As IntPtr = IntPtr.Zero<br>        Dim smsHandle As IntPtr = IntPtr.Zero<br>        Dim smsProviderData As IntPtr = IntPtr.Zero<br>        Dim smsMessage As IntPtr = IntPtr.Zero<br>        Dim ProvData(12) As Byte<br><br>        Try<br><br>            retVal = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, smsHandle, IntPtr.Zero)<br>            If retVal.ToInt32 &lt;&gt; 0 Then<br>                Throw New Exception(&quot;Could not open SMS.&quot;)<br>            End If<br><br>            'Set address structure<br>            Dim smsatAddressType As Byte() = BitConverter.GetBytes(SMS_ADDRESS_TYPE.SMSAT_UNKNOWN)<br>            Dim ptsAddress As Byte() = System.Text.Encoding.Unicode.GetBytes(sPhoneNumber)<br>            Dim smsAddressTag(smsatAddressType.Length + ptsAddress.Length) As Byte<br>            Array.Copy(smsatAddressType, 0, smsAddressTag, 0, smsatAddressType.Length)<br>            Array.Copy(ptsAddress, 0, smsAddressTag, smsatAddressType.Length, ptsAddress.Length)<br>            Dim smsAddress As IntPtr = Marshal.AllocHLocal(smsAddressTag.Length)<br>            System.Runtime.InteropServices.Marshal.Copy(smsAddressTag, 0, smsAddress, smsAddressTag.Length)<br><br>            'Set message<br>            Dim smsMessageTag As Byte() = System.Text.Encoding.Unicode.GetBytes(sMessage)<br>            smsMessage = Marshal.AllocHLocal(smsMessageTag.Length)<br>            System.Runtime.InteropServices.Marshal.Copy(smsMessageTag, 0, smsMessage, smsMessageTag.Length)<br><br>            retVal = SmsSendMessage(smsHandle, 0, smsAddress, 0, smsMessage, smsMessageTag.Length, _<br>             ProvData, 12, SMS_DATA_ENCODING.SMSDE_OPTIMAL, SMS_OPTION_DELIVERY_NONE, 0)<br><br>        Catch ex As Exception<br>            MessageBox.Show(ex.Message)<br>        End Try<br><br>        Try<br>            retVal = SmsClose(smsHandle)<br>        Catch ex As Exception<br>            MessageBox.Show(ex.Message)<br>        End Try<br>    End Sub<br><br>End Class<br><br>After that I wrote as the example said the following code.<br><br> SMS.SendMessage(&quot;12121212&quot;, &quot;This is a test&quot;)<br><br>But When I run it in the windows mobile 6.0 classic emulator I'm getting <br>Could not find Pinvoke Dll &quot;sms.dll&quot;<br><br>I know that I am missing something but I don't know what it is.<br>Should I deploy something in the emulator ? If yes what should I deploy and also where am I suppose to find it ?<br>When I want to deploy myApp to the real device should I also include something ?<br>Any Ideas ? I also try to configure emulator. Emulator's port in my pc is COM3 and also when running the classic emulator I went to the configure option and changed the serial port to COM3.<br><br>Any ideas ???<br><br>Thank you <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>Thu, 12 Jun 2008 12:10:21 Z2008-06-17T09:08:48Zhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#2b4571e0-1a69-4a64-9f97-59785eb21b8chttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#2b4571e0-1a69-4a64-9f97-59785eb21b8cIlya Tumanovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ilya%20TumanovCould Not load sms.dll<font face=Calibri> <p class=MsoNormal style="margin:0in 0in 10pt"><font size=3>That is expected as WM 6 Classic has no phone capabilities which means no SMS support and thus sms.dll is not present. </font></p> <p class=MsoNormal style="margin:0in 0in 10pt" align=left><font size=3>You should test your SMS code on something actually capable of SMS, e.g. WM 6 Standard (aka SmartPhone) or WM 6 Professional (AKA Pocket PC Phone Edition).</font></p> <p class=MsoNormal style="margin:0in 0in 10pt"><font size=3>Hint: cut down your code to the bare minimum as you’re posing it to the forum. Nobody has time to read pages of code, consequentially your chances of getting an answer are greatly reduced. </font></p> <p class=MsoNormal style="margin:0in 0in 10pt"></font></p>Thu, 12 Jun 2008 16:05:43 Z2008-06-12T16:05:43Zhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#a253ded1-2185-4c89-96d6-d4a515dc8d4fhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#a253ded1-2185-4c89-96d6-d4a515dc8d4fzakkarhttp://social.msdn.microsoft.com/Profile/en-US/?user=zakkarCould Not load sms.dllHi ,<br><br>I have tested both methods using the WM 6 professional emulator. Using the SMS class I'm not getting any exceptions although I will see in a real enviroment if it is working. Using the Microsoft.WindowsMobile.PocketOutlook I'm getting an error saying  'Error sending sms message'.<br>Why am I getting this error ?<br><br>Thank you<br><br><br><br>Fri, 13 Jun 2008 06:26:44 Z2008-06-13T06:26:44Zhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#17105eb9-e67f-4bb0-ba1e-13eeb9f1469ehttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#17105eb9-e67f-4bb0-ba1e-13eeb9f1469ezakkarhttp://social.msdn.microsoft.com/Profile/en-US/?user=zakkarCould Not load sms.dll<div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>zakkar wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%">Hi ,<br><br>I have tested both methods using the WM 6 professional emulator. Using the SMS class I'm not getting any exceptions although I will see in a real enviroment if it is working. Using the Microsoft.WindowsMobile.PocketOutlook I'm getting an error saying  'Error sending sms message'.<br>Why am I getting this error ?<br><br>Also I have deployed my app to my windows mobile 6.0 device and tried to send an SMS using both ways but with no succes.<br>What am I missing ?<br><br>Thank you<br><br><br><br></td></tr></tbody></table></td></tr></tbody></table></div>Fri, 13 Jun 2008 08:12:52 Z2008-06-13T08:12:52Zhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#c93956ed-b0b8-49f7-9271-ee00d38f5907http://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#c93956ed-b0b8-49f7-9271-ee00d38f5907Ilya Tumanovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ilya%20TumanovCould Not load sms.dll<p><span style="font-size:10pt;font-family:'Arial','sans-serif'">Think about it: to actually send SMS message you need cell phone hardware. Emulator has none so it cannot possibly send or receive SMS message for real. Thus it must fake it somehow so you can see this fake SMS in some way. To do so there's a tool called &quot;Cellular Emulator&quot; which fakes it all (normally found in &quot;%ProgramFiles%\Windows Mobile 6 SDK\Tools\Cellular Emulator&quot;). You should use it to simulate all kind of phone activities, see <a title="http://blogs.msdn.com/dglover/archive/2007/04/03/how-to-connect-the-windows-mobile-device-emulator-v2-to-the-wm6-sdk-cellular-emulator.aspx" href="http://blogs.msdn.com/dglover/archive/2007/04/03/how-to-connect-the-windows-mobile-device-emulator-v2-to-the-wm6-sdk-cellular-emulator.aspx">this</a>.</span></p> <p><span style="font-size:10pt;font-family:'Arial','sans-serif'"> </span></p> <p><span style="font-size:10pt;font-family:'Arial','sans-serif'">What's wrong with actual device? That I would not know. Make sure it has valid SIM card and whatever plan you're using includes SMS capabilities.</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><font face=Calibri size=3></font> </p>Sat, 14 Jun 2008 18:12:08 Z2008-06-17T09:08:48Zhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#b79658cd-528b-4ca0-8448-5b60d2bb4ed6http://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#b79658cd-528b-4ca0-8448-5b60d2bb4ed6zakkarhttp://social.msdn.microsoft.com/Profile/en-US/?user=zakkarCould Not load sms.dllhi and thank you for your answer.I wasn't expecting to send an sms from the emulator.But I was expecting to send from  my WM device. I have the glofiish X500 + which includes everything. GPS , WM 6.0 and also a valid sim cause I'm using it as a mobile phone.<br>Is there any additional setting which I need to take care off or with the two lines of code (let's say that I am going to use pocketoutlook class ) I will send it by itsself ?<br><br>PocketOutlook class will find the settings ? Or It supports specific types of devices ? Also in my device I can open contacts as Outlook contacts because I'm sychronizing my device with my PC's Outlook.<br>Is it supposed to be working without doing any additional settings ? Just the code I wrote and that's it ?<br><br>Thank you<br>Tue, 17 Jun 2008 05:54:51 Z2008-06-17T05:54:51Zhttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#56d33ee4-d679-4cea-a5f1-ce7632139f6ahttp://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/fe3b2463-2489-453d-a787-eb43e07295bf#56d33ee4-d679-4cea-a5f1-ce7632139f6azakkarhttp://social.msdn.microsoft.com/Profile/en-US/?user=zakkarCould Not load sms.dll<p>Hi  .</p> <p align=left>It is working.</p> <p align=left>I have reset the emulator , sent the sms from the emulator (I saw the sms on the emulator's screen ) and installed it on my device.</p> <p align=left>It is working now.</p> <p align=left> </p> <p align=left>Thank you</p> <p align=left> </p> <p align=left><font face=Arial size=2></font> </p>Tue, 17 Jun 2008 09:10:29 Z2008-06-17T09:10:29Z