PDA

View Full Version : copied exe-file is not a valid application


xgadkob
29th April 2003, 12:54 PM
Hi,

I have written a litte application (eMbedded Visual C++) for Pocket PC 2002
to copy an exe-file from the root-directory to the startmenu-directory.

It seems to work fine, but when I start the copied application (the exe-file) I get the message

"... is not a valid Pocket PC application"

What is wrong with this applcation?

Or does anyone know how to call Copy from an Pocket PC application directly?

Here is the code:

// Setup.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

#define SOURCEFILE_NAME "\\banking.exe"
#define DESTINATIONFILE_NAME "\\Windows\\Start Menu\\banking.exe"
#define DESTINATIONFILE_NAME_GERMAN "\\Windows\\Startmenü\\banking.exe"

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.

BOOL german = FALSE;

FILE *file = 0;
FILE *rfile = 0;

rfile = fopen (SOURCEFILE_NAME, "rb");

if (!rfile)
{
MessageBox (0, TEXT("Error"), TEXT("Setup"), MB_TOPMOST);
return 1;
}

file = fopen (DESTINATIONFILE_NAME_GERMAN, "wb");
if (!file)
file = fopen (DESTINATIONFILE_NAME, "wb");
else
german = TRUE;

if (file)
{
char buffer [1000];
size_t num_read = 0;
size_t num_written = 0;
size_t num_read_tot = 0;
size_t num_written_tot = 0;

do
{
num_read = fread (buffer, sizeof (char), 1000, rfile);

if (feof(rfile))
break;

num_read_tot += num_read;
if (num_read > 0)
{
num_written= fwrite (buffer, sizeof (char), num_read, file);
num_written_tot += num_written;
}
else
break;

} while (1);



fclose (file);
}

fclose (rfile);

DWORD attr = 0;
BOOL rc = 0;
attr = GetFileAttributes (TEXT(SOURCEFILE_NAME));

if (german)
rc = SetFileAttributes (TEXT(DESTINATIONFILE_NAME_GERMAN), attr);
else
rc = SetFileAttributes (TEXT(DESTINATIONFILE_NAME), attr);



MessageBox (0, TEXT("Ready"), TEXT("Setup"), MB_TOPMOST);
return 0;
}
// END

gabitzigu
29th April 2003, 04:07 PM
Hello,

You are trying to reinvent the wheel by copying yourself the info from the file. Use the CopyFile function.
But your error "... is not a valid Pocket PC application" has probably appeared for another reason...

tyfy
29th April 2003, 04:54 PM
You should also look at SHFileOperation

JohnSmith
29th April 2003, 09:01 PM
It's not a good idea to copy *.exe files to start menu...

Create a shortcut with CECreateShortcut(...) instead.

If this is part of a application setup (in a cab file) just create the shortcut with the build in features:

...
[DefaultInstall]
...
CEShortcuts = Shortcuts
...
[Shortcuts]
BankingMenuText,0,banking.exe
...

John

xgadkob
30th April 2003, 10:25 AM
John,

thank you for your comment.

Perhaps you ore someone else can tell me how to create a shortcut (for the banking.exe) from a Pocket PC - application ?

(The background is as follows:
I want to deliver my banking-application on SD-Card;
a little setup-application on the SD-Card copies the banking.exe from SD-Card into the program-directory of the Pocket PC.
And last but not least this setup-application shoult insert a shortcut for the copied banking.exe in the Start Menu.

xgadkob
30th April 2003, 02:38 PM
OK,

cabwiz.exe does exactly the job.

One open question:

How can I achieve, that after executing the cab-file is N O T deleted?

gabitzigu
1st May 2003, 12:41 PM
Create Shortcut with SHCreateShortcut.

Not deleting cab file : mark it as read-only on the desktop (before copying) 8)