GPRS connectivity in EVB - Windows Mobile Development and Hacking General

I have an EVB application that connects to GPRS using a library from Sapphire Solutions.
This has worked reasonably well, but doesn't give me a lot of control of what is going on.
What other methods have people tried? Any hints?

here
I also was lookinf for this solution forever and never found it so i wrote the software myself. Here is the dll that you need to connect to the internet through evb it connects to the default connection no problems.
http://xdaconnect.wastedbrains.com
have fun,
Dan Mayer

Thanks for this. I'll have a play.
The stupid thing is, O2 have told me that I should be using their routines. But nobody can tell me what the routines are, how to find them or give me any information about them whatsoever!
Compare and contrast with Vodafone who actually know a thing or two about implementing mobile systems, but don't have a product to implement...

Code:
Public Declare Function AllocPointer Lib "VBPointers" Alias "VB_AllocPointer" (ByVal nSrcSizeInBytes As Long) As Long
Public Declare Function AllocStringPointer Lib "VBPointers" Alias "VB_AllocStringPointer" (ByVal str As String) As Long
Public Declare Function FreePointer Lib "VBPointers" Alias "VB_FreePointer" (ByVal Pointer As Long) As Long
Public Declare Sub SetLongAt Lib "VBPointers" Alias "VB_SetLongAt" (ByVal Pointer As Long, ByVal OffsetInBytes As Long, ByVal Value As Long)
Public Declare Function PhoneMakeCall Lib "Phone" (ByVal CallInfo As Long) As Long
Public Sub Dial(Number_to_dial As String)
CallInfo = AllocPointer(24) ' sizeof (PHONEMAKECALLINFO)
Call SetLongAt(CallInfo, 0, 24) ' cbSize
Call SetLongAt(CallInfo, 4, 1) ' dwFlags = PMCF_DEFAULT
PhoneNumber = AllocStringPointer(Number_to_dial)
Call SetLongAt(CallInfo, 8, PhoneNumber) ' pszDestAddress
PhoneMakeCall (CallInfo)
FreePointer (PhoneNumber)
FreePointer (CallInfo)
End Sub

The xdaconnect dll posted by Dan is pretty good at getting a connection. The problem is that it has to be registered on each device using eVC. My problem is that I want to make a cd so that other people who dont have eVC can install the device. Normally I would do this with dllRegisterServer or by including the file in the manifest file of dll's to be registered when a program is installed. The problem is that this dll wont register alone, an error is returned back that "dllRegsisterServer is not included in the dll".
Can anyone help?
The dll and eVC project file is available for download at http://xdaconnect.wastedbrains.com
Many thanks
Tony

Related

Using Connection Manager in vb.net

Does anyone know how to use the connection manager API to programatically detect GPRS disconnection and start a new connection? I can find some code for C# (openNETCF) and eVC++ (Microsoft's CMhelper), but not VB.net.
Any ideas or links?
Thanks,
Kath
OpenNETCF, MissingMethodException, TypeLoadException
I was advised to just add a reference to the opennetcf.dll, which seems the best option!
I've managed to add a reference to the OpenNETCF.Net.dll, and my
project works with the added references (openNETCF.Net.dll and
mscorlib). However, I have the following problems if I try to declare
an instance of the opennetcf:
1) In my global declarations module, I add the declaration:
"Public GPRSconn As New OpenNETCF.Net.ConnectionManager".
When I try to run the project, it crashes on my form's class (before
opening the form), with a MissingMethodException (in myproject.exe).
2) I move the declaration to my first form, declaring it locally in a
sub. The form loads fine. When I click on my button, it crashes on the
line which calls my sub to declare the GPRSconn, with the exception:
TypeLoadException (in myproject.exe).
ie.
Private Sub TrytoDecGPRS()
Try
Dim GPRSconn As New OpenNETCF.Net.ConnectionManager
MsgBox(GPRSconn.State.ToString)
Catch ex As Exception
MsgBox("intro(tryGPRS): " + ex.Message)
End Try
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
TrytoDecGPRS()
It crashes on the line "TrytoDecGPRS()"
Am I not declaring the opennetcf correctly? Am I missing something?
Any help greatly appreciated!
Thanks,
Kath
solution
Someone on another group helped me out, I needed to reference the OpenNetCF.dll as well as the OpenNetCF.Net.dll.

GPRS

