MobiReg 1.01
I saw video at YouTube and I found one unfortunate typo. My 1.00 version of MobiReg claimed to be beta 2. To solve this issue, I present you 1.01.
My program was failing with MissingMethodException (Method not found: ‘Void System.Windows.Forms.FileDialog.set_AutoUpgradeEnabled(Boolean)’). This happened only on Windows XP and not all of them.
Culprit was obvious. I used OpenFileDialog and I decided to set AutoUpgradeEnabled property. Only problem was that this property was introduced with .NET Framework 2.0 SP1. Notice this service pack part - that property does not exist if you have version without it.
Solution is easy if you are trying setting this property to true - that is default value anyhow. If you want to set it to false, just use reflection:
var property = typeof(FileDialog).GetProperty("AutoUpgradeEnabled");
if (property != null) {
property.SetValue(openFileDialog1, false, null);
}
Notice that this property is shared among other controls inheriting from FileDialog (e.g. SaveFileDialog) so same thing applies to them also.
I saw video at YouTube and I found one unfortunate typo. My 1.00 version of MobiReg claimed to be beta 2. To solve this issue, I present you 1.01.
Most of Win32 functions are user friendly. Not as user friendly as .NET framework, but once you see specification, everything is clear. There is no problem translating it to P/Interop call.
But there is one issue that may be problematic - unions. They are used in C++ programs in order to force multiple variables to use same memory space. We will use INPUT structure as example here:
typedef struct tagINPUT {
DWORD type;
union {
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
} INPUT, *PINPUT;
typedef struct tagMOUSEINPUT {
LONG dx;
LONG dy;
DWORD mouseData;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} MOUSEINPUT, *PMOUSEINPUT;
typedef struct tagKEYBDINPUT {
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT;
typedef struct tagHARDWAREINPUT {
DWORD uMsg;
WORD wParamL;
WORD wParamH;
} HARDWAREINPUT, *PHARDWAREINPUT;
Although this code is little bit messy, it should be mostly clear to C# developer:
public struct MOUSEINPUT {
public Int32 dx;
public Int32 dy;
public Int32 mouseData;
public Int32 dwFlags;
public Int32 time;
public UInt32 dwExtraInfo;
}
public struct KEYBDINPUT {
public Int16 wVk;
public Int16 wScan;
public Int32 dwFlags;
public Int32 time;
public UInt32 dwExtraInfo;
}
public struct HARDWAREINPUT {
public Int32 uMsg;
public Int16 wParamL;
public Int16 wParamH;
}
While this conversion is clear, what is not so clear is what to do with tagINPUT. Solution in C# could look like this:
public struct tagHARDWAREINPUT {
[FieldOffset(0)]
public MOUSEINPUT mi;
[FieldOffset(0)]
public KEYBDINPUT ki;
[FieldOffset(0)]
public HARDWAREINPUT hi;
}
This makes all fields aligned on first byte and thus they behave identically to C++ structure union.
Today (2009-04-23) I gave lecture about virtual disk support in Windows 7.
Here are some links I promised:
If you are interested in this topic, you may wish to check this blog at later times also. I will be adding more detailed explanations of VHD API and updates to this C# implementation.
P.S. If you get “Privilege not held” exception message, run Visual Studio 2008 as administrator. VHD API requires elevated rights.
[2009-04-27: Windows 7 RC will have some changes regarding Virtual Disk API. Major ones include changing names of some functions (E.g. what was SurfaceVirtualDisk is now AttachVirtualDisk, what was UnsurfaceVirtualDisk is now DetachVirtualDisk) and structures. Once RC is out and I install it, I will release update of code.]
[2009-05-01: Code is updated.]
Final version of MobiReg is out.
This is small registry editor which supports supports creating and editing of string, binary, DWord (32-bit), QWord (64-bit), multi-string and expandable-string data types. Additionally to that, there is support for both Smartphone (Windows Mobile Classic) and Pocket PC (Windows Mobile Professional) platform in single executable.
One of features that may help you to decide whether to use it or not is support for both import and export of registry in standard .reg file.
You can download it here.
In order to run it, you may need .NET Compact Framework 2.0 or higher (if it is not already installed).