The CERunApp application can be downloaded from:
The CERunApp source code can be downloaded from:
In
Windows CE: Using RAPI to Run Applications (Part 1) and
Windows CE: Using RAPI to Run Applications (Part 2) I wrote about using RAPI remotely start applications on a Windows CE device from a workstation. In
Windows CE: Using RAPI to Run Applications (Part 2) I presented an application,
CERunApp.exe, that downloads an application from the workstation to the Windows CE device and then starts the application. A reader responded to that article by asking about running an MP3 file using the
CERunApp.exe. I responded that the
CERunApp.exe starts applications, not MP3 files. This article will correct that by extending the
CERunApp.exe to download a file and run a resident application on the Windows CE device with the name of the file as a command line argument.
I am not going to go into great detail about the changes to CERunApp, but to get started, I added a tab control so that the app can have two ways of being used. The original application is in the first tab, labeled Application. It looks like:
Not much of a change to this part of the application, but the new tab labeled Parameter adds the new functionality. This new tab looks like:
In this new tab there are:
· A drop down list of EXE files in the \Windows folder on the Windows CE device
This list is populated when the user clicks on the Parameter tab from the Application tab.
· A text box to enter command line parameters
· A browse button to select a file to be downloaded and include in the command line
When the user clicks on the Run Application button, the file is downloaded, then the application is started with the command line with the file name added to it.
Since I covered most of the RAPI code in the previous articles, I am going to focus on the changes that I made. The fist change was to add code to get the list of EXE files in the \Windows folder. This was done using CeFindFirstFile(), CeFindNextFile(), and CeFindClose(). These functions work much like their counterparts that would be used on the device itself. To use these, I added FindFirstFile(), FindNextFile() and FindClose() the the CRapi class as follows.
public System.IntPtr FindFirstFile(string FolderName, ref string FileName)
{
System.IntPtr ReturnValue = System.IntPtr.Zero;
CE_FIND_DATA FindData = new CE_FIND_DATA();
if (IsConnected())
{
ReturnValue = CeFindFirstFile(FolderName, ref FindData);
if (ReturnValue != System.IntPtr.Zero)
{
FileName = FindData.cFileName;
}
}
return ReturnValue;
}
public bool FindNextFile(System.IntPtr hFind, ref string FileName)
{
bool ReturnValue = false;
CE_FIND_DATA FindData = new CE_FIND_DATA();
if (IsConnected() && hFind != System.IntPtr.Zero)
{
ReturnValue = CeFindNextFile(hFind, ref FindData);
if (ReturnValue != false)
{
FileName = FindData.cFileName;
}
}
return ReturnValue;
}
public bool FindClose(System.IntPtr hFind)
{
bool ReturnValue = false;
if (IsConnected() && hFind != System.IntPtr.Zero)
ReturnValue = CeFindClose(hFind);
return ReturnValue;
}
If your read the previous article closely, you would have noticed that at that time I chose to make the connection and end the connecting in the functions as they were called. Using 20/20 hindsight I have change this so that the connection is made when the CRapi class is instantiated and closed with a call to Disconnect() which I added to CRapi. Disconnect() is also closed when the CRapi is destructor is called, but of course that is up to the garbage collector. I recommend closing when finished rather than letting the destructor do it. This change was clearly necessary when using the find file functions.
The code that handles the click on the Parameter tab looks like:
private void FileCopyTab_Click(object sender, EventArgs e)
{
CRapi RAPI = new CRapi();
String FoundFile = "No Files Found";
System.IntPtr hFind;
string[] FileNames;
uint Index = 0;
uint LoopCount = 0;
Cursor.Current = Cursors.WaitCursor;
FileAppName.Items.Clear();
do
{
FileNames = new string[Index];
Index = 0;
hFind = RAPI.FindFirstFile("\\Windows\\*.exe", ref FoundFile);
if (hFind != System.IntPtr.Zero)
{
do
{
if (LoopCount > 0)
FileNames[Index] = FoundFile;
Index++;
} while (RAPI.FindNextFile(hFind, ref FoundFile));
RAPI.FindClose(hFind);
}
else
{
if( LoopCount > 0 )
FileNames[Index] = FoundFile;
Index++;
}
}
while (LoopCount++ < 1);
CaseInsensitiveComparer Comparer = CaseInsensitiveComparer.Default;
Array.Sort(FileNames, Comparer);
LoopCount = Index;
for (Index = 0; Index < LoopCount; Index++)
{
FileAppName.Items.Add(FileNames[Index]);
}
RAPI.Disconnect();
Cursor.Current = Cursors.Default;
}
This code finds the EXE files in the \Windows folder, then sorts them alphabetically.
The rest uses code similar to or included in the original application.
Copyright © 2009 – Bruce Eitman
All Rights Reserved