Hi I am very new to C# and compact framework. I have been coding for XDA's using eVB. I want to be able to enable the GPRS mode and also be able to Hangup.
Do I use RasDial? Is this an achievable task for a C# beginer? Could someone please give me some hints as how to achieve this.
Highflyer,
Firstly, why move over to C# when you can achieve what you want using VB.NET. Like yourself, I have ported across an eVB Rasdial app across to .NET CF. Secondly, with GPRS remember that you only pay for the data that is transferred over the connection, so you dont need to worry about the disconnection, but this can be done manually by putting the XDA into FLIGHT MODE. I think you will find another thread covering how to do this programmatically in this forum.
In my app, my XDA is sending and requesting XML packets over HTTP to a web server. To do this I use the HttpWebRequest and HttpWebResponse classes.
Here is a snippet of code
*******************************
Public Function Post(ByVal sURL As String, Optional ByVal strRequest As String = "", Optional ByVal blnRetValExpected As Boolean = False, Optional ByRef strReturned As String = "", Optional ByRef intStatus As Integer = 0) As Boolean
Dim WebReq As HttpWebRequest
Dim WebRes As HttpWebResponse
Dim bOK As Boolean
Try
WebReq = CType(WebRequest.Create(sURL), HttpWebRequest)
If strRequest <> "" Then
Dim encoding As New ASCIIEncoding
Dim byte1 As Byte() = encoding.GetBytes(strRequest)
WebReq.Method = "POST"
WebReq.ContentType = "application/x-www-form-urlencoded"
WebReq.ContentLength = strRequest.Length
Dim newStream As Stream = WebReq.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
newStream.Close()
End If
WebRes = CType(WebReq.GetResponse(), HttpWebResponse)
If WebRes.StatusCode = HttpStatusCode.OK Then
bOK = True
End If
intStatus = WebRes.StatusCode
Catch ex As InvalidOperationException
bOK = False
Catch ex As WebException
bOK = False
Catch ex As ProtocolViolationException
bOK = False
End Try
If bOK And blnRetValExpected Then
If WebRes.ContentLength > 0 Then
Dim sResponse() As Byte
Dim ReceiveStream As Stream = WebRes.GetResponseStream()
Dim encode As encoding = encoding.GetEncoding("utf-8")
Dim ReadStream As New StreamReader(ReceiveStream, encode)
Dim strXML As String = ""
Try
strXML = ReadStream.ReadToEnd()
Catch ex As Exception
strXML = ""
bOK = false
Finally
ReadStream.Close()
End Try
strReturned = strXML
End If
End If
WebRes.Close()
Post = bOK
End Function
*******************************
What you will find with the above code is that there is no code for making the GPRS connection and RasDial is no longer required. This is due to the code being hidden away in the HttpWebRequest class and the GPRS connection will use the current connection if it exists or prompt the user for the connection to use. The prompting can be overcome by setting a defualt GPRS connection in Settings - Connection Manager, and saving the password along with it. HTH.
Tony,
Many thanks for your advice. The included sample code is very useful. The problem is I have to stick with C#, wether I like it or not. However I can follow your code to reporoduce something similar in C#. I have already used Post in eVB, to send data, however I changed over to using sockets (WinSock), since I understand there is lower data over head in using sockets. I appreciate any comments you may have with this choice.
One question, you mentioned that when we connect to GPRS we do not pay for actual connection. Is this right, my understanding was when the device connects to GPRS, some data is used to achieve this connection, thus just establishing a connection to GPRS would cost. I am thinking of the situation when GPRS has to be enabled and disabled hundreds of times a day.
Thanks again, looking forward to hear any comments.
Highflyer,
Regarding a connection charge - you may be right about this depending on the type of contract you are on, but as I mentioned once a connection is established you are only charged for the data that is transferred over the connection, so why not leave the connection open then there will only be the one connection charge. If the connection is lost due to poor signal then the underlying code of the web components will re-establish the connection as and when required. HTH.
Thanks for your advice.
I am still very interested to be able to perform RasDial using C#. As I said I have tried to write the code however due to my lack of experience in using C# the code does not work.
Any Ideas or advice anybody.
Thanks
WebRequest on Magician/XDA Mini?
Hi there!
I´m glad finding .NET developers here ;-)
I have a big, big problem:
On several XDA Mini´s (HTC Magician) the HttpWebRequest or WebRequest methods instantly return with an exception (ConnectFailure), even if Pocket IE or other software can reach the net. I´ve tested both, connection via ActiveSync and GPRS, but it does not work.
Any ideas on this? Is it a known issue, and is there a way to solve it?
Thanky in advance,

VB.NET how to pass a struct? anyone?

