Remotely Closing a Pocket PC Application

G

Guest

I'm trying to close an compact framework application (VB.NET) from a VB6
application on my desktop PC. The Pocket PC is connected via Active Sync
(USB). Any ideas?

Apart from directly shutting down the application from my PC I have also
considered using the RAPI function CeCreateProcess to start another app on
the Pocket PC. The second application (VB.NET) would contain all of the code
to shutdown the original application before shutting itself down. However, I
don't know how to accomplish this either.

Your help is much appreciated.
 
P

Peter Foot [MVP]

You can use RAPI on the desktop to communicate with the device. Your best
option would be to either create a native dll which exposes a function you
can call with CeRapiInvoke, or write a managed non-forms exe you can start
using CeCreateProcess. This app should search for the window handle of your
application - e.g. using FindWindow, then send a WM_CLOSE message to it and
close itself.
You can call the RAPI functions from VB6 using Declare to specify the
functions contained. If you use VB.NET on the desktop you can use
OpenNETCF's Desktop.Communication library which has these functions
ready-wrapped.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
G

Guest

Thanks Peter it worked a treat.

For anyone that wants to do the same thing the basis of my code is listed
below. I created a VB.NET windowless app on the Pocket PC that is used
purely to shutdown my main app. Then from my VB6 app on my PC I called this
application using the RAPI Function CeCreateProcess.

VB.NET code:
----------------

Public Declare Function FindWindow Lib "coredll" (ByVal lpClassName As
String, ByVal lpWindowName As String) As IntPtr

Public Declare Function SendMessage Lib "coredll" (ByVal hWnd As IntPtr,
ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As
Integer

Private Sub CloseAnApplicationByFormTitle(ByVal FormTitle As String)
Dim hwnd As IntPtr = FindWindowByTitle(FormTitle)
If IntPtr.Zero.Equals(hwnd) Then
Return
Else
CloseWindow(hwnd)
End If
End Sub

Public Function FindWindowByTitle(ByVal lpWindowName As String, Optional
ByVal lpClassName As String = vbNullString) As IntPtr
Try
Dim ptr As IntPtr = IntPtr.Zero
ptr = FindWindow(lpClassName, lpWindowName)
Return ptr
Catch ex As Exception
Return IntPtr.Zero
End Try
End Function

Public Sub CloseWindow(ByVal hwnd As IntPtr)
SendMessage(hwnd, WindowsMessage.WM_CLOSE, 0, 0)
End Sub

VB6 code:
------------

Dim pi As RemoteCETypeLibrary.PROCESS_INFORMATION
Dim FullPathToApp as String
FullPathToApp = "\Program Files\AppFolder\MyApp.exe"
CeCreateProcess(FullPathToApp, "", vbNullString, vbNullString, 0, 0,
vbNullString, vbNullString, vbNullString, pi)

In my VB6 app I used the VBRAPI type library from
http://www.unsupportedsoftware.com/ce/dev/vbrapi.htm. If you declare your
own API declaration for CeCreateProcess then you will probably define the
parameters as Long (not Any) and hence will need to change vbNullString to 0
and pi to 0 in the call to CeCreateProcess.

Hope you find this useful,

Darren.
 

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