惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - zqonline

vs2015 添加行件 关于 OpenSmtp 邮件标题过长后出现乱码问题的解决 获取 httponly 的 cookie 大文本编辑程序 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。 加速度传感器与车祸报警解决方案 sqlserver2008里创建系统管理员 iis+php 运行wordpress所遇到的问题 Winforms下使用TableLayoutPanel进行布局,并解决闪烁及平均列宽与平均行高问题 使用edtftpnet上传文件到Serv-U出现乱码的问题,并且不能创建中文文件名或文件夹。 升级程序到.net 4.0 发现log4net不工作与log4net conversionPattern 说明 uc密码产生方式。 SQLite数据库参数化编程时,采用命名参数的方式 System.Data.SQLite 不能在.net 4.0 里引用的解决方法 初次使用json数据格式,发生的常识性错误。 我电脑上的mssql2000居然,被黑了,在还原数据时提示:无法装载DLL Microsoft提示请误随意操作SQL数据库,以免对数据库造成不必要的麻烦或DLL所引用的某一DLL。原因:126(找不到指定模块) 解决SQL2000出现"无法执行查询,因为文件缺少或未注册。再次运行安装程序确保要求的文件已注册。"的方法 wordpress ImetaWeblog 运行时出现 “child”不是此父级的子控件。
wince文件同步代码[转]
zqonline · 2011-11-24 · via 博客园 - zqonline

从PC机到终端可以用Microsoft ActiveSync 这个同步软件直接文件同步就可以了。。

