Turning on GPRS programmatically

G

Goggs

Hi

I have developed a Pocket PC mobile application which
transfers data from the PDA to a destop computer. My
issue is, GPRS need to be turned on/connected before the
data transfer can be preformed.

Is there a way to programmatically turn GPRS on as appose
to doing this manually (I'm looking to do the same thing
as Start -> Settings, Connections, Internet Settings
Modify, click & Connect.). I would love an example in C#.
 
F

Floris Briolas

Dear Tony,

You should install evc and check out the connmgr.h look for
ConnMgrEstablishConnection. But there is also another option for you, make a
webrequest for your site, cf.net should try to connect on it's owe.

regards Floris Briolas
 
Z

Zippy

You can programatically start an existing dialup connection using the
rnaapp.exe passing the name of the connection you want to initiate as
a parameter with the -e attribute

below is the code to run an executable with a parameter (encapsulated
in a class called utils)


class SHELLEXECUTEEX
{
public UInt32 cbSize;
public UInt32 fMask;
public IntPtr hwnd;
public IntPtr lpVerb;
public IntPtr lpFile;
public IntPtr lpParameters;
public IntPtr lpDirectory;

public int nShow;
public IntPtr hInstApp;
// Optional members
public IntPtr lpIDList;
public IntPtr lpClass;
public IntPtr hkeyClass;
public UInt32 dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}


public class Utils
{
[DllImport("coredll")]
extern static int ShellExecuteEx( SHELLEXECUTEEX ex );

[DllImport("coredll")]
extern static IntPtr LocalAlloc( int flags, int size );

[DllImport("coredll")]
extern static void LocalFree( IntPtr ptr );

// Code starts here

public static void Execute(string Filename, string param)
{
int nSize = Filename.Length * 2 + 2;
int pSize = param.Length *2+2;
IntPtr pData = LocalAlloc(0x40, nSize);
IntPtr parm = LocalAlloc(0x40, pSize);
Marshal.Copy(Encoding.Unicode.GetBytes(Filename), 0, pData, nSize -
2);
Marshal.Copy(Encoding.Unicode.GetBytes(param),0, parm, pSize -2);

SHELLEXECUTEEX see = new SHELLEXECUTEEX();
see.cbSize = 60;
see.dwHotKey = 0;
see.fMask = 0;
see.hIcon = IntPtr.Zero;
see.hInstApp = IntPtr.Zero;
see.hProcess = IntPtr.Zero;;
see.lpClass = IntPtr.Zero;
see.lpDirectory = IntPtr.Zero;
see.lpIDList = IntPtr.Zero;
see.lpParameters = parm;
see.lpVerb = IntPtr.Zero;
see.nShow = 0;
see.lpFile = pData;

ShellExecuteEx(see);

LocalFree(pData);
}

public Utils()
{

}
}

and to call the method -

Utils.Execute (@"\windows\rnaapp.exe"," -e"+connectionName);

Using this method you can set up the connection via the HHT and open
whenever required.


hope this helps
Andy
 
F

Floris Briolas

Zippy

nice, how can you close the connection?

Zippy said:
You can programatically start an existing dialup connection using the
rnaapp.exe passing the name of the connection you want to initiate as
a parameter with the -e attribute

below is the code to run an executable with a parameter (encapsulated
in a class called utils)


class SHELLEXECUTEEX
{
public UInt32 cbSize;
public UInt32 fMask;
public IntPtr hwnd;
public IntPtr lpVerb;
public IntPtr lpFile;
public IntPtr lpParameters;
public IntPtr lpDirectory;

public int nShow;
public IntPtr hInstApp;
// Optional members
public IntPtr lpIDList;
public IntPtr lpClass;
public IntPtr hkeyClass;
public UInt32 dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}


