The trick is using wceload.exe with the /noaskdest and /noui parameters.
Again thanks to opennetcf.org.
private bool installCabFile ()
{
try
{
ProcessInfo pi = new ProcessInfo();
if (CreateProcess ("\\Windows\\wceload.exe","/noaskdest /noui " + downloadFileName, pi))
return false;
}
catch (Exception e)
{
Cursor.Current = Cursors.Default;
MessageBox.Show ("Problem installing Cab file " + e.ToString());
return true;
}
return false;
}
// CreateProcess PInvoke API
[DllImport("CoreDll.DLL", SetLastError=true)]
private extern static int CreateProcess ( String imageName, String cmdLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, Int32 boolInheritHandles, Int32 dwCreationFlags, IntPtr lpEnvironment, IntPtr lpszCurrentDir, byte [] si, ProcessInfo pi );
// GetLastError PInvoke API
[DllImport("CoreDll.dll")]
private extern static Int32
GetLastError();
public Int32 GetPInvokeError()
{
return GetLastError();
}
[DllImport("CoreDll.dll")]
private extern static Int32
WaitForSingleObject ( IntPtr Handle, Int32 Wait);
public bool CreateProcess (String ExeName, String CmdLine, ProcessInfo pi)
{
Int32 INFINITE;
unchecked {INFINITE = (int)0xFFFFFFFF;}
bool result = false;
if (pi == null) pi = new ProcessInfo ();
byte [] si = new byte [128];
result = CreateProcess (ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi) != 0;
WaitForSingleObject (pi.hProcess,INFINITE);
return result;
}
public sealed class ProcessInfo
{
public IntPtr hProcess = IntPtr.Zero;
public IntPtr hThread = IntPtr.Zero; public int dwProcessID = 0;
public int dwThreadID = 0;
}
Enjoy!
(Compact Framework)
Ideas and thoughts about Microsoft Identity, C# development, cabbages and kings and random flotsam on the incoming tide
Showing posts with label Compact Framework. Show all posts
Showing posts with label Compact Framework. Show all posts
Monday, September 26, 2005
CF : Battery status in CF
bool success = GetSystemPowerStatusEx (ref system_power_status_ex, true);
this.lblMainInfo.Text = system_power_status_ex.BatteryLifePercent.ToString() +
"% Power Status " + (BatteryChargeStatusEnum)system_power_status_ex.BatteryFlag;
this.lblBackupInfo.Text = system_power_status_ex.BackupBatteryLifePercent.ToString() +
"% Power Status " + (BatteryChargeStatusEnum)system_power_status_ex.BatteryFlag;
where:
[DllImport("Coredll.dll")]
public static extern bool GetSystemPowerStatusEx(ref SYSTEM_POWER_STATUS_EX pstatus, bool fUpdate);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_POWER_STATUS_EX
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePercent;
public byte Reserved1;
public uint BatteryLifeTime;
public uint BatteryFullLifeTime;
public byte Reserved2;
public byte BackupBatteryFlag;
public byte BackupBatteryLifePercent;
public byte Reserved3;
public uint BackupBatteryLifeTime;
public uint BackupBatteryFullLifeTime;
}
private SYSTEM_POWER_STATUS_EX system_power_status_ex;
public enum BatteryChargeStatusEnum : byte
{
High = 1,
Low = 2,
Critical = 4,
Charging = 8,
NoSystemBattery = 128,
Unknown = 255
}
Thanks to the good folks at OpenNETCF (see "Links") for this.
Enjoy!
(Compact Framework)
this.lblMainInfo.Text = system_power_status_ex.BatteryLifePercent.ToString() +
"% Power Status " + (BatteryChargeStatusEnum)system_power_status_ex.BatteryFlag;
this.lblBackupInfo.Text = system_power_status_ex.BackupBatteryLifePercent.ToString() +
"% Power Status " + (BatteryChargeStatusEnum)system_power_status_ex.BatteryFlag;
where:
[DllImport("Coredll.dll")]
public static extern bool GetSystemPowerStatusEx(ref SYSTEM_POWER_STATUS_EX pstatus, bool fUpdate);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_POWER_STATUS_EX
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePercent;
public byte Reserved1;
public uint BatteryLifeTime;
public uint BatteryFullLifeTime;
public byte Reserved2;
public byte BackupBatteryFlag;
public byte BackupBatteryLifePercent;
public byte Reserved3;
public uint BackupBatteryLifeTime;
public uint BackupBatteryFullLifeTime;
}
private SYSTEM_POWER_STATUS_EX system_power_status_ex;
public enum BatteryChargeStatusEnum : byte
{
High = 1,
Low = 2,
Critical = 4,
Charging = 8,
NoSystemBattery = 128,
Unknown = 255
}
Thanks to the good folks at OpenNETCF (see "Links") for this.
Enjoy!
(Compact Framework)
CF : Hiding / showing the taskbar in CF
This is for Windows CE Compact Framework.
In the "onLoad" method:
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
To show:
int h = FindWindow ("HHTaskBar", "");
ShowWindow (h, SW_SHOW);
Rectangle rc = this.Bounds;
this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;
MoveWindow (hwnd, rc.Left, rc.Top, rc.Right, rc.Bottom - taskBarSize, true);
To hide:
int h = FindWindow ("HHTaskBar", "");
ShowWindow (h, SW_HIDE);
Rectangle rc = this.Bounds;
this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;
MoveWindow (hwnd, rc.Left, rc.Top, rc.Right, rc.Bottom + taskBarSize, true);
where:
private int taskBarSize = 24;
const int SW_HIDE = 0x0000;
const int SW_SHOW = 0x0001;
[DllImport("coredll")]
public static extern IntPtr GetCapture();
[DllImport("coredll.dll")]
public static extern int FindWindow (string lpClassName, string
lpWindowName);
[DllImport("coredll.dll")]
public static extern int ShowWindow (int hwnd, int nTaskShow);
[DllImport("coredll.dll")]
public static extern int MoveWindow(IntPtr hwnd, int X, int Y, int nWidth,
int nHeight, bool bRepaint);
Enjoy!
In the "onLoad" method:
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
To show:
int h = FindWindow ("HHTaskBar", "");
ShowWindow (h, SW_SHOW);
Rectangle rc = this.Bounds;
this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;
MoveWindow (hwnd, rc.Left, rc.Top, rc.Right, rc.Bottom - taskBarSize, true);
To hide:
int h = FindWindow ("HHTaskBar", "");
ShowWindow (h, SW_HIDE);
Rectangle rc = this.Bounds;
this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;
MoveWindow (hwnd, rc.Left, rc.Top, rc.Right, rc.Bottom + taskBarSize, true);
where:
private int taskBarSize = 24;
const int SW_HIDE = 0x0000;
const int SW_SHOW = 0x0001;
[DllImport("coredll")]
public static extern IntPtr GetCapture();
[DllImport("coredll.dll")]
public static extern int FindWindow (string lpClassName, string
lpWindowName);
[DllImport("coredll.dll")]
public static extern int ShowWindow (int hwnd, int nTaskShow);
[DllImport("coredll.dll")]
public static extern int MoveWindow(IntPtr hwnd, int X, int Y, int nWidth,
int nHeight, bool bRepaint);
Enjoy!
Friday, September 23, 2005
CF : Enabling network connection from a PPC emulator
Assuming the desktop that runs the emulator has a network connection ...
This is using PPC 2003 emulator / PPC 2002 is similar.
Start / Settings / Connections
Click Connections icon.
Advanced / Select Networks
Change dropdown for Internet connection to "My Work Network"
Edit / Proxy Settings
Check the checkbox "This network connects to the Internet"
OK all the way out.
Try IE - should now have a network connection from the emulator.
Enjoy!
(Compact Framework)
This is using PPC 2003 emulator / PPC 2002 is similar.
Start / Settings / Connections
Click Connections icon.
Advanced / Select Networks
Change dropdown for Internet connection to "My Work Network"
Edit / Proxy Settings
Check the checkbox "This network connects to the Internet"
OK all the way out.
Try IE - should now have a network connection from the emulator.
Enjoy!
(Compact Framework)
Wednesday, September 07, 2005
Misc : Blackberry vs Compact Framework development
You can say what you like about Microsoft but the Compact Framework development environment and support creams RIM and Blackberry hands down, TKO, no contest!
- Visual Studio is a much better, less buggy IDE than the Blackberry JDE.
- Deployment is much easier with Active Synch as opposed to Desktop Manager. It's basically another folder and you can drag and drop all kinds of files anywhere.
- Blackberry Forum support is a joke. Does anyone from RIM actually read it? Most of the posts go unanswered for days on end. Compare this to the Google group "microsoft.public.dotnet.framework.compactframework". You get answers within hours and the quality is excellent with such people as Peter Foot, Paul G Tobey, Daniel The Moth, the two Alex's and so on.
- CF has the superb OpenNETCF. RIM has nothing even remotely comparable.
- Do a Google search for some CF samples. You are spoiled for choice. Do the same for Blackberry - the quickest way I know to return zero Google results. If anyone out there is doing Blackberry development, they certainly don't seem to be posting it to anywhere.
- To be fair, Blackberry is constrained by the J2ME environment in terms of the quantity and richness of the components but it's still no contest.
Enjoy!
Thursday, April 07, 2005
CF : Updating the application on the device
Two very useful links:
Creating Self-Updating Applications With the .NET Compact Framework
http://msdn.microsoft.com/smartclient/understanding/netcf/deploy/default.aspx?pull=/library/en-us/dnnetcomp/html/autoupdater.asp
Deployment Patterns for Microsoft .NET Compact Framework
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/DeploymentPatterns.asp
Enjoy!
(Compact Framework)
Creating Self-Updating Applications With the .NET Compact Framework
http://msdn.microsoft.com/smartclient/understanding/netcf/deploy/default.aspx?pull=/library/en-us/dnnetcomp/html/autoupdater.asp
Deployment Patterns for Microsoft .NET Compact Framework
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/DeploymentPatterns.asp
Enjoy!
(Compact Framework)
CF : Links for Packaging and Deploying .NET Compact Framework-based applications
There are some really useful links here:
http://blogs.msdn.com/onoj/archive/2004/12/04/275074.aspx
Good one!
Enjoy!
(Compact Framework)
http://blogs.msdn.com/onoj/archive/2004/12/04/275074.aspx
Good one!
Enjoy!
(Compact Framework)
Friday, April 01, 2005
CF : Problem with CF SP2 with Form navigation
My particular problem was with Windows CE.
This behavior can be seen using the CE emulator running under Visual Studio 2003.
InitializeComponent() and the onLoad event both have the
this.WindowState = FormWindowState.Maximized;
construct set.
Using the RTM version of the CF (1.0.2268.0) navigating between the two forms using the buttons causes the two forms to be always maximized.
Installing SP2 (1.0.3316.0) on the emulator and then running the same application causes the forms to be minimized on the taskbar while navigating between them and they have to be manually maximized.
The full example I wrote to illustrate this can be found here:
Problem with CF SP2 with Form navigation
After posting to the group, emails to Microsoft, formally logging the bug with Microsoft I got nowhere.
Then Alex Feiman suggested a workaround to this.
The code was:
currentForm.Hide ();
...
nextForm.Show ();
As Alex explained: "The reason the forms get minimized is because at some point you do not have a visible form and the runtime thinks you want the app hidden".
Reversing the order:
nextForm.Show ();
...
currentForm.Hide ();
stops the next form from minimising under SP2. It was never an issue with RTM.
Each form has always had the
this.WindowState = FormWindowState.Maximized;
attribute set.
Enjoy!
(Compact Framework)
This behavior can be seen using the CE emulator running under Visual Studio 2003.
InitializeComponent() and the onLoad event both have the
this.WindowState = FormWindowState.Maximized;
construct set.
Using the RTM version of the CF (1.0.2268.0) navigating between the two forms using the buttons causes the two forms to be always maximized.
Installing SP2 (1.0.3316.0) on the emulator and then running the same application causes the forms to be minimized on the taskbar while navigating between them and they have to be manually maximized.
The full example I wrote to illustrate this can be found here:
Problem with CF SP2 with Form navigation
After posting to the group, emails to Microsoft, formally logging the bug with Microsoft I got nowhere.
Then Alex Feiman suggested a workaround to this.
The code was:
currentForm.Hide ();
...
nextForm.Show ();
As Alex explained: "The reason the forms get minimized is because at some point you do not have a visible form and the runtime thinks you want the app hidden".
Reversing the order:
nextForm.Show ();
...
currentForm.Hide ();
stops the next form from minimising under SP2. It was never an issue with RTM.
Each form has always had the
this.WindowState = FormWindowState.Maximized;
attribute set.
Enjoy!
(Compact Framework)
Tuesday, March 29, 2005
CF : Error: Cannot establish a connection ...
Irritating error: "Error: Cannot establish a connection. Be sure the device is physically connected to the development computer."
This may help:
You need to download and install Microsoft Windows CE Utilities for Visual Studio .NET 2003 Add-on Pack 1.1 on your development PC running Visual Studio. Get it from here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=7ec99ca6-2095-4086-b0cc-7c6c39b28762&displaylang=en
Then read through the solutions listed in the Readme.htm file in the:
C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\WinCE Utilities folder.
You may need to run C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\WinCE Utilities\WinCE Proxy Ports Reg\ProxyPorts.reg.
Also: In Visual Studio under "Device Options", ensure that the "Transport" is "TCP Connect Transport" and that you "Obtain an IP address automatically".
Then start ActiveSynch, inside your project go to Tools\Select Windows CE Device CPU and select ARMV4T or whatever your CPU is. Then deploy to the device and you should be able to debug on the device.
Enjoy!
(Compact Framework)
This may help:
You need to download and install Microsoft Windows CE Utilities for Visual Studio .NET 2003 Add-on Pack 1.1 on your development PC running Visual Studio. Get it from here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=7ec99ca6-2095-4086-b0cc-7c6c39b28762&displaylang=en
Then read through the solutions listed in the Readme.htm file in the:
C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\WinCE Utilities folder.
You may need to run C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\WinCE Utilities\WinCE Proxy Ports Reg\ProxyPorts.reg.
Also: In Visual Studio under "Device Options", ensure that the "Transport" is "TCP Connect Transport" and that you "Obtain an IP address automatically".
Then start ActiveSynch, inside your project go to Tools\Select Windows CE Device CPU and select ARMV4T or whatever your CPU is. Then deploy to the device and you should be able to debug on the device.
Enjoy!
(Compact Framework)
CF : Downloading a file to the emulator
Perhaps the simplest way is to add the file as "Content" to your project using Solution Explorer and then deploy the project to the emulator. Then find the file and run it.
Note: "Left Slash" = /, "Right Slash" =
In Windows CE, copy the file to a shared directory on your desktop and then using the "Run" command, execute
"Right Slash""Right Slash"Desktop"Right Slash"Share.
Then either run the file direct or copy / paste to a directory inside the emulator and then run it.
In PPC, use IE and type
file:"LeftSlash""LeftSlash""Right Slash""Right Slash"Desktop"Right Slash"Share and follow the same procedure.
Alternatively, use "File Explorer/Open" and then
""Right Slash""Right Slash"Desktop"Right Slash"Share
You can also use "Emulator ActiveSync Connection Tool - Allows Activesync to connect to your Emulator session from Visual Studio .NET 2003" from "Windows Mobile Developer Power Toys" available here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=74473fd6-1dcc-47aa-ab28-6a2b006edfe9&displaylang=en
(Note: There are two downloads. You need to download "EmuASConfig.msi").
Once connected via ActiveSync, you could use "CECopy - Command line tool for copying files to the device currently connected to desktop ActiveSync" also available from the Power Toys link above.
Enjoy!
(Compact Framework)
Note: "Left Slash" = /, "Right Slash" =
In Windows CE, copy the file to a shared directory on your desktop and then using the "Run" command, execute
"Right Slash""Right Slash"Desktop"Right Slash"Share.
Then either run the file direct or copy / paste to a directory inside the emulator and then run it.
In PPC, use IE and type
file:"LeftSlash""LeftSlash""Right Slash""Right Slash"Desktop"Right Slash"Share and follow the same procedure.
Alternatively, use "File Explorer/Open" and then
""Right Slash""Right Slash"Desktop"Right Slash"Share
You can also use "Emulator ActiveSync Connection Tool - Allows Activesync to connect to your Emulator session from Visual Studio .NET 2003" from "Windows Mobile Developer Power Toys" available here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=74473fd6-1dcc-47aa-ab28-6a2b006edfe9&displaylang=en
(Note: There are two downloads. You need to download "EmuASConfig.msi").
Once connected via ActiveSync, you could use "CECopy - Command line tool for copying files to the device currently connected to desktop ActiveSync" also available from the Power Toys link above.
Enjoy!
(Compact Framework)
Subscribe to:
Posts (Atom)