PDA

View Full Version : WM5 - Reading and Writing to Registry


GF
04-05-2006, 07:07 AM
I am looking for some help to assist in reading and writing values to the registry from a program on WM5. I am writing the program in either VB or C# using Visual Studio 2005 as that is what i have experience in.

Can anyone offer any assistance to assist me as my reseach has had me banging my head on the wall all day.

Thnx.
GF

Rudegar
04-05-2006, 10:09 AM
something like this works on a pc in C#
should be 100% the same on a pda
most .net stuff is the same apart from advanced controls
which are excluded in compact framework

string myValue;
RegistryKey pRegKey = Registry.LocalMachine;
pRegKey = pRegKey.OpenSubKey("Software\\Some Program");
Object val=null;
Object val2=null;
if(pRegKey!=null)val = pRegKey.GetValue("Some Key");
if(val==null)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("Some Key", true);
RegistryKey newkey = key.CreateSubKey("Some Value");
newkey.SetValue("Some Value", "String");
}
else myValue=val.ToString();

VZ800
04-05-2006, 10:52 AM
If you are using .NET then have a look at the OpenNETCF.Win32.Registry class available from http://www.opennetcf.org which is open source and freely available.

In my opinion .NET is too slow on the PPC. I am just getting used to writing for the PPC and WM5 but I am using eVC4 which being C++ is much faster. I am also writing a RegEdit utility as my first project. I am however a Software Engineer and am used to C++ and also C# and VB6.

GF
04-05-2006, 10:46 PM
Thnx for the help to date. I now get the above error once i have imported the code provided. The help refers to the following declaration:

[ComVisibleAttribute(true)]
public sealed class RegistryKey : MarshalByRefObject, IDisposable

But i am unsure of where to place this within the code to adequately declare the RegistryKey.

I have looked at http://www.opennetcf.org but all the code is for older versions of the VS. One would think there would be an easy solution in the world for this type of thing.

GF

VZ800
05-05-2006, 02:47 PM
Once you have built the DLL from the OpenNETCF you should then have a OpenNETCF.Win32.Registry.DLL which is a .NET DLL. Then add a reference to this DLL in your project:

Project->AddReference - click on the Browse tab and browse for the said DLL. This will then be added to your project for you to use. In the class where you need to access the classes in the DLL add a using directive for [color=blue]using[/color] OpenNETCF.Win32;

You don't need to use InterOp services as it isn't a COM DLL.

HTH

VZ800
05-05-2006, 02:51 PM
Sorry the embedding didn't work too well the code to add for a using directive is:

using OpenNETCF.Win32;

GF
08-05-2006, 04:51 AM
I have managed to get it running, i think it was a problem with using OpenNETCF.Win32.RegsitryKey, where the default VS uses is Microsoft.Win32.RegistryKey

Thnx for everyones help.

GF

Klutsh
11-05-2006, 10:12 PM
Just download the WM5 SDK for Pocket PC or SmartPhone, Registry editing is then possible using the .NET CF V2

ie:
Dim RegKey As RegistryKey = Registry.LocalMachine.CreateSubKey("System\StorageManager\FATFS")
Dim RegValue As String = RegKey.GetValue("CacheSize", Nothing)
RegKey.SetValue("ReplStoreCacheSize", GeneralSystemPerformanceCmb.Text, RegistryValueKind.DWord)

VZ800
12-05-2006, 12:10 AM
Yes of course it is possible. But .NET apps on a PPC is JUST TOOOOO SLOOOOOWWWW. In my opinion there is no chois=ce but to go with C++ until the PPC processors get much faster, which .NET expects.