PC Review


Reply
Thread Tools Rate Thread

How to check a PDA is connected to the PC

 
 
=?Utf-8?B?cHJha2FzaA==?=
Guest
Posts: n/a
 
      22nd Sep 2004
pHi
I have a program to copy files from desktop pc to PDA for that I
was used OpenNETCF RAPI . It copies the file to the device well.

It gives an exception, when I try to copy the file to device which is not
connected to the PC ( Active sync not installed )

My program hangs, when try to copy the file to device which is not
connected to the PC ( Active sync installed )

There is any way to fix that problem
--
regards
prakash

 
Reply With Quote
 
 
 
 
Neville Lang
Guest
Posts: n/a
 
      22nd Sep 2004
Prakash,

I am using ordinary RAPI and not the one from OpenNETCF though I susepct
these would be the same.

The clue is that CeRapiInit() simply waits for a connection, effectively
"hanging" the program. I have found the best choice is to use the
CeRapiInitEx(). Here is a method that might be useful in that it informs the
user if there is no connection:

public static bool IsDeviceConnected(int MillisecondsToWait)
{
RAPIINIT rapiStructure = new RAPIINIT();
rapiStructure.cbSize = 12;
uint hResult = CeRapiInitEx(ref rapiStructure);
if (hResult == E_FAIL)
{
MessageBox.Show("Unable to initialize connection to device !!");
return false;
}
uint hWait = WaitForSingleObject(rapiStructure.heRapiInit,
MillisecondsToWait);
if (hWait == WAIT_FAILED)
{
MessageBox.Show("Unable to wait for device: " +
Marshal.GetLastWin32Error().ToString());
return false;
}
if (hWait == WAIT_TIMEOUT)
{
MessageBox.Show("Timed out waiting for device !!");
return false;
}
if (rapiStructure.hrRapiInit == E_FAIL)
{
MessageBox.Show("Failed to connect to device !!");
return false;
}
return true;
}


I pass a value of 5000 to this method, allowing 5 seconds to wait if the PPC
is not in the cradle.

Regards,
Neville Lang



"prakash" <(E-Mail Removed)> wrote in message
news:EFB5C953-6015-46D3-8E75-(E-Mail Removed)...
> pHi
> I have a program to copy files from desktop pc to PDA for that I
> was used OpenNETCF RAPI . It copies the file to the device well.
>
> It gives an exception, when I try to copy the file to device which is not
> connected to the PC ( Active sync not installed )
>
> My program hangs, when try to copy the file to device which is not
> connected to the PC ( Active sync installed )
>
> There is any way to fix that problem
> --
> regards
> prakash
>



 
Reply With Quote
 
=?Utf-8?B?cHJha2FzaA==?=
Guest
Posts: n/a
 
      22nd Sep 2004
Thank you very much Neville

can you give the declaration of RAPIINIT,CeRapiInitEx , constant values

regards
prakash

"Neville Lang" wrote:

> Prakash,
>
> I am using ordinary RAPI and not the one from OpenNETCF though I susepct
> these would be the same.
>
> The clue is that CeRapiInit() simply waits for a connection, effectively
> "hanging" the program. I have found the best choice is to use the
> CeRapiInitEx(). Here is a method that might be useful in that it informs the
> user if there is no connection:
>
> public static bool IsDeviceConnected(int MillisecondsToWait)
> {
> RAPIINIT rapiStructure = new RAPIINIT();
> rapiStructure.cbSize = 12;
> uint hResult = CeRapiInitEx(ref rapiStructure);
> if (hResult == E_FAIL)
> {
> MessageBox.Show("Unable to initialize connection to device !!");
> return false;
> }
> uint hWait = WaitForSingleObject(rapiStructure.heRapiInit,
> MillisecondsToWait);
> if (hWait == WAIT_FAILED)
> {
> MessageBox.Show("Unable to wait for device: " +
> Marshal.GetLastWin32Error().ToString());
> return false;
> }
> if (hWait == WAIT_TIMEOUT)
> {
> MessageBox.Show("Timed out waiting for device !!");
> return false;
> }
> if (rapiStructure.hrRapiInit == E_FAIL)
> {
> MessageBox.Show("Failed to connect to device !!");
> return false;
> }
> return true;
> }
>
>
> I pass a value of 5000 to this method, allowing 5 seconds to wait if the PPC
> is not in the cradle.
>
> Regards,
> Neville Lang

 
Reply With Quote
 
Neville Lang
Guest
Posts: n/a
 
      22nd Sep 2004
Prakash,

Sorry, I should have added those earlier.

public const uint E_FAIL = 0x80004005;
public const uint WAIT_FAILED = 0xffffffff;
public const uint WAIT_TIMEOUT = 0x00000102;

[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
public uint cbSize;
public uint heRapiInit;
public uint hrRapiInit;
}

