C# Windows phone 8处于已连接待机模式

C# Windows phone 8处于已连接待机模式,c#,windows-phone-8,driver,C#,Windows Phone 8,Driver,我选择了Windows驱动程序测试框架WDTF来支持Windows 8中的连接待机。我在编译时遇到以下错误 无法嵌入Microsoft.WDTF.WDTF2Class“”。使用适用的 接口。类型“Microsoft.WDTF.WDTF2Class”没有 构造函数定义 所有dll引用都来自C:\Program Files x86\Windows Kits\8.2\Testing\Development\lib\x86\。 这是我的剧本 IWDTF2 wdtf = new WDTF2Clas

我选择了Windows驱动程序测试框架WDTF来支持Windows 8中的连接待机。我在编译时遇到以下错误

无法嵌入Microsoft.WDTF.WDTF2Class“”。使用适用的 接口。类型“Microsoft.WDTF.WDTF2Class”没有 构造函数定义

所有dll引用都来自C:\Program Files x86\Windows Kits\8.2\Testing\Development\lib\x86\。 这是我的剧本

    IWDTF2 wdtf = new WDTF2Class();
    IWDTFSystemDepot2 systemDepot = wdtf.SystemDepot;
    IWDTFTarget2 systemTarget = systemDepot.ThisSystem;
    IWDTFSystemAction2 systemAction = (IWDTFSystemAction2)systemTarget.GetInterface("System");
    systemAction.ConnectedStandby(1000);

我与这个完全相同的问题进行了斗争,我终于能够解决它。您必须包括以下两个参考资料:

WDTF.Interop.dll WDTFSystemAction.Interop.dll 缺少第二个引用将导致您共享的错误。此外,目标机器Windows Surface 3平板电脑需要安装VC可再发行x64,正如我使用VS2013一样,还需要安装WDTF运行时。WDTF运行时是作为WDK[]的一部分安装的。在我的机器上,该路径如下所示:

C:\Program Files x86\Windows Kits\8.1\Testing\Runtimes\Windows驱动程序测试框架WDTF运行时库-x64\u en-us.msi

如果未安装VC可再发行版本,则可能会从计算机中收到一条…MSVCR120.DLL丢失…消息。或者,如果该消息编译为调试,则该消息可能引用MSVCR120D.DLL

如果未在目标计算机上安装运行时,则可能会收到以下错误:

未处理的异常:System.Runtime.InteropServices.COMException:检索CLSID为{0D972387-817B-46E7-913F-E9993FF401E的组件的COM类工厂 B} 由于以下错误而失败:80040154类未注册来自HRESULT的异常:0x80040154 REGDB_E_CLASSNOTREG。 在System.RuntimeTypeHandle.CreateInstanceRuntimeType类型、Boolean publicOn、Boolean noCheck、Boolean&canBeCached、RuntimeMethodHandleInternal&ctor、Bo olean&bNeedSecurityCheck中 位于System.RuntimeType.CreateInstanceSlowBoolean publicOnly、Boolean SkipCheck kThis、Boolean fillCache、StackScrawMark和stackMark 位于System.RuntimeType.CreateInstanceDefaultTorBoolean publicOnly、Boolean s kipCheckThis、Boolean fillCache、StackScrawlMark和stackMark 在System.Activator.CreateInstanceType类型中,布尔值为非公共 位于System.Activator.CreateInstanceType类型

完成所有这些步骤后,我能够使平板电脑进入ConnectedStandby状态。另一件需要注意的事情是:通过Damware连接时,平板电脑检测到输入,并拒绝进入ConnectedStandby状态。我最终能够通过将此可执行文件设置为按计划任务运行,然后将平板电脑ping到查看是否/何时失去网络连接,以及何时恢复网络连接

注意:ConnectedStandby_SleepAndWake是我在VS2013中的项目名称

CS、app.config和项目定义csproj文件如下:

*program.cs*

*app.config*

*已连接待机\u sleep和wake.csproj*


也许是一个愚蠢的问题,但为什么要使用windows-mobile-6标记?这个问题可能也不愚蠢。删除了windows-Mobile6标记。即使添加Interop.dll作为参考,我也无法编译上述代码段。任何人都可以使用WDTF API成功地将windows Phone系统置于CS模式。请回复。我在C++ MSDN页面上找到你的片段,你想做什么?给我们更多的上下文。上下文很简单。JPHELEMMONS,需要使用WDTF把Windows手机连接到待机模式。如果你在上面工作,PLZ提供建议。我不明白你在说什么。这是问题的答案。你读了整个回复吗?对不起……误会
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WDTF;
using System.Configuration;

namespace ConnectedStandby_SleepAndWake
{
    class Program
    {
        static void Main(string[] args)
        {

            int CSDurationMilliseconds = 0;
            DateTime wakeTime = new DateTime();
            try
            {
            if (ConfigurationManager.AppSettings["wakeTime"] != null)
            {
                wakeTime = Convert.ToDateTime(ConfigurationManager.AppSettings["wakeTime"]);
            }
            else
            {
                wakeTime = DateTime.Now.AddMinutes(2);
            }

            System.TimeSpan wakeInMs = wakeTime.Subtract(DateTime.Now);
            CSDurationMilliseconds = wakeInMs.Milliseconds;

            IWDTF2 WDTF = new WDTF2();
            IWDTFSystemAction2 Sys = (IWDTFSystemAction2)WDTF.SystemDepot.ThisSystem.GetInterface("System");
            // Sys.SleepWakeTimeInSeconds = 60;
            // Sys.Sleep(4);

            Sys.ConnectedStandby(CSDurationMilliseconds);
            }

            catch (Exception e)
            {
            }



        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <appSettings>
    <add key="wakeTime" value="2015-08-16 01:25AM"/>
  </appSettings>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{657A21BE-8991-4E24-AB41-59D7F0C7D3EB}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>ConnectedStandby_SleepAndWake</RootNamespace>
    <AssemblyName>ConnectedStandby_SleepAndWake</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>x64</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Reference Include="WDTF.Interop">
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\8.1\Testing\Development\lib\x64\WDTF.Interop.dll</HintPath>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </Reference>
    <Reference Include="WDTFInterfaces.Interop">
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\8.1\Testing\Development\lib\x64\WDTFInterfaces.Interop.dll</HintPath>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </Reference>
    <Reference Include="WDTFSystemAction.Interop">
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\8.1\Testing\Development\lib\x64\WDTFSystemAction.Interop.dll</HintPath>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.5">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>