zoukankan      html  css  js  c++  java
  • WinCE中获取根目录的几种方式(C#)

    由于在WinCE中不支持相对路径,同时很多在Winform中可以使用的方法在Wince中都不可用。

    今天用到,就上网查找了下。有这么几个方式获取根目录的文件

    string root = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName) + "\\Configure.xml";

    或者

    String CodePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
    CodePath = CodePath.Substring(0, CodePath.LastIndexOf(@"\"));
    string filename = CodePath + "\\Configure.xml";

    或者使用API

    [DllImport("Coredll.dll", EntryPoint = "GetModuleFileName")]
    private static extern uint GetModuleFileName(IntPtr hModule, [Out] StringBuilder lpszFileName, int nSize);
    StringBuilder root = new StringBuilder(256);
    GetModuleFileName(IntPtr.Zero, root, 256);

    本来GetModuleFileName函数是在"Kernel32.dll"中的,但是在WINCE中,"Coredll.dll"对应了"Kernel32.dll"和"User32.dll"这两个文件了,所以将"Kernel32.dll"换成"Coredll.dll"。

  • 相关阅读:
    B+树实现
    一些比较特殊的计数序列
    codeforce刷题(六)
    codeforces刷题(五)
    Swap and Flip
    leetcode刷题(三)
    leetcode刷题(二)
    leetcode刷题(一)
    C语言学习笔记-变量存储
    水笔记
  • 原文地址:https://www.cnblogs.com/yabbi/p/3066515.html
Copyright © 2011-2022 走看看