CeRapiInit just hangs if the pocket pc isn't connected

  • Thread starter Thread starter fig000
  • Start date Start date
F

fig000

Hi,

Very new to pocket pcs and net cf. I'm running a small app on my
desktop that reads a file from a viewsonic pocket pc. I had gotten
CeRapiInit to work with the device connected (and I'm able to read
files, etc). I had wanted to set up code to see if the device was or
wasn't connected; I planned to display an error message if the device
wasn't connected so our users would know that no processing had taken
place.

What I found was that if the device wasn't connected, instead of
returning a code indicating non-success, CeRapiInit just hangs the
program. Here's the code:

llReturn = CeRapiInit()
(llreturn is a long; the code is in vb.net)

This is not a deal breaker but annoying. I should be able to see if the
device is connected and put in code to trap that. I'd appreciate any
help.

Neil
 
fig000 said:
Hi,

Very new to pocket pcs and net cf. I'm running a small app on my
desktop that reads a file from a viewsonic pocket pc. I had gotten
CeRapiInit to work with the device connected (and I'm able to read
files, etc). I had wanted to set up code to see if the device was or
wasn't connected; I planned to display an error message if the device
wasn't connected so our users would know that no processing had taken
place.

What I found was that if the device wasn't connected, instead of
returning a code indicating non-success, CeRapiInit just hangs the
program. Here's the code:

llReturn = CeRapiInit()
(llreturn is a long; the code is in vb.net)

This is not a deal breaker but annoying. I should be able to see if the
device is connected and put in code to trap that. I'd appreciate any
help.

Neil

Have a look at CeRapiInitEx instead. CeRapiInit is a blocking function,
so your thread will hang if the device isn't connected. CeRapiInitEx is
non-blocking, so the method will return even if the device isn't
connected. If you have access to it, ".NET Compact Framework Programming
with C#" by Yao and Durant has a section devoted to exactly this.
Shannon
 
Shannon,

Thanks for answering. I've looked in the newsgroups and found some
code to use CERapiInitEx. I think I copied it correctly but I'm getting
this error:

Object reference not set to an instance of an object

The code is:

<DllImport("rapi.dll", CharSet:=CharSet.Unicode)> _
Private Shared Function CeRapiInitEx( _
ByVal pRapiInit As RAPIINIT) As Long
End Function

Structure RAPIINIT
Public cbSize As Long
Public heRapiInit As Long
Public hrRapiInit As Long
End Structure

Dim hr As Long
Dim pRapiInit As New RAPIINIT (I TRIED DOING THIS WITH AND WITHOUT NEW)

Dim dwWaitRet, dwTimeout As Long
pRapiInit.cbSize = Len(pRapiInit)
pRapiInit.heRapiInit = 0
pRapiInit.hrRapiInit = 0
hr = E_FAIL
dwWaitRet = 0
dwTimeout = 10 * ONE_SECOND
hr = CeRapiInitEx(pRapiInit) 'THIS IS WHERE IT JUST HANGS

I can't really see how dwWaitRet and dwTimeout get connected to the
CERapiInitEx. I'm assuming that it must be PrAPInit that isn't geting
instantiated correctly but I don't see how.

Thanks for putting up with a newbie.

Neil
 
Back
Top