首页  ·  知识 ·  编程语言
微软.NET精简框架(NETCF)最常见问题
佚名  www.weste.net  .NET  编辑:dezai  图片来源:网络
1. 开发 1.1. 什么是微软 .net精简框架? 微软.net精简框架是.net框架为智能设备开发的平台,是实现微软的目标:“为用户提供精彩的体验--

1. 开发

1.1. 什么是微软 .net精简框架?

微软.net精简框架是.net框架为智能设备开发的平台,是实现微软的目标:“为用户提供精彩的体验--任何时间、任何地点、任何设备” 的关键部分。.net精简框架把托管代码的世界从web服务带到了智能设备上, 允许在个人数字助理(PDA)、移动电话、机顶盒设备上的 安全的、可下载的应用。

http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/overview/default.aspx

1.2. 我需要什么工具才能开发.net精简框架的应用?

Visual Studio .NET 2003 是在Pocket PC 2000、Pocket PC 2002和Windows CE.NET 4.1上开发.net精简框架所需要的, .net精简框架与Visual Studio .NET 2003一同发售.
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/vstudio/default.aspx

其他Windows移动平台开发包可以在以下地方获得:

Windows Mobile 2003 Pocket PC SDK:
http://www.microsoft.com/downloads/details.aspx?familyid=9996b314-0364-4623-9ede-0b5fbb133652&displaylang=en

Windows Mobile 2003 Smartphone SDK:
http://www.microsoft.com/downloads/details.aspx?familyid=a6c4f799-ec5c-427c-807c-4c0f96765a81&displaylang=en

这篇文章将介绍如何使用.net精简框架和Visual Studio .NET 2003下开发健壮的智能设备应用程序.
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfgetstarted.asp

1.3. 哪里可以下载最新的工具和相关软件?

Visual Studio .NET 2003试用版可以在这里获得:
http://msdn.microsoft.com/vstudio/productinfo/trial/default.aspx

最新的.net精简框架和补丁集可以在这里获得:
http://msdn.microsoft.com/mobility/downloads/default.aspx

1.4. .net精简框架支持些什么设备?

.net精简框架可以在Pocket PC 2000, Pocket PC 2002, Windows Mobile 2003的Pocket PC 和 基于Windows CE.NET 4.1嵌入式系统的Pocket PC、智能手机 上运行。

1.5. .net精简框架以后将支持什么设备?

.net精简框架将被集成到微软系统中并成为一部分,包括未来的Pocket PC设备,Pocket PC电话版,智能手机,车载Windows CE系统,MSTV。 各种设备的发布时间待定。

.net精简框架将作为Windows CE .NET 4.1系统组件的一部分,因此允许OEM厂商使用PlatformBuilder把.net精简框架集成到新的Windows CE设备中。

1.6. 调试程序时为什么会出现“与模拟器建立连接失败”的错误(刚开始执行程序的时候)?

下面这个连接将告诉你如何设置调试和排错。
http://download.microsoft.com/download/c/d/b/cdbff573-73fb-4f9f-a464-c5adc890e1ae/Readme.htm

1.7. .net框架和.net精简框架之间有什么区别?

.NET框架 和 .net精简框架 的关系:
http://msdn.microsoft.com/library/en-us/dv_evtuv/html/etconComparisonsWithNETFramework.asp

在线查看.net精简框架类库关系工具:
http://msdn.microsoft.com/library/en-us/dv_spchk/html/NET_Compact_Framework.htm

1.8. .net精简框架的补丁有什么改进?

.net精简框架 SP1 修正了许多漏洞,查看修正项目列表:
http://www.microsoft.com/downloads/details.aspx?familyid=1f62a2a3-7282-4ba9-b26b-2267e972501d&displaylang=en

1.9. Poclet PC上的.net精简框架开发和Windows CE .NET上的.net精简框架开发有什么不同?

这篇文章将描述在Pocket PC和Windows CE.NET平台上开发基于.net 精简框架的应用程序的区别之处。
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfPPCtoCE.asp

