Log in

View Full Version : Relocate .NET Compact Framework 2.0 to your storage card: free up 5.4 MBytes memory!!


Menneisyys
04-26-2006, 03:22 PM
One of the biggest complaints with Microsoft's Compact Framework 2 (CF2 for short) (and, consequently, with programs relying on it - Hitchhiker (http://www.kasuei.com/Hitchhiker/), SMS Notifier (http://www.pocketpcmag.com/blogs/index.php?blog=3&title=title_26&more=1&c=1&tb=1&pb=1), Webby (http://www.pocketpcmag.com/blogs/index.php?blog=3&p=652&more=1&c=1&tb=1&pb=1), IBE Mail (http://www.pocketpcmag.com/blogs/index.php?blog=3&p=629&more=1&c=1&tb=1&pb=1) etc.) has always been its storage needs, which, by default, is some 5.4 Mbytes. See for example this thread (http://www.pocketpcthoughts.com/forums/viewtopic.php?t=47339) for users' opinions on the memory consumption on CF2 and their subsequent not wanting to install it.

I've always tried to reduce the main memory load on Pocket PC - with great success. Just search for the word-start "relocat" in the Pocket PC Magazine Expert Blog (http://www.pocketpcmag.com/blogs) and on my old homepage (http://www.winmobiletech.com/) for some examples of them. No wonder I've also decided to look into this, so far, unsolved problem to greatly help my fellow Pocket PC users. And, after a day's work and testing, I can present you a 100% working solution, which has been thoroughly tested on four of my WM2003+ PDA's, all with success. This IS a big thing, considering that internal memory is still precious, even with most Windows Mobile 5 (WM5) Pocket PC's. (For example, most WM5 PPC's are shipped with 128M of ROM, of which in general 40-45 Mbytes is free.) The situation is even worse with pre-WM5 Pocket PC's, where the available RAM is very rarely (only with devices shipped with 128 Mbytes of RAM) over 50 Mbytes, from which CF2 takes away 5.4 Mbytes.

Note that this will work on all Pocket PC and Pocket PC Phone Edition devices that are able to run CF2 (that is, all WM2003+ devices, including WM5).

The complete tutorial