Anyone know how to pass a pointer to a struct in VB.NET that could help me out?
" pGPSPosition
Pointer to a GPS_POSITION structure. On return, this structure is filled with location data obtained by the GPS Intermediate Driver. The dwValidFields member of the GPS_POSITION instance specifies which fields of the instance are valid."
This is from a link on MS site: (http://msdn2.microsoft.com/en-us/library/bb202050.aspx)
So how do I do this in VB?
Looking for a little love here...
TIA,
WM6 SDK contains the sample with the complete wrapper around the GPS intermediate driver in the managed code
But one warning - on some devices (namely HTC Artemis) the serious bug in some version of code provided by Microsoft to Oem return an error when calling functions this API. Communication with a GPS via serial port is still more reliable for a commercial solutions...
Appreciate the response but do you have any source that I can use with VB? My biggest problem is actually retrieving any information from the GPS device using the "GPSGetPosition" function. (see other link - http://forum.xda-developers.com/showthread.php?p=1979418#post1979418)
"But one warning - on some devices (namely HTC Artemis) the serious bug in some version of code provided by Microsoft to Oem return an error when calling functions this API"
Could you be a little more specific?
TW,
Semi manual marshhalling of structure to pointer:
Dim pointerM As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(myStruct))
Marshal.StructureToPtr(myStruct, pointerM, False)
Marshal.FreeHGlobal(pnt)
Ad Artemis and another devices) GPS structure has invalid size from old platform builder and intermediate driver (GPS API) refuse it with error.
RStein,
As I was reading about it appeared that Marshaling was going to have to be used in some way since I'm pretty sure that the struct would need to be passed to the C function.
Which brings me to another Q since it appears your are savy at programing in C - how to convert the following C struct?
The struct appears to have a couple of arrays and a few other enums thats are passed to the function, how is that handled in VB?
DWORD GPSGetPosition(
HANDLE hGPSDevice,
GPS_POSITION *pGPSPosition,
DWORD dwMaximumAge,
DWORD dwFlags
);
typedef struct _GPS_POSITION {
DWORD dwVersion;
DWORD dwSize;
DWORD dwValidFields;
DWORD dwFlags;
SYSTEMTIME stUTCTime;
double dblLatitude;
double dblLongitude;
float flSpeed;
float flHeading;
double dblMagneticVariation;
float flAltitudeWRTSeaLevel;
float flAltitudeWRTEllipsoid;
GPS_FIX_QUALITY FixQuality;
GPS_FIX_TYPE FixType;
GPS_FIX_SELECTION SelectionType;
float flPositionDilutionOfPrecision;
float flHorizontalDilutionOfPrecision;
float flVerticalDilutionOfPrecision;
DWORD dwSatelliteCount;
DWORD rgdwSatellitesUsedPRNs[GPS_MAX_SATELLITES];
DWORD dwSatellitesInView;
DWORD rgdwSatellitesInViewPRNs[GPS_MAX_SATELLITES];
DWORD rgdwSatellitesInViewElevation[GPS_MAX_SATELLITES];
DWORD rgdwSatellitesInViewAzimuth[GPS_MAX_SATELLITES];
DWORD rgdwSatellitesInViewSignalToNoiseRatio[GPS_MAX_SATELLITES];
} GPS_POSITION, *PGPS_POSITION;
Click to expand...
Click to collapse
I had a suggestion to create a library from the C# SDK, how difficult would that be? Would it be easier than trying to convert to VB?
Can you help with that?
Thanks for any feedback...

Play Sound While on Call

Hello,
Does anyone know how to play a sound (preferably through the earpiece) while on a phone call? I found some code on the internet somewhere that allows me to play sound, but when I make a call, it doesn’t work. Here is the code I have now.
Code:
Public Class Sound
Private m_soundBytes() As Byte
Private m_fileName As String
Public Declare Function WCE_PlaySound Lib "CoreDll.dll" Alias "PlaySound" (ByVal szSound As String, ByVal hMod As IntPtr, ByVal flags As Integer) As Integer
Public Declare Function WCE_PlaySoundBytes Lib "CoreDll.dll" Alias "PlaySound" (ByVal szSound() As Byte, ByVal hMod As IntPtr, ByVal flags As Integer) As Integer
Private Enum Flags
SND_SYNC = &H0 ' play synchronously (default)
SND_ASYNC = &H1 ' play asynchronously
SND_NODEFAULT = &H2 ' silence (!default) if sound not found
SND_MEMORY = &H4 ' pszSound points to a memory file
SND_LOOP = &H8 ' loop the sound until next sndPlaySound
SND_NOSTOP = &H10 ' don't stop any currently playing sound
SND_NOWAIT = &H2000 ' don't wait if the driver is busy
SND_ALIAS = &H10000 ' name is a registry alias
SND_ALIAS_ID = &H110000 ' alias is a predefined ID
SND_FILENAME = &H20000 ' name is file name
SND_RESOURCE = &H40004 ' name is resource name or atom
End Enum
' Construct the Sound object to play sound data from the specified file.
Public Sub New(ByVal fileName As String)
m_fileName = fileName
End Sub
' Construct the Sound object to play sound data from the specified stream.
Public Sub New(ByVal stream As IO.Stream)
' read the data from the stream
m_soundBytes = New Byte(stream.Length) {}
stream.Read(m_soundBytes, 0, Fix(stream.Length))
End Sub 'New
' Play the sound
Public Sub Play()
' If a file name has been registered, call WCE_PlaySound,
' otherwise call WCE_PlaySoundBytes.
If Not (m_fileName Is Nothing) Then
WCE_PlaySound(m_fileName, IntPtr.Zero, Fix(Flags.SND_ASYNC Or Flags.SND_FILENAME))
Else
WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, Fix(Flags.SND_ASYNC Or Flags.SND_MEMORY))
End If
End Sub
End Class
I am writing this for my Kaiser on WM6, but support for earlier devices would be nice if possible.
Thanks,
Jay
i'm also trying to create an application that vibrates the phone whenever call is connected but somehow the OS mutes all sounds and vibrations while you are making a call.
The code you have, IMHO, plays the sound through the loudspeaker, not the earpiece.
what you would have to do, because i have done it, is set the registry settings under the control panel (under local machine) and there is an option to set different sounds for differnt events/actions/calls/messages etc
try API PlayEventSound
this idea is already integrated in LC minutes though i didnt have much time to work it out like it should be.
It would be nice to have a complete customization of this idea.
mrpotter said:
try API PlayEventSound
Click to expand...
Click to collapse
Thank you mrpotter. PlayEventSound did what I was looking for
It may play a sound environmental background during a call to simulate being in a traffic jam or in the countryside?
Example
Can anyone post an example of how to use API playeventsound in .net ?

