Checking if device is docked - please help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is driving me mad, i'm using the below code:

public static bool IsDeviceDocked()
{
bool bRetVal = false;
try
{
string sHostName = Dns.GetHostName();

IPHostEntry ipheThisHost = Dns.GetHostByName(sHostName);
IPAddress ipThisAddr = ipheThisHost.AddressList[0];

string ip = ipThisAddr.ToString();
string localhost = IPAddress.Parse("127.0.0.1").ToString();

if (ip == localhost)
{
bRetVal = false;
}
else
{
bRetVal = true;
}
}
catch (Exception ex)
{
// TODO: Add your own exception handling here
}
return bRetVal;
}

Basically, if i start the application while it's docked then it returns true
(as it should), if the application is started docked but then unplugged it
still returns true, if i start it unplugged then it returns false.

What is a reliable way of telling if it's docked or not? Nothing seems to
work for me.

Thanks guys
 
If you're using Windows Mobile 5.0 or higher then you should check out the
CradlePresent SystemState from the SNAPI (Microsoft.WindowsMobile.Status)
 
If you resolve PPP_PEER on any version of Windows Mobile, I think you should
get something if you are docked, and nothing if you are not.

Paul T.

Christian Resma Helle said:
If you're using Windows Mobile 5.0 or higher then you should check out the
CradlePresent SystemState from the SNAPI (Microsoft.WindowsMobile.Status)

--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com


Rob S said:
This is driving me mad, i'm using the below code:

public static bool IsDeviceDocked()
{
bool bRetVal = false;
try
{
string sHostName = Dns.GetHostName();

IPHostEntry ipheThisHost = Dns.GetHostByName(sHostName);
IPAddress ipThisAddr = ipheThisHost.AddressList[0];

string ip = ipThisAddr.ToString();
string localhost =
IPAddress.Parse("127.0.0.1").ToString();

if (ip == localhost)
{
bRetVal = false;
}
else
{
bRetVal = true;
}
}
catch (Exception ex)
{
// TODO: Add your own exception handling here
}
return bRetVal;
}

Basically, if i start the application while it's docked then it returns
true
(as it should), if the application is started docked but then unplugged
it
still returns true, if i start it unplugged then it returns false.

What is a reliable way of telling if it's docked or not? Nothing seems to
work for me.

Thanks guys
 
Thanks, that works perfectly.

Christian Resma Helle said:
If you're using Windows Mobile 5.0 or higher then you should check out the
CradlePresent SystemState from the SNAPI (Microsoft.WindowsMobile.Status)

--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com


Rob S said:
This is driving me mad, i'm using the below code:

public static bool IsDeviceDocked()
{
bool bRetVal = false;
try
{
string sHostName = Dns.GetHostName();

IPHostEntry ipheThisHost = Dns.GetHostByName(sHostName);
IPAddress ipThisAddr = ipheThisHost.AddressList[0];

string ip = ipThisAddr.ToString();
string localhost = IPAddress.Parse("127.0.0.1").ToString();

if (ip == localhost)
{
bRetVal = false;
}
else
{
bRetVal = true;
}
}
catch (Exception ex)
{
// TODO: Add your own exception handling here
}
return bRetVal;
}

Basically, if i start the application while it's docked then it returns
true
(as it should), if the application is started docked but then unplugged it
still returns true, if i start it unplugged then it returns false.

What is a reliable way of telling if it's docked or not? Nothing seems to
work for me.

Thanks guys
 

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

Back
Top