C#在VS2005:可以在一个设备项目的目标都完整的框架和CF? [英] C# in VS2005: Can a device project target both full framework and CF?

查看:143
本文介绍了C#在VS2005:可以在一个设备项目的目标都完整的框架和CF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在与Visual Studio 2005的下一个设备Compact Framework的开发不过我们希望该软件的模拟版本,以及,在PC(最好通过构建配置可选)运行。

We're developing with Compact Framework for a device under Visual Studio 2005. However we want to make an emulated version of the software as well, running at the PC (preferably selectable via a Build Configuration).

但是,由于它似乎.vsproj文件是具体的设备;有没有办法通过只是改变了目标来使用,例如完整的.NET框架。

It seems however that the .vsproj file is specific for devices; there is no way to use the full .NET framework for example by just changing the target.

有没有解决这个办法吗?我想我们可以运行在PC上紧凑的框架,但仍项目不能定位,例如ARM处理器,否则我假定JIT编译器会为PC机无法使用的代码?

Is there any way around this? I suppose we can run the compact framework on the PC, but still the project can't target for example an ARM processor or else I assume the JIT compiler will generate unusable code for the PC?

推荐答案

您的可以的运行常规的Windows(也许)一个Compact Framework的应用程序。有两个主要的潜在问题,这一点,但是。

You can run a Compact Framework application in regular Windows (maybe). There are two major potential problems with this, however.

首先,因为存在于完整的框架一定的形式和控制性能在紧凑的框架缺失,您的应用程序的行为有些奇怪的是在Windows中。例如,在完整的框架形式具有决定那里的形式出现在屏幕上是第一次创建时,他们一个中StartPosition属性。此属性并不在紧凑的框架存在(原因很明显),所以当你在常规的Windows运行CF应用程序,形式拿起 WindowsDefaultLocation 的默认中StartPosition值,这意味着,设置窗体的Left和Top属性对他们出现的地方没有任何影响,所以形式弹出的地方。

First, because certain form and control properties present in the full framework are missing in the compact framework, your application will behave a bit oddly in Windows. For example, in the full framework forms have a StartPosition property which determines where the forms appear on the screen when they're first created. This property does not exist in the compact framework (for obvious reasons), so when you run your CF application in regular Windows, the forms pick up the default StartPosition value of WindowsDefaultLocation, which means that setting the form's Left and Top properties has no effect on where they appear, so the forms pop up wherever.

二,任何Windows API的PInvoke在CF呼叫必须参考coredll,而在完整的框架参考USER32,WINMM等相同的调用解决这个问题的办法是做这样的事情:

Second, any Windows API PInvoke calls in CF must reference "coredll", whereas the same calls in the full framework reference "user32", "winmm" etc. One way around this problem is to do something like this:

[DllImport("winmm.dll", EntryPoint="waveOutReset")]
private static extern int waveOutResetFULL(IntPtr hWaveIn);
[DllImport("coredll.dll", EntryPoint="waveOutReset")]
private static extern int waveOutResetCF(IntPtr hWaveIn);
public static int waveOutReset(IntPtr hWaveIn)
{
    if (Environment.OSVersion.Platform == PlatformID.WinCE)
    {
        return waveOutResetCF(hWaveIn);
    }
    else
    {
        return waveOutResetFULL(hWaveIn);
    }
}

有其他方法可以做到这一点,也。

There are other ways to do this, also.

关于第一组问题,一种解决方案是设置了当应用程序在常规的Windows运行通过反射缺少紧凑的框架的属性。我想一个更好的选择是封装你的UI用户控件作为,每一个主办了创建,并根据需要部署其他用户控件元素的一个主用户控件的所有元素。然后,您可以承载在窗体的单个实例的单个主用户控件。

Regarding the first set of problems, one solution is to set the properties that are missing in the compact framework via Reflection when the application is running in regular Windows. I think a better alternative is to encapsulate all the elements of your UI as UserControls, each one hosted on a single "master" UserControl that creates and disposes the other UserControl elements as needed. You can then host your single "master" UserControl on a single instance of a form.

顺便说一句,我写的不正是一个应用程序这(在Windows中运行,在Windows Mobile设备)的主要造船厂,它仍然在使用。事实上,这种应用在两种环境下运行的能力,从字面上保存它的生命的时候使用在船厂的移动设备被临时停牌出于安全原因。

By the way, I wrote an application that does exactly this (run in Windows and on Windows Mobile devices) for a major shipbuilder, and it is still in use. In fact, the ability of this application to run in both environments literally saved its life when the use of mobile devices in the shipyard was temporarily suspended for security reasons.

这篇关于C#在VS2005:可以在一个设备项目的目标都完整的框架和CF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