How can i access VIBRATE from VB-NET

Hello,
i´m writing an application with VB-NET, and i want to access the VIBRATE function. But ...
This API is not supported by Windows Mobile 6 Professional
i´m not able to get this API.
On the MS Homepage i found many function with the funny remark.
How can i make my phone vibrate with vb-net (VSO08P)
and how can i find a offline documentation for the WM6.1 Prof. device ??
Thx.
Daniel
Isn’t possible to access all functions from .NET (VB.NET, C#, etc). Some time is necessary to use unmanage code.
To import a dll you must use function <DllImport(".dll"> (must specify the dll name)
P.S. Excuse my English
Search for SndSetSound on aygshell.dll .
C#
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndSetSound(SoundEvent
seSoundEvent, ref SNDFILEINFO pSoundFileInfo, bool fSuppressUI);
A search at google will give you the rest.
this might work:
Declare Function Vibrate Lib "aygshell.dll" (ByVal cvn As Integer, ByVal rgvn As IntPtr, ByVal fRepeat As Boolean, ByVal dwTimeout As UInteger) As Integer
Declare Function VibrateStop Lib "aygshell.dll" () As Integer
Vibrate(0, IntPtr.Zero, vbTrue, INFINITE)
Const INFINITE As UInteger = 4294967295
Many thanks for the code, but on my device
i don´t fond the "aygshell.dll".
How can i find this ddl for a HTC Diamond for Win Mobile 6.1 Prof. ??
I only found one for an old HTC2000 (?).
And, if i share a programm for the HTC , it is legal to copy the DLL ??
Daniel
OK - I found a DLL and want to transfer the dll to WINDOWS ... but the file already exist $§%§..
The Scrips don´t work - no error message - no vibrate.
Daniel
danielham said:
Many thanks for the code, but on my device
i don´t fond the "aygshell.dll".
How can i find this ddl for a HTC Diamond for Win Mobile 6.1 Prof. ??
I only found one for an old HTC2000 (?).
And, if i share a programm for the HTC , it is legal to copy the DLL ??
Daniel
OK - I found a DLL and want to transfer the dll to WINDOWS ... but the file already exist $§%§..
The Scrips don´t work - no error message - no vibrate.
Daniel
Click to expand...
Click to collapse
Import aygshell.lib
In MSDN for this functions requirements are:
Pocket PC Platforms: None
OS Versions: Windows CE 3.0 and later
Header: Declared in vibrate.h
Library: Use aygshell.lib
----
Declare Function VibrateStop Lib "aygshell.dll" () As Integer
'Const INFINITE As Integer = 4294967295
Const INFINITE As UInteger = &HFFFFFFFF&
Declare Function Vibrate Lib "aygshell.dll" (ByVal cvn As Integer, ByVal rgvn As IntPtr, ByVal fRepeat As Boolean, ByVal dwTimeout As UInteger) As Integer
----
i tried both version for INFINITE.
First, i work with VB.NET and i don´t find "IMPORT DLL...."
Second, i get a warning message for UInteger dwTimeout, as Integer i get no warning ?
The first statement above are in the Class FORM1
----
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Vibrate(0, IntPtr.Zero, vbTrue, INFINITE)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
VibrateStop()
End Sub
----
And this statement don´t work ...
I want to vibrate if i press a key ...
a "hello world" for vibrate for beginners
Daniel

Categories

Resources