如下代码,在PC机上 实现 PC机 终端 相互传文件,就引用rapi.dll
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  static string configFilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName) + "\\";

  #region 声明要引用的DLL
  // 声明要引用的API
  [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
  internal static extern int CeRapiUninit();

  [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
  internal static extern int CeRapiGetError();

  [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
  internal static extern int CeRapiInit();

  // 声明要引用的API
  [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
  internal static extern int CeCloseHandle(IntPtr hObject);

  [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
  internal static extern int CeWriteFile(IntPtr hFile, byte[] lpBuffer,
  int nNumberOfbytesToWrite, ref int lpNumberOfbytesWritten, int lpOverlapped);

  [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
  internal static extern IntPtr CeCreateFile(
  string lpFileName,
  uint dwDesiredAccess,
  int dwShareMode,
  int lpSecurityAttributes,
  int dwCreationDisposition,
  int dwFlagsAndAttributes,
  int hTemplateFile);
  [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
  internal static extern int CeCopyFile(string lpExistingFileName, string lpNewFileName, int bFailIfExists);

  [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
  internal static extern int CeGetSystemInfo(out SYSTEM_INFO pSI);

  [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
  internal static extern bool CeGetVersionEx(out OSVERSIONINFO lpVersionInformation);

  [DllImport("rapi.dll ", CharSet = CharSet.Unicode, SetLastError = true)]
  internal static extern int CeReadFile(IntPtr hFile, byte[] lpBuffer, int nNumberOfbytesToRead, ref int lpNumberOfbytesRead, int lpOverlapped);

  #endregion

  #region 声明变量
  private const uint GENERIC_WRITE = 0x40000000; // 设置读写权限
  private const short CREATE_NEW = 1; // 创建新文件
  private const short FILE_ATTRIBUTE_NORMAL = 0x80; // 设置文件属性
  private const short INVALID_HANDLE_VALUE = -1; // 错误句柄

  private const short CREATE_ALWAYS = 2;
  private const uint GENERIC_READ = 0x80000000;
  private const short OPEN_EXISTING = 3;
    
  IntPtr remoteFile = IntPtr.Zero; // 本地计算机文件名
  String LocalFileName = @"F:\InsertRecordData.txt"; // 远程设备文件名
  String RemoteFileName = @"\Application Data\Log\InsertRecordData.txt";
  byte[] buffer = new byte[0x1000]; // 传输缓冲区定义为4k
  FileStream localFile;

  int bytesread = 0;
  int byteswritten = 0;
  int filepos = 0;

  #endregion

  #region Rapi初始化
  public int RapiInit()
  {
  int ret = CeRapiInit();

  if (ret != 0)
  {
  // 连接失败,获取失败代码
  int e = CeRapiGetError();

  // 抛出异常
  Marshal.ThrowExceptionForHR(ret);
  }

  return ret;
  }
  #endregion

  #region 將遠程設備上的文件複製到PCs文件目錄下
  /// <summary>
  /// 將遠程設備上的文件複製到PCs文件目錄下  
  /// </summary>
  /// <param name="LocalFileName"></param>
  /// <param name="RemoteFileName"></param>
  /// <param name="Overwrite"></param>
  public void CopyFileFromDevice(string LocalFileName, string RemoteFileName, bool Overwrite)
  {
  FileStream localFile;
  IntPtr remoteFile = IntPtr.Zero;
  int bytesread = 0;
  int create = Overwrite ? CREATE_ALWAYS : CREATE_NEW;
  byte[] buffer = new byte[0x1000]; // 4k transfer buffer  

  // open the remote (device) file  
  remoteFile = CeCreateFile(RemoteFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  // check for success  
  if ((int)remoteFile == INVALID_HANDLE_VALUE)
  {
  throw new Exception("不能打开远程设备上指定文件!");
  //throw new Exception("不能打開遠程設備上的Material_Tx.xml文件 ");
  }

  // create the local file  
  //localFile = new FileStream(LocalFileName, Overwrite ? FileMode.Create : FileMode.CreateNew, FileAccess.Write);
  localFile = new FileStream(LocalFileName, Overwrite ? FileMode.Create : FileMode.Create, FileAccess.Write);

  // read data from remote file into buffer  
  CeReadFile(remoteFile, buffer, 0x1000, ref bytesread, 0);
  while (bytesread > 0)
  {
  // write it into local file  
  localFile.Write(buffer, 0, bytesread);

  // get more data  
  if (!Convert.ToBoolean(CeReadFile(remoteFile, buffer, 0x1000, ref bytesread, 0)))
  {
  CeCloseHandle(remoteFile);
  localFile.Close();
  throw new Exception("读取远程设备上指定文件失败!");
  //throw new Exception("讀取遠程設備上的Material_Tx.xml文件失敗! ");
  }
  }

  // close the remote file  
  CeCloseHandle(remoteFile);

  localFile.Flush();

  // close the local file  
  localFile.Close();
  }
  #endregion

  #region PC文件写入到Wince
  /// <summary>
  /// PC文件写入到Wince
  /// </summary>
  public void RapiFile()
  {
  // 创建远程文件
  remoteFile = CeCreateFile(RemoteFileName, GENERIC_WRITE, 0, 0, CREATE_NEW,
  FILE_ATTRIBUTE_NORMAL, 0);

  // 检查文件是否创建成功
  if ((int)remoteFile == INVALID_HANDLE_VALUE)
  {
  throw new Exception("Could not create remote file");
  }

  // 打开本地文件
  localFile = new FileStream(LocalFileName, FileMode.Open);

  // 读取4K字节
  bytesread = localFile.Read(buffer, filepos, buffer.Length);
  while (bytesread > 0)
  {
  // 移动文件指针到已读取的位置
  filepos += bytesread;

  // 写缓冲区数据到远程设备文件
  if (!Convert.ToBoolean(CeWriteFile(remoteFile, buffer, bytesread,
  ref byteswritten, 0)))
  { // 检查是否成功,不成功关闭文件句柄,抛出异常
  CeCloseHandle(remoteFile);
  throw new Exception("Could not write to remote file");
  }
  try
  {
  // 重新填充本地缓冲区
  bytesread = localFile.Read(buffer, 0, buffer.Length);
  }
  catch (Exception)
  {
  bytesread = 0;
  }
  }

  // 关闭本地文件
  localFile.Close();

  // 关闭远程文件
  CeCloseHandle(remoteFile);
  }
  #endregion

#region 参数函数
  ///
  /// OSVERSIONINFO platform type
  /// 
  public enum PlatformType : int
  {
  ///
  /// Win32 on Windows CE.
  /// 
  VER_PLATFORM_WIN32_CE = 3
  }
  ///
  /// 操作系统版本信息
  /// 
  public struct OSVERSIONINFO
  {
  internal int dwOSVersionInfoSize;
  ///
  /// 主版本信息
  /// 
  public int dwMajorVersion;
  /// 
  /// 副版本信息
  /// 
  public int dwMinorVersion;
  /// 
  /// 编译信息
  /// 
  public int dwBuildNumber;
  ///
  /// 操作系统类型
  /// 
  public PlatformType dwPlatformId;
  }

  public struct SYSTEM_INFO
  {
  /// <summary>
  /// Processor architecture
  /// </summary>
  public ProcessorArchitecture wProcessorArchitecture;
  internal ushort wReserved;
  /// <summary>
  /// Specifies the page size and the granularity of page protection and commitment.
  /// </summary>
  public int dwPageSize;
  /// <summary>
  /// Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs).  
  /// </summary>
  public int lpMinimumApplicationAddress;
  /// <summary>
  /// Pointer to the highest memory address accessible to applications and DLLs.
  /// </summary>
  public int lpMaximumApplicationAddress;
  /// <summary>
  /// Specifies a mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.  
  /// </summary>
  public int dwActiveProcessorMask;
  /// <summary>
  /// Specifies the number of processors in the system.
  /// </summary>
  public int dwNumberOfProcessors;
  /// <summary>
  /// Specifies the type of processor in the system.
  /// </summary>
  public ProcessorType dwProcessorType;
  /// <summary>
  /// Specifies the granularity with which virtual memory is allocated.
  /// </summary>
  public int dwAllocationGranularity;
  /// <summary>
  /// Specifies the system抯 architecture-dependent processor level.
  /// </summary>
  public short wProcessorLevel;
  /// <summary>
  /// Specifies an architecture-dependent processor revision.
  /// </summary>
  public short wProcessorRevision;
  }
  public enum ProcessorArchitecture : short
  {
  /// <summary>
  /// Intel
  /// </summary>
  Intel = 0,
  /// <summary>
  /// MIPS
  /// </summary>
  MIPS = 1,
  /// <summary>
  /// Alpha
  /// </summary>
  Alpha = 2,
  /// <summary>
  /// PowerPC
  /// </summary>
  PPC = 3,
  /// <summary>
  /// Hitachi SHx
  /// </summary>
  SHX = 4,
  /// <summary>
  /// ARM
  /// </summary>
  ARM = 5,
  /// <summary>
  /// IA64
  /// </summary>
  IA64 = 6,
  /// <summary>
  /// Alpha 64
  /// </summary>
  Alpha64 = 7,
  /// <summary>
  /// Unknown
  /// </summary>
  Unknown = -1
  }
  public enum ProcessorType : int
  {
  /// <summary>
  /// 386
  /// </summary>
  PROCESSOR_INTEL_386 = 386,
  /// <summary>
  /// 486
  /// </summary>
  PROCESSOR_INTEL_486 = 486,
  /// <summary>
  /// Pentium
  /// </summary>
  PROCESSOR_INTEL_PENTIUM = 586,
  /// <summary>
  /// P2
  /// </summary>
  PROCESSOR_INTEL_PENTIUMII = 686,
  /// <summary>
  /// IA 64
  /// </summary>
  PROCESSOR_INTEL_IA64 = 2200,
  /// <summary>
  /// MIPS 4000 series
  /// </summary>
  PROCESSOR_MIPS_R4000 = 4000,
  /// <summary>
  /// Alpha 21064
  /// </summary>
  PROCESSOR_ALPHA_21064 = 21064,
  /// <summary>
  /// PowerPC 403
  /// </summary>
  PROCESSOR_PPC_403 = 403,
  /// <summary>
  /// PowerPC 601
  /// </summary>
  PROCESSOR_PPC_601 = 601,
  /// <summary>
  /// PowerPC 603
  /// </summary>
  PROCESSOR_PPC_603 = 603,
  /// <summary>
  /// PowerPC 604
  /// </summary>
  PROCESSOR_PPC_604 = 604,
  /// <summary>
  /// PowerPC 620
  /// </summary>
  PROCESSOR_PPC_620 = 620,
  /// <summary>
  /// Hitachi SH3
  /// </summary>
  PROCESSOR_HITACHI_SH3 = 10003,
  /// <summary>
  /// Hitachi SH3E
  /// </summary>
  PROCESSOR_HITACHI_SH3E = 10004,
  /// <summary>
  /// Hitachi SH4
  /// </summary>
  PROCESSOR_HITACHI_SH4 = 10005,
  /// <summary>
  /// Motorola 821
  /// </summary>
  PROCESSOR_MOTOROLA_821 = 821,
  /// <summary>
  /// Hitachi SH3
  /// </summary>
  PROCESSOR_SHx_SH3 = 103,
  /// <summary>
  /// Hitachi SH4
  /// </summary>
  PROCESSOR_SHx_SH4 = 104,
  /// <summary>
  /// Intel StrongARM
  /// </summary>
  PROCESSOR_STRONGARM = 2577,//---98x
  /// <summary>
  /// ARM720
  /// </summary>
  PROCESSOR_ARM720 = 1824,
  /// <summary>
  /// ARM820
  /// </summary>
  PROCESSOR_ARM820 = 2080,
  /// <summary>
  /// ARM920
  /// </summary>
  PROCESSOR_ARM920 = 2336,
  /// <summary>
  /// ARM 7
  /// </summary>
  PROCESSOR_ARM_7TDMI = 70001
  }
  #endregion

  #region 连接
  private void button1_Click(object sender, EventArgs e)
  {
  if (RapiInit() == 0)
  {
  MessageBox.Show("连接成功!");
  //labelstate.Text = "连接成功";

  //btnConnect.Enabled = false;
  }
  else
  {
  MessageBox.Show("连接失败!");
  }
  }
  #endregion

  #region 上传到PC机
  private void button2_Click(object sender, EventArgs e)
  {
  string localpath = @"F:\InsertRecordData.txt";
  CopyFileFromDevice(localpath, @"\Application Data\Log\InsertRecordData.txt", false);
  MessageBox.Show("上传成功!", "提示");
  }
  #endregion

  #region 下载到Wince
  private void button3_Click(object sender, EventArgs e)
  {
  RapiFile();
  MessageBox.Show("下载成功!", "提示");
  }
  #endregion

  }
}