public class Utils
{
[DllImport("coredll")]
extern static int ShellExecuteEx( SHELLEXECUTEEX ex );

[DllImport("coredll")]
extern static IntPtr LocalAlloc( int flags, int size );

[DllImport("coredll")]
extern static void LocalFree( IntPtr ptr );

// Code starts here

public static void Execute(string Filename, string param)
{
int nSize = Filename.Length * 2 + 2;
int pSize = param.Length *2+2;
IntPtr pData = LocalAlloc(0x40, nSize);
IntPtr parm = LocalAlloc(0x40, pSize);
Marshal.Copy(Encoding.Unicode.GetBytes(Filename), 0, pData, nSize -
2);
Marshal.Copy(Encoding.Unicode.GetBytes(param),0, parm, pSize -2);

SHELLEXECUTEEX see = new SHELLEXECUTEEX();
see.cbSize = 60;
see.dwHotKey = 0;
see.fMask = 0;
see.hIcon = IntPtr.Zero;
see.hInstApp = IntPtr.Zero;
see.hProcess = IntPtr.Zero;;
see.lpClass = IntPtr.Zero;
see.lpDirectory = IntPtr.Zero;
see.lpIDList = IntPtr.Zero;
see.lpParameters = parm;
see.lpVerb = IntPtr.Zero;
see.nShow = 0;
see.lpFile = pData;

ShellExecuteEx(see);

LocalFree(pData);
}

public Utils()
{

}
}

and to call the method -

Utils.Execute (@"\windows\rnaapp.exe"," -e"+connectionName);

Using this method you can set up the connection via the HHT and open
whenever required.


hope this helps
Andy


"Goggs" <[email protected]> wrote in message
Hi

I have developed a Pocket PC mobile application which
transfers data from the PDA to a destop computer. My
issue is, GPRS need to be turned on/connected before the
data transfer can be preformed.

Is there a way to programmatically turn GPRS on as appose
to doing this manually (I'm looking to do the same thing
as Start -> Settings, Connections, Internet Settings
Modify, click & Connect.). I would love an example in C#.
 
Z

Zippy

To be honest i havent got that far yet.
This is only my second month on C#

i'd do a bit of surfing for rnaapp.exe and see what you can find.

Andy


Floris Briolas said:
Zippy

nice, how can you close the connection?

Zippy said:
You can programatically start an existing dialup connection using the
rnaapp.exe passing the name of the connection you want to initiate as
a parameter with the -e attribute

below is the code to run an executable with a parameter (encapsulated
in a class called utils)


class SHELLEXECUTEEX
{
public UInt32 cbSize;
public UInt32 fMask;
public IntPtr hwnd;
public IntPtr lpVerb;
public IntPtr lpFile;
public IntPtr lpParameters;
public IntPtr lpDirectory;

public int nShow;
public IntPtr hInstApp;
// Optional members
public IntPtr lpIDList;
public IntPtr lpClass;
public IntPtr hkeyClass;
public UInt32 dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}


public class Utils
{
[DllImport("coredll")]
extern static int ShellExecuteEx( SHELLEXECUTEEX ex );

[DllImport("coredll")]
extern static IntPtr LocalAlloc( int flags, int size );

[DllImport("coredll")]
extern static void LocalFree( IntPtr ptr );

// Code starts here

public static void Execute(string Filename, string param)
{
int nSize = Filename.Length * 2 + 2;
int pSize = param.Length *2+2;
IntPtr pData = LocalAlloc(0x40, nSize);
IntPtr parm = LocalAlloc(0x40, pSize);
Marshal.Copy(Encoding.Unicode.GetBytes(Filename), 0, pData, nSize -
2);
Marshal.Copy(Encoding.Unicode.GetBytes(param),0, parm, pSize -2);

SHELLEXECUTEEX see = new SHELLEXECUTEEX();
see.cbSize = 60;
see.dwHotKey = 0;
see.fMask = 0;
see.hIcon = IntPtr.Zero;
see.hInstApp = IntPtr.Zero;
see.hProcess = IntPtr.Zero;;
see.lpClass = IntPtr.Zero;
see.lpDirectory = IntPtr.Zero;
see.lpIDList = IntPtr.Zero;
see.lpParameters = parm;
see.lpVerb = IntPtr.Zero;
see.nShow = 0;
see.lpFile = pData;

ShellExecuteEx(see);

LocalFree(pData);
}

public Utils()
{

}
}

and to call the method -

Utils.Execute (@"\windows\rnaapp.exe"," -e"+connectionName);

Using this method you can set up the connection via the HHT and open
whenever required.


hope this helps
Andy


"Goggs" <[email protected]> wrote in message
Hi

I have developed a Pocket PC mobile application which
transfers data from the PDA to a destop computer. My
issue is, GPRS need to be turned on/connected before the
data transfer can be preformed.

Is there a way to programmatically turn GPRS on as appose
to doing this manually (I'm looking to do the same thing
as Start -> Settings, Connections, Internet Settings
Modify, click & Connect.). I would love an example in C#.
 

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