1.10. 哪里有更多的关于建立.net精简框架上的应用程序的信息?

以下资源能教会您怎样建立.net精简框架应用程序:

.net精简框架  快速入门
http://samples.gotdotnet.com/quickstart/compactframework/

.net精简框架白皮书 MSDN移动和嵌入式开发中心:
http://msdn.microsoft.com/mobility/understanding/articles/default.aspx

1.11. .net精简框架的文档在哪里?

http://msdn.microsoft.com/library/en-us/dv_evtuv/html/etconNETCompactFramework.asp

1.12. 怎样设置才不会在每次调试的时候把所涉及的文件都拷贝到设备上?

在Visual Studio .NET 2003, 右键点击文件并选择属性,把Build的属性设置为None.文件将不再被拷贝.如果文件修改过了,需要重新拷贝,把Build属性改为Content即可.

1.13. 怎样设置模拟器的属性?

在Visual Studio .NET 2003菜单中,选择 Tools->Options. 打开 Device Tools 文件夹,并选择 Devices. 您应该看到一个显示设备列表的对话框.选择您想修改的设备,按Configuration按钮.
现在您应该看到一个包含多个TAB并可以修改设置的对话框,如设置内存和屏幕大小等.

1.14. 怎么调试.net精简框架的应用程序?

微软.net精简框架完全集成在Visual Studio .NET 2003中,在Visual Studio .NET 2003下调试.net精简框架的应用和在Visual Studio .NET 2003下调试其他应用一样。在一个单独的设备上调试程序和在模拟器中调试程序需要注意不同的地方。查看下面文章可以获得更多调试.net精简框架的经验。
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/CompactFXDebug.asp

1.15. 怎样开始使用Visual Basic .NET开发.net精简框架的程序?

了解怎样使用Smart Device Extensions (SDE)编写只能设备的应用。这篇文章详细介绍了在.net精简框架上开发、调试、发布的完整过程,并描述了和在.net框架上开发的区别。
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/sdeforvb.asp

1.16. 怎样才能把.net精简框架安装到装配集中(GAC)?

http://msdn.microsoft.com/library/en-us/dncfhowto/html/HOWTOGAC.asp

1.17. 当从Visual Studio .NET 2003中发布程序到设备上的时候,怎样处理"Sharing Violation"?

This article illustrates the cause of a sharing violation that prevents the deployment of your application from Visual Studio .NET 2003, and gives instructions on how to work around it.
http://msdn.microsoft.com/library/en-us/dncfhowto/html/HOWTOSharingviolation.asp

1.18. 什么是common language runtime (CLR)?

.net精简框架提供的运行环境叫做CLR,它使程序运行,并且是开发更加容易。以下文章将使您了解更多关于CLR:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcommonlanguageruntimeoverview.asp

1.19. 什么是Global Assembly Cache (GAC)?

每一台装了.net环境的机器都会有一个本机器范围内的缓冲,这就是GAC。GAC中存放的装配会被这台计算机上的一些应用程序共享 。这篇文章将告诉你更多关于GAC的信息:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconglobalassemblycache.asp

1.20. 在.net精简框架下内存管理是怎样的?

自动内存管理是CLR提供的一项服务。CLR的垃圾回收器会管理应用程序内存的分派和回收,以下文章将为您解释:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconautomaticmemorymanagement.asp

1.21. 当我的网络协议数超过50个的时候,为什么不能向发布程序?

请查看本文章的  "11.4. 为什么当网络协议数超过50个的时候,就不能向设备发布程序?"  部分。

1.22. 为什么会有跨平台代码?

.net精简框架和它的执行引擎是.net框架和CLR的子集。缺省的强名称策略,针对.net精简框架编译的程序同样可以在完整的.NET框架上运行,但会有一些重要的异常信息:


.net精简框架装配使用和.net框架不用的强名称签名,所以CLR可以区分它们。
在未来发布的.NET框架和CLR的绑定策略中将使用.NET框架装配代替兼容.NET精简框架参考。这样,在普通情况下,不需要重新连接就能重用组件。 例如:如果您的组件只引用了.net精简框架的 System 和 System.NET 类库,它则不需要重新连接就适合在.net精简框架和完整的.NET框架下运行。
如果你引用了.net精简框架特有的功能,如PocketPC特有的用户界面,程序将不能在完整的.net框架上运行。
如跨平台的中间组件的开发和发布,微软认为丰富的客户端应用应该利用智能设备特有的功能为用户带来更好的体验。这一味着好的图形用户界面基本上是客户端特有的。
尽管微软花费很大精力为不同设备和功能划分了不同的命名空间和装配以避免装配冲突,但在1.0的版本里还是会有不能处理的兼容性问题。在这种情况下,在. net框架上不经意地使用了设备专有的功能将会导致程序在运行时的异常,而不是载入时的异常。

1.23. 这些ARM指令代表什么?

XScale支持ARM v5指令集,同时也向下兼容ARM v4指令集。这里有三种情况:


ARMv4 -> 只支持32位ARMv4指令
ARMv4T -> 'T' 表示 Thumb. Thumb 是ARM16位指令模式
ARMv4I -> 'I' 表示 Interworking. 允许32位和16位指令共存

对于其他ARM处理器:


StrongARM (SA1110) -> 只支持ARMv4指令
ARM920T, etc -> 支持所有三种情况

.net精简框架支持三种ARM代码

ARMv4 for PocketPC 2000 and Pocket PC 2002. 支持所有ARM设备,包括XScale。发布到设备的CAB文件名包含有"arm"字符。
ARMv4 for Windows CE.NET. 支持由PlatformBuilder使用ARMv4核心编译的Windows CE.NET设备。Pocket PC 2003支持这种代码。发布到设备的CAB文件名包含有"armv4"字符。
ARMv4T or ARMv4I for Windows CE.NET. 支持由PlatformBuilder使用ARMv4T 或 ARMv4I核心编译的Windows CE.NET设备。发布到设备的CAB文件名包含有"armv4T"字符。

1.24. 怎样写注册表?

Visual Studio .NET 的发布中没有包括Windows CE的远程注册表编辑器。要修改注册键值,可以采用以下方法:

Microsoft Embedded Visual Tools Remote Registry Editor
Microsoft Windows CE Platform Builder Remote Registry Editor
PHM Pocket PC Registry Editor (共享软件,很容易在网上找到)
1.25. How can I prevent .CAB files from being deleted after installation?

Automatic deletion of .CAB files can be prevented by setting the property of the .CAB file(s) to Read Only.

1.26. How can I determine the version of the .NET Compact Framework that is installed on a device?

Each version of the .NET Compact Framework is released with a different Win32 File Version number (this is a separate version number from the Assembly Version, which should be the same across all releases of the Version 1 .NET Compact Framework, including Service Packs).

In order to see what version is installed, use File Explorer to navigate to the \Windows directory on the device, and click the file called CGACUTIL. You will get a message box showing you the Win32 File Version of the .NET Compact Framework installed on the device.

RTM = 1.0.2268.0
SP1 = 1.0.3111.0
SP2 Recall = 1.0.3226.0
SP2 Beta = 1.0.3227.0
SP2 Final = 1.0.3316.0

To determine the version programmatically you can use System.Environment.Version.ToString().

1.27. How do I copy files to the emulator?

One approach would be to create a file share on your development PC, and then connect to that share via File Explorer in the emulator. You may then copy and paste the files from the share to the emulator's local file system. Another approach would be to add the file(s) to a smart device project and set their Build Action(s) property to "Content". See the Visual Studio .NET online documentation for more information on "File Properties":

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconfileproperties.asp

Step by step instructions for adding a "Content" file to a smart device project:

Open or create a smart device project,
On the View menu, click Solution Explorer,
In Solution Explorer, right-click on your project, point to Add, and click Add Existing Item. Browse to and add the desired file to the project.
Right-click on the file that you added, in solution explorer, and click Properties,
Set the Build Action property to "Content", if it is not already set.
1.28. Why does installation of the PocketPC 2002 SDK fail?

Symptom: The Pocket PC 2002 SDK installer hangs while "registering components."

Cause: An unregestered component causes the installation to hang while attempting to run the emulator.

Workaround: From a console window prompt:
cd \WINNT\system32
regsvr32 atl.dll

1.29. How do I debug a Web service consumed by a Smart Device application?

You need to attach the debugger to the ASP.NET worker process.

Refer to the following link for more information:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskdebugginganaspdeployedwebapplication.asp

1.30. What is the footprint of the .NET Compact Framework?

.NET Compact Framework storage size:

1.55MB (ROM) on Pocket PC 2000/2002
1.35MB (ROM) on Windows Mobile for Pocket PC 2003 or Windows CE .NET Devices
Running RAM requirements:

.5 MB+ (depends on application)
Typical application sizes:

5 - 100 KB
1.31. How do I include imgdecmp.dll in an emulator image?

You must ask the OEM to include it in the device's image. If you are the OEM and you are using Platform Builder 4.2, then including the OS Dependencies for the .NET item automatically causes imgdecmp.dll to be part of the emulator image - if that is not working then refer to cesysgen.bat. Another method is to set the environment variable "__SYSGEN_IMGDECMP=1" to explicitly force the DLL into the image.

1.32. How do I programmatically replace Assemblies in the Global Assembly Cache (GAC)?

One can install and remove Assemblies directly to and from the GAC by programmatically launching cgacutil.

Remove assemblies from the GAC using the -u option
Install assemblies to the GAC using the -i option
It is typically safest to remove the Assembly before reinstalling it.

1.33. How can I display Pocket PC applications on my desktop or laptop without needing any device side configuration?

Download the ActiveSync Remote Display from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

1.34. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?

See the entry titled "11.17. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?" of this FAQ.

1.35. How can I copy files to the device currently connected to desktop ActiveSync?

See the entry titled "11.18. How can I copy files to the device currently connected to desktop ActiveSync?" of this FAQ.

1.36. How can I stress test user input?

Download Hopper from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

1.37. Where can I get a UI version of the Platform Builder Target Control Window?

Download JShell from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

1.38. Where can I get a Command shell for Pocket PC 2003 devices?

Download PPC Command Shell from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

1.39. How can I get detailed information about currently running processes?

Download RAPI Debug from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

1.40. How can I remotely start an application on a Pocket PC from my desktop?

Download RAPI Start from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

1.41. Why can't I load different assemblies with the same name?

This is by design. You must either change the names of the DLLs, or if the DLLs are strong named, place them in the GAC and use Assembly.Load with a full strong name.

1.42. How can I force Visual Studio .NET 2003 to connect to newer versions of the Pocket PC 2003 emulator?

Download the Emulator ActiveSync Connection Tool from Windows Mobile Developer Power Toys:
http://www.microsoft.com/downloads/details.aspx?familyid=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

This allows ActiveSync to connect to your Emulator session from Visual Studio .NET 2003. Create an ActiveSync session to the 4.2 emulator, this will allow Visual Studio 2003 to consider it a real device (Choose PPC device as the deployment target).

1.43. Why don't my custom controls show up properly in the toolbox?

While adding designer support in Visual Studio .NET 2003 for Smart Device custom controls, you may run into the following issues:

Unable to associate an Icon to the Control for showing it in the toolbox at design time
The component, when added to the toolbox, becomes greyed out
Causes

Using a design project separate from the control project. Visual Studio .NET automatically prepends the project default namespace to the bitmap name. The "default namespace" defaults to the project name. This may be a problem because the design project has a slightly different name than the runtime project.
Not setting the correct ToolBoxItemFilterAttribute values
Resolutions

