Mobile Apps - WinCE 6 filesystem and access

Asked By WinCEMcJon
19-Jan-10 12:47 PM
I am new to WinCE programming but am experienced in C++ and C# programming.

I wrote a simple C# app to load a bitmap and display it in a pictureframe.

So my code is:
Bitmap myImage=new Bitmap("myfile.bmp")

This works fine in C# on an Win7 platform and loads the file in the current
directory.  Running in /Release works fine.

However, I compiled the application then copied it to an SD card which
appears as "Storage Card" in my WinCE machine.  I doubleclick on "Storage
Card" and run my application from a folder.  It works fine but it cannot load
the myfile.bmp file which is also located in the same directory.

However, if I copy the .bmp file to \ on my WinCE device, it works great.

How do I load a file in the local directory under WinCE?

I am having the same problem with loading applications at startup.  I can
edit the project.bib and project.dat files to run an application but only if
I build it into my image.

If I run "\\Storage Card\\Startup\\myexe.exe" then it will not load.  But it
works fine if I load the application by doubleclicking on it from WinCE
explorer and also works fine if I build it into the image.

What am I doing wrong?
WinCE
(1)
Path.GetDirectoryName
(1)
Windows 7
(1)
EMVP
(1)
FileAvailableNow
(1)
FullAppPath
(1)
BruceEitman
(1)
GetName
(1)
  Paul G. Tobey [eMVP] replied to WinCEMcJon
19-Jan-10 01:40 PM
The answer is going to be a bit long, but you are better off understanding
why, rather than just what.

Windows CE has no such thing as a current directory.  On the desktop, there
is a current directory and, if you specify no path on a filename, that is the
folder where the system looks for files first.  Since there is no such thing
in Windows CE, you should specify a full path for any file specification.
That is, if you know that a file is on the storage card, use:

\Storage Card\myfile.extension

NOT

myfile.extension

If you want to use the folder where the EXE that is running is installed, get
that folder, in managed code by doing the following:

string appName_s=Assembly.GetExecutingAssembly() .GetName() .CodeBase;
string fullAppPath_s = Path.GetDirectoryName(appName_s);

and prepend the path to the name of the file you want to load.

Paul T.
  Paul G. Tobey [eMVP] replied to Paul G. Tobey [eMVP]
19-Jan-10 06:37 PM
Didn't finish that message before the send button found my finger...


Think about how this works.  When you boot the device, is the storage card
there, instantly?  No.  When the system starts, everything starts happening.
The basic filesystem is loaded and the drivers start getting loaded for
built-in and connected devices (your storage card falls into this category).
In parallel, the filesystem driver/application is starting to run the Startup
folder contents. So, you have a race.  If the driver for whatever bus your
storage card is connected to (PCMCIA, USB, SD, etc.), gets loaded, and if the
driver for the card itself then gets loaded (USB mass storage, PCMCIA ATA,
etc.), and then the partition driver for the card gets loaded, and then the
driver for the filesystem on the card gets loaded (FAT), all before the
Startup folder item to start your application gets processed, then your
application will be started.  However, if not, it will not because there is no
storage card in the filesystem of the device.

So, you might build in a startup program that will run on startup and wait
for the storage card to mount.  Once it does, it could enumerate all of the
entries in a startup folder on the card and run them.  This is a pretty
common sort of utility to build into a device.

Alternatively, you could force the storage card to be mounted before
allowing boot to continue.  Of course, if you happen not to install a storage
card, the device may never boot, which would be bad.

You're not going anything wrong; you are just expecting Windows CE to work
like desktop Windows and have all devices that are connected when the
computer powers on mounted by the time Windows starts.  Not the case with
CE...

Paul T.
  WinCEMcJon replied to Paul G. Tobey [eMVP]
20-Jan-10 01:15 PM
Paul: Thank you for the answers.  It was extremely helpful!

I am positive I can fix my .bmp load problem but the load problem from SD I am
not so sure yet and would appreciate some insight.

I made a helper function like this
http://geekswithblogs.net/BruceEitman/archive/2008/06/30/windows-ce-starting-an-application-when-the-system-boots.aspx

which is called by HKEY_LOCAL_MACHINE\Init