* create a directory on your storage card or, if you have, in the built-in File Store. (Note that the files, as they are surely not needed at boot time (unlike some Today plug-in DLL's), may also be relocated to a storage card. That is, they don't need to be stored in the more scarce File Store - if it's available at all; that is, if you have a pre-WM5 device). Let's assume you give this directory the name "DLLs".

* move the following files from \Windows to this directory:

cgacutil.exe
MSCOREE2_0.dll
netcfagl2_0.dll
netcfd3dm2_0.dll
GAC_CustomMarshalers_v2_0_0_0_cneutral_1.dll
GAC_Microsoft.VisualBasic_v8_0_0_0_cneutral_1.dll
GAC_Microsoft.WindowsCE.Forms_v2_0_0_0_cneutral_1.dll
GAC_Microsoft.WindowsMobile.DirectX_v2_0_0_0_cneutral_1.dll
GAC_mscorlib_v2_0_0_0_cneutral_1.dll
GAC_System.Data_v2_0_0_0_cneutral_1.dll
GAC_System.Drawing_v2_0_0_0_cneutral_1.dll
GAC_System.Messaging_v2_0_0_0_cneutral_1.dll
GAC_System.Net.IrDA_v2_0_0_0_cneutral_1.dll
GAC_System.Web.Services_v2_0_0_0_cneutral_1.dll
GAC_System.Windows.Forms.DataGrid_v2_0_0_0_cneutral_1.dll
GAC_System.Windows.Forms_v2_0_0_0_cneutral_1.dll
GAC_System.Xml_v2_0_0_0_cneutral_1.dll
GAC_System_v2_0_0_0_cneutral_1.dll

(netcf2_0license.txt can also be copied here - or just deleted.)

This means only Microsoft .NET CF 2.0.GAC and mscoree.dll needs to stay in \Windows. Never ever try to touch the former (Microsoft .NET CF 2.0.GAC). Even if you copy it back to \Windows (after starting any CF2-dependent app), CF2 won't work again until you reinstall it.

Copying the files can be done in several ways, of which I show the one way that requires no third-party apps, that is, without having to resort to, for example, the WindowsCE File System plug-in of the desktop-based Total Commander (http://pocketpcmag.com/forum/topic.asp?TOPIC_ID=15577).

Start the built-in (Pocket) File Explorer and navigate to \Windows. Tap and hold an empty (not highlighting any file or directory) region anywhere (for example, the end of the list) and enable "View All files" in the context menu:

http://www.winmobiletech.com/042006RelocateCF2/PFEShowAllFiles.bmp.png

Now, click the "Name" drop-down menu in the upper right corner; a "Sort By" list will be displayed, defaulting to "Name". Switch it to "Date":

http://www.winmobiletech.com/042006RelocateCF2/PFERelocateDateSort.bmp.png

Scroll to the region with filedates of Aug 26 and, with cgacutil.exe, 27, 2005 (this is the easiest way to find the files) and mass-highlight all files that are listed in the above list. Note that mscoree.dll should not be highlighted (as has been pointed out, it should be left in \Windows). Also note that the filedates of the current, 2.0 version of CF2 are all dated at Aug 26/27 last year. They will only have a different filedate if you've restored them from a backup. Then, they will have the timestamp of the restoration and you'll may end up having to hunting for them one-by-one, based on their name.

http://www.winmobiletech.com/042006RelocateCF2/PFERelocate-1.bmp.png

Now tap-and-hold the selection somewhere so that the context menu comes up. Choose Cut:

http://www.winmobiletech.com/042006RelocateCF2/PFERelocate-2.bmp.png

Go to the target directory (in this case, DLLs on your storage card); tap-and-hold an empty area and choose Paste:

http://www.winmobiletech.com/042006RelocateCF2/PFERelocate-3.bmp.png

The transfer of the files will start:

http://www.winmobiletech.com/042006RelocateCF2/PFERelocate-4.bmp.png

Note that you can also use other file handler tools on the Pocket PC; for example Resco File Explorer or Total Commander. In Resco, go to File/Options/Browser and make sure "Show all files" is chosen (instead of the default "Hide hidden files and files...") as can be seen in this screenshot (http://www.winmobiletech.com/042006RelocateCF2/RescoShowAllFiles.bmp.png).

* get a registry editor that is able to (flawlessly (!)) edit multiline strings (that is, all known, up-to-date registry editors except PHM Registry Editor and Total Commander; please check out The Ultimate Roundup of Registry Editors for the Pocket PC (http://www.pocketpcmag.com/blogs/menneisyys/UltimateRoundupOfRegistryEditors.asp) for a thorough explanation of why I don't recommend these two applications if interested). In this tutorial, I use Resco Registry Editor (Resco for short). It's commercial, but the 14-day, unrestricted trial version is fully sufficient for our purposes. Start it.

* First, we'll modify the so-called "System Path" (which is a bit similar to the PATH in traditional operating systems) so that it includes our new directory. To do this, go to HKEY_LOCAL_MACHINE\Loader:

http://www.winmobiletech.com/042006RelocateCF2/PFERelocate-5.bmp.png

Note that, in here, I've switched to "Tree Mode" in View/Show Tree View as can be seen in here (http://www.winmobiletech.com/042006RelocateCF2/RescoEdShowTree.bmp.png).

Now, click SystemPath (highlighted in this screenshot (http://www.winmobiletech.com/042006RelocateCF2/RescoEdLoaderRewrite-1.bmp.png)); you'll be presented the following dialog:

http://www.winmobiletech.com/042006RelocateCF2/RescoEdLoaderRewrite-2.bmp.png

Note that there may be some values already in the text input area in here. For example, if you've ever had SKTools or MemMaid relocate DLL's for you, the target directory will be in here. Also, by default (if you haven't ever touched the System Path), there may be a \Release\ or \windows\oem\ in here. These can be safely deleted as they're not used. You can, naturally, leave them in there; of course, then, you must make sure the new path is entered in a new row as can be seen in this x51v (http://www.winmobiletech.com/042006RelocateCF2/LeavingReleaseInx51v.bmp.png) or this HTC Wizard (latest Qtek ROM) (http://www.winmobiletech.com/042006RelocateCF2/LeavingOemInx51v.bmp.png) screenshot. Once again: you can safely delete them.

All you have to do is entering the full path of your new DLL directory in here. For example, if you've moved the CF2 files to a directory named DLLs on your storage card named CF-Card (Storage Card, CF Card, SD Card, SD-MMCard are also widely used), enter

\CF-Card\DLLs\

in here, as can also be seen in here:

http://www.winmobiletech.com/042006RelocateCF2/RescoEdLoaderRewrite-3.bmp.png

Don't forget to add the leading and the trailing backslash characters (\)!

Now, click OK in the upper right corner and answer Yes:

http://www.winmobiletech.com/042006RelocateCF2/RescoEdLoaderRewrite-4.bmp.png

In the list view, the new, just-entered value should be shown as can be seen in here:

http://www.winmobiletech.com/042006RelocateCF2/RescoEdLoaderRewrite-5.bmp.png

Note that, again, if you want to keep the previous values of System Path, then, the new entry should be put in a separate row. For example, if the previous value of HKEY_LOCAL_MACHINE\Loader has been

\SD-MMCard\Programs\CrEme\bin\
\LOOXstore\DLLs\

then, you need to add the new value in a new row as can be seen in here:

http://www.winmobiletech.com/042006RelocateCF2/RescoEdLoaderRewrite-6.bmp.png

* now comes a bit more complicated part. First, go to HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ .NETCompactFramework\ Installer\ Assemblies\ Global.

Note that, on some devices, in the above path, SOFTWARE may not (all) be uppercase. This varies from model to model and shouldn't be paid attention to. (Also note that I’ve added spaces after every backslash characters (\) in the above registry path so that the blog engine nicely renders it. In the reality, it should not contain any spaces!)

Here, look for names (on the left) that have 2.0 in them. Note that almost all values (except for CustomMarshalers, Microsoft.WindowsMobile.DirectX and Microsoft.WindowsMobile.DirectX, which have all been introduced in CF2 and didn't exist in CF 1.x) seem to be duplicated and their name will start with the same (Microsoft.*, mscorlib.*, System* etc.); it's only after this that they start to be different. One set of them will continue in Version=1.0, the other set will continue in Version=2.0. The only exception from this "must contain Version=2.0" law is the value starting with "Microsoft.VisualBasic, Version=8.0.0.0" (that is, 8.0 instead of 2.0).

In all these Version=2.0 values, you'll need to modify the original path referring to \Windows to the new home of the relocated files - for example, in our case, \CF-Card\DLLs.

In order to be able to see this as easily as possible, enabling Show Header in the View menu is highly recommended, as can be seen in here (http://www.winmobiletech.com/042006RelocateCF2/CF2ShowHeaderToExpandTheSize.bmp.png). Then, you'll be able to greatly increase the displayed length of the value names if you drag the header to the right. Of course, switching to Landscape and/or VGA mode (if possible) is highly recommended. Then, you'll be able to see the version number in all the values. For example, this screenshot (http://www.winmobiletech.com/042006RelocateCF2/CF2LSQVGA.bmp.png) shows a QVGA WM5 device in Landscape - here, it's also possible to increase the width of the "Name" column so that the version number can also be seen without having to click every value.

All you need to do is just click all the values that have Version=2.0 in their name (except, as has already been pointed out, the 8.0 Microsoft.VisualBasic) and just change \Windows to the new value in the first row. An example of this:

before:

http://www.winmobiletech.com/042006RelocateCF2/CF2Relocation-ValueChange-1.bmp.png

after:

http://www.winmobiletech.com/042006RelocateCF2/CF2Relocation-ValueChange-2.bmp.png

Another example of a changed value (WM5, QVGA device, with files relocated to \Storage Card\_):

http://www.winmobiletech.com/042006RelocateCF2/CF2Relocation-ValueChange-QVGA.bmp.png

and with the VGA x51v in standard VGA mode:

http://www.winmobiletech.com/042006RelocateCF2/CF2Relocation-ValueChange-x51v.bmp.png

Note that, much as it refers to the main storage (\Program Files\.NET CF 2.0\), you don't need to pay attention to the second row in all these values. Just leave them there.

Consider using a PC-based Pocket PC controller tool to do this (please read this article (http://www.pocketpcmag.com/blogs/index.php?blog=3&p=514&more=1&c=1&tb=1&pb=1) for more info on them if not sure). Using them, you can speed up the registry modification by orders of magnitude, particularly if you use copy/paste to insert the new directory path.

After you've modified all the affected values, check once more if it was successful. Fortunately, you'll see all the names (showing that a given value is 2.0-specific) and values (showing whether it refers to the original \Windows directory in the main storage or somewhere else) on the same screen as in this screenshot (http://www.winmobiletech.com/042006RelocateCF2/CF2Relocation-ValueChange-AllChanged.bmp.png).

You may also want to export the just-modified branch to a registry (.reg) file. Then, in case you reinstall CF2 and want to avoid hand-editing the entire stuff, you'll only need to reimport this file. To do this, tap-and-hold Globals in the upper, tree pane and choose Export:

http://www.winmobiletech.com/042006RelocateCF2/CF2Relocation-ExportBranch.bmp.png

On WM5 devices, you will also want to make sure the changes are flushed back to the ROM (as the Registry is kept in RAM and changes are rarely flushed back to ROM, which will result in a simple soft reset getting rid of all changes and, therefore, CF2 not working after the relocation). To do this, on many WM5 devices (like the HTC Wizard), just long-press the Power button. On some other devices, you must explicitly configure the device to shut the PDA completely down upon a long-press (instead of just dimming the screen). For example, on the x51v, you must go to Settings/System/Power/Power Button and enable "Full power off" instead of the default "Dim/light the display" as can be seen in this screenshot (http://www.winmobiletech.com/042006RelocateCF2/FullPowerOff51v.bmp.png). You'll only need to power off your PDA for some seconds because it's before shutting it down that the Registry is flushed back to the ROM; that is, you can safely switch it back on instantly.

Congratulations! Now, the relocated CF2 will be working! If you've modified the System Path, you'll need to reboot; otherwise, you can start your CF2 apps right away.

Advanced remarks for geeks/advanced hackers

* Exporting, editing and re-importing the contents of HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ .NETCompactFramework\ Installer\ Assemblies\ Global (so that you can much easier change all occurrences of \Windows to the new path) just won't work because the values in here are multiline strings, which are exported as hexadecimal values by all export-capable Pocket PC-based registry editors (I've checked this!) like in here:

http://www.winmobiletech.com/042006RelocateCF2/MultiLineExport.png

* The \Windows paths in HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ .NETCompactFramework\ Installer\ Assemblies\ Reference (note that the last word is Reference, not Global!) don't need to be modified. Actually, you can even get rid of the entire subkey because it's not used at all.

* Technically, the GAC*.dll files don't need to be in the System Path; it's only with the other files (cgacutil.exe, MSCOREE2_0.dll, netcfagl2_0.dll and netcfd3dm2_0.dll) that must be. That if, you have already set up a relocated DLL directory somewhere in the System Path, you can safely move the files to there. It's in order to be as easy as possible for a novice user that I've instructed copying all relocated files to the same directory in the System Path.

isajoo
04-26-2006, 05:33 PM
seem like a lot of trouble!
maybe i missed something :roll: or TOO MUCH reading :lol:

how long do it take?

Will it affect the performence of CF.net 2.0 apps?

total saving of memory is?

affects of removing the CF/SD card if unit is on/off/turn on?

Menneisyys
04-26-2006, 08:37 PM
seem like a lot of trouble!
maybe i missed something :roll: or TOO MUCH reading :lol:

Well, a lot of reading, but it's just because I wanted to be absolutely clear that it's THAT long :) It's actually very easy - a lot of other people have already reported success (over at AximSite, FirstLoox and in my blog).

how long do it take?

5-10 minutes.

Will it affect the performence of CF.net 2.0 apps?

Some startup slowness may be experienced - but it's not that bad, given that CF itself is slooooow, unlike native apps.

total saving of memory is?

5.4 Mbytes. Pretty much - particularly on 64/128M ROM WM5 and/or 32/64M RAM pre-WM5 devices. Definitely worth the hack.

affects of removing the CF/SD card if unit is on/off/turn on?

Your CF2 apps just won't start. That is, no hard resets and stuff.

isajoo
04-27-2006, 04:12 AM
cool, good to know that others have had success and that it will save my Precious Memory... NEED EVERY DROP.

thanks for the follow up, will give a good read and try tonight. although I only use it for Hitchhikers (even it uses LOTS of Memory to RUN) WPA keys or whatever its called instead of WEP for logging onto other freinds wireless routers. They dont believe in FREE sharing without permission. I do.

isajoo
04-27-2006, 05:50 AM
well...

:cry:
IT was not the 5-10 mins that u said,(not your fault) As u can see from the time i last posted.

BUT IT WORKED. After MANY ERRORS

I put it in the CF Card/DLLs

I could not figure out the space in between CF and Card.

Was going by your pics and not really reading too much. (dont enjoy reading :oops: )

THANKS, SAVED ME 5.09 MB :!:

BUT hitchhiker still gussales the memory almost 8-10 MB...is this normal?

isajoo
04-27-2006, 05:56 AM
funny thing...
I thought i still have the same memory as before i did this hack....

but remembered that earlier today put around 5-6 megs on the main memory. :lol:

Menneisyys
04-27-2006, 09:51 AM
well...

:cry:
IT was not the 5-10 mins that u said,(not your fault) As u can see from the time i last posted.

BUT IT WORKED. After MANY ERRORS

I put it in the CF Card/DLLs

I could not figure out the space in between CF and Card.

Was going by your pics and not really reading too much. (dont enjoy reading :oops: )

THANKS, SAVED ME 5.09 MB :!:

BUT hitchhiker still gussales the memory almost 8-10 MB...is this normal?

Glad it worked for you too - it was certainly worth dedicating some 10-12 hours for implementing, testing and documenting the hack :)