Given the following example:
Runtime VS.NET Project: MyProject
Class Name: MyProject.MyClass
Design VS.NET Project Name: MyProject.Design
BitMap name in VS.NET Design Project: Foo.bmp
Bitmap name in design assembly: MyProject.Design.MyClass.bmp
-- This creates a problem because the bitmap needs the name: MyProject.MyClass.bmp

In the above example, setting the design project's default namespace to "MyProject" rather then "MyProject.Design" should fix the problem.

The easiest way to check the name of the bitmap within the assembly is to run ILDASM and open the Manifest. The embedded resources are listed at the end of the manifest.

If you create a custom component derived from the Component class, your code must include the following statements so that your component appears in the Toolbox:

ToolBoxItemFilterAttribute("NETCF",ToolBoxItemFilterType.Require)
ToolBoxItemFilterAttribute("System.CF.Windows.Forms", ToolBoxITemFilterType.Custom)

 

--------------------------------------------------------------------------------


2. 图形


 2.1. 怎样建立一个图形对象?

有很多种方法可以建立图形对象,看你怎么用:

在OnPaint中,使用object参数提供的PaintEventArgs参数:


//C#
protected override void OnPaint(PaintEventArgs e)
{
  e.Graphics.DrawLine(...);
}

'VB
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    e.Graphics.DrawLine(...)
End Sub 'OnPaint


在程序的其他部分,利用控件的一个方法,可以用来建立任意控件的图形对象:


//C#
using System.Drawing;

Graphics g = this.CreateGraphics();

'VB
Imports System.Drawing

Dim g As Graphics = Me.CreateGraphics()


直接画到bitmap位图文件中:


//C#
using System.Drawing;

Bitmap bm = new Bitmap(10,10);
Graphics g = Graphics.FromImage(bm);

'VB
Imports System.Drawing

Dim bm As New Bitmap(10, 10)
Dim g As Graphics = Graphics.FromImage(bm)


2.2. 怎样优化GDI+?

以下编码方式有助提高使用Graphics的绘图速度:


只建立一个图形对象 (或只使用OnPaint中的 PaintEventArgs)。
把所有绘图工作先画到不显示的位图上,再一次性把位图显示出来。
只重画变化的部分图象。
尽可能在相同的区域上画相同大小的图象。
主要思路:最小化地重画图象。例如,当光标拖过图象时,不需要把整个图重新画一遍。只需要重画光标之前经过的地方。

2.3. 怎样在窗体上画一个图案?

这里有个例子,告诉你怎样把图片画到窗体的背景上:
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/bkgndimage.aspx

2.4. 怎样画一个带有透明色的图案?

画一个带有透明色的图象,需要设置ImageAttributes对象的透明色。目前.net精简框架支持单种颜色的透明色。虽然SetColorKey 功能可以设置颜色范围,但颜色的最大值和最小值必须相同,不然在运行时会出现ArgumentException的错误:


//C#
using System.Drawing.Imaging;

ImageAttributes attr = new ImageAttributes();

'VB
Imports System.Drawing.Imaging

Dim attr As New ImageAttributes()


以下代码描述了如何根据图象左上角的颜色设置透明色。


//C#
attr.SetColorKey(bmp.GetPixel(0,0), bmp.GetPixel(0,0));

'VB
attr.SetColorKey(bmp.GetPixel(0,0), bmp.GetPixel(0,0))


以下方法可以准确的设置颜色:


//C#
attr.SetColorKey(Color.FromArgb(255,0,255),Color.FromArgb(255,0,255));
attr.SetColorKey(Color.Fuchsia, Color.Fuchsia);

'VB
attr.SetColorKey(Color.FromArgb(255,0,255),Color.FromArgb(255,0,255))
attr.SetColorKey(Color.Fuchsia, Color.Fuchsia)


图象会被重载的Graphics.DrawImage方法重画,并且使用ImageAttributes对象作为一个参数parameter:


//C#
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height,GraphicsUnit.Pixel, attr);

'VB
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height,GraphicsUnit.Pixel, attr)

本文作者:佚名 来源:www.weste.net
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读