My understanding is that the load order is dictated by DependXX.  So "
Depend60"=hex:14,00, 1e,00 " waits for two other apps.

Is there a driver/application that is loaded that guarantees the SD card is
available?  I would think I could search through the BSP driver libraries to
look for the SD card code but I am not so sure I can find it.

That is my first plan.

If there is no guarantee using the init key then I can modify the code to
look for the storage card.

So my pseudo code would be something like:
while (timer < timout)
{
int fid=fopen("\\Storage Card\\myExe.exe","r");
if (fid>0)
{
fclose(fid);
fileAvailableNow();
}
timer+=1;
sleep(100);
}

But then I thought that this must be a common problem and code I write will
always be suboptimal to experts like you.  One problem is that this code
blocks so if threads are not running continously in the background then this
will not work as the SD driver will never be loaded.

Is there a function or example in the Win32/WinCE Api that does this already?
  Paul G. Tobey [eMVP] replied to WinCEMcJon
21-Jan-10 11:39 AM
Yes, it waits for #20 and #30 to be loaded and to call SignalStarted before
your #60 application will run.


You are that application!  You could do that several ways, but the cleanest
is to RequestDeviceNotifications() for mounting of drives and, when each
mount event is sent to you, see if it is the one you want.  When that one
appears, do your thing.  Note that, in RequestDeviceNotifications(), you want
to request notifications for all devices, in case the card does happen to get
mounted before your application runs.


Yes, you can do this, too.  Nothing wrong with it (although 100ms delay is
pretty short). It uses a few more cycles than RequestDeviceNotifications() is
all.


You lost me here.  Windows CE is a preemptive multitasking operating system.
Assuming that there is not a higher-priority thread ready-to-run, your thread
will always get some time. The SD card driver almost certainly has its
threads running mostly at a higher priority, so it will not fail to boot because
of you.

Paul T.
help
WinCE or Windows Mobile - Virtual Printer support Mobile Apps Is WinCE oe Windows Mobile have support for Virtual Printer, using that we can save the content to be PDF or other format instead of really prnting in the paper. WindowsCE Platform Builder Discussions WinCE (1) Windows Embedded (1) WindowsEmbeddedCookbook (1) EMVP (1) Windowsembeddedit (1) AFAIK windows CE does not support virtual printer. - - vinoth.R http: / / vinoth-vinothblog.blogspot.com http: / / www third parties already provide such a product. - - Valter Minute (eMVP) Training, support and development for Windows CE: www.fortechembeddedlabs.it My embedded programming and cooking blog: www.geekswithblogs.net / WindowsEmbeddedCookbook Windows
The Spectacular Failure of WinCE and Windows Mobile Mobile Apps The Spectacular Failure of WinCE and Windows Mobile http: / / www.roughlydrafted.com / RD / RDM.Tech.Q1.07 / 50755EA6-A759-42FD-84ED-EBB5A060AF16.html Windows Mobile, Palm OS, Linux, and Symbian currently power the world's smartphones. How does each overview looking at the merits of each, starting with a historical perspecive of Microsoft's WinCE. PocketPC Discussions WinCE (1) IPhone (1) OS (1) XP (1) DanielEran (1) MS (1) Vista (1) WinMo (1 danieleran@gmail.com> What a load of rubbish. To start with: The xbox was not wince, just the dreamcast. The XBox was based on a stripped down windows 2000. Please at
Transfer contacts from windows mobile to windows phone 7 Mobile Apps How to transfer contacts from windows mobile to windows phone 7? http: / / www.imobiletool.com / how-to-transfer-contacts-from-windows-mobile-to-windows-phone-7-device.html Many windows mobile phone users do not know how to contacts from windows mobile to windows phone 7 when they get the new winodws phone 7 device. This
WinCE or Windows Mobile - Virtual Printer support Mobile Apps Is WinCE oe Windows Mobile have support for Virtual Printer, using that we can save the content to be PDF or other format instead of really prnting in the paper. WindowsCE App Development Discussions WinCE (1) Windows (1) Nothing like that comes from Microsoft, no. Some specific devices may have the capability. Paul T. keywords: WinCE, or, Windows, Mobile, -, Virtual, Printer, support description: Is WinCE oe Windows Mobile have support for Virtual Printer