[DllImport("rapi.dll", CharSet=CharSet.Unicode)]
public static extern uint CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref
RAPIINIT pRapiInit);

[DllImport("kernel32.dll", SetLastError=true)]
public static extern uint WaitForSingleObject(uint hHandle, int
milliseconds);


Regards,
Neville Lang




"prakash" <(E-Mail Removed)> wrote in message
news:A30CB0FC-E9E2-4444-BEF1-(E-Mail Removed)...
> Thank you very much Neville
>
> can you give the declaration of RAPIINIT,CeRapiInitEx , constant values
>
> regards
> prakash
>
> "Neville Lang" wrote:
>
> > Prakash,
> >
> > I am using ordinary RAPI and not the one from OpenNETCF though I susepct
> > these would be the same.
> >
> > The clue is that CeRapiInit() simply waits for a connection, effectively
> > "hanging" the program. I have found the best choice is to use the
> > CeRapiInitEx(). Here is a method that might be useful in that it informs

the
> > user if there is no connection:
> >
> > public static bool IsDeviceConnected(int MillisecondsToWait)
> > {
> > RAPIINIT rapiStructure = new RAPIINIT();
> > rapiStructure.cbSize = 12;
> > uint hResult = CeRapiInitEx(ref rapiStructure);
> > if (hResult == E_FAIL)
> > {
> > MessageBox.Show("Unable to initialize connection to device !!");
> > return false;
> > }
> > uint hWait = WaitForSingleObject(rapiStructure.heRapiInit,
> > MillisecondsToWait);
> > if (hWait == WAIT_FAILED)
> > {
> > MessageBox.Show("Unable to wait for device: " +
> > Marshal.GetLastWin32Error().ToString());
> > return false;
> > }
> > if (hWait == WAIT_TIMEOUT)
> > {
> > MessageBox.Show("Timed out waiting for device !!");
> > return false;
> > }
> > if (rapiStructure.hrRapiInit == E_FAIL)
> > {
> > MessageBox.Show("Failed to connect to device !!");
> > return false;
> > }
> > return true;
> > }
> >
> >
> > I pass a value of 5000 to this method, allowing 5 seconds to wait if the

PPC
> > is not in the cradle.
> >
> > Regards,
> > Neville Lang



 
Reply With Quote
 
=?Utf-8?B?cHJha2FzaA==?=
Guest
Posts: n/a
 
      22nd Sep 2004
Thank you very much Neville . your codes works very well

I post the VB version of your code
------------------------------------------
Public Structure RAPIINIT
Friend cbSize As Int32
Friend heRapiInit As Int32
Friend hrRapiInit As Int32
End Structure

<System.Runtime.InteropServices.DllImport("rapi.dll",
CharSet:=Runtime.InteropServices.CharSet.Unicode)> _
Public Shared Function
CeRapiInitEx(<System.runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Struct)> ByRef pRapiInit As RAPIINIT) As Integer
End Function

<System.Runtime.InteropServices.DllImport("kernel32.dll",
SetLastError:=True)> _
Public Shared Function WaitForSingleObject(ByVal hHandle As Integer,
ByVal dwMilliseconds As Integer) As Integer
End Function

Public Const E_FAIL = &H80004005
Public Const WAIT_FAILED = &HFFFFFFFF
Public Const WAIT_TIMEOUT = &H102

Public Function IsDeviceConnected(ByVal MilliSecondsToWait As Integer)
As Boolean
Dim rapiStructure As New RAPIINIT
Dim hresult As Integer

rapiStructure.cbSize = 12
hresult = CeRapiInitEx(rapiStructure)

If hresult = E_FAIL Then
MsgBox("Unable to initialize connection to device !!")
Return False
End If

Dim hWait As Integer = WaitForSingleObject(rapiStructure.heRapiInit,
MilliSecondsToWait)

If hWait = WAIT_FAILED Then
MsgBox("Unable to wait for device: " &
System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString())
Return False
ElseIf (hWait = WAIT_TIMEOUT) Then
MessageBox.Show("Timed out waiting for device !!")
Return False
ElseIf (rapiStructure.hrRapiInit = E_FAIL) Then
MessageBox.Show("Failed to connect to device !!")
Return False
End If

Return True
End Function

Regards
prakash


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if i'm connected to the internet =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 3 12th Jun 2007 05:25 AM
Check Mapped Drive is Connected Ben Microsoft VB .NET 6 30th Mar 2006 07:24 PM
Re: how to check if printer is offline/connected in vb .Net Ken Tucker [MVP] Microsoft VB .NET 0 4th Aug 2004 01:15 PM
how to check if internet is connected? Paul M Microsoft Dot NET Framework Forms 0 2nd Apr 2004 04:19 PM
Check if connected via ActiveSync Dan M Microsoft Dot NET Compact Framework 1 9th Jan 2004 09:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:40 AM.