【发布时间】:2008-08-25 12:51:33
【问题描述】:
Compact Framework 不支持通过 Assembly.GetEntryAssembly 确定启动 .exe。那么有没有其他方法可以获取正在执行的.exe的名字呢?
编辑:我在 Peter Foot 的博客上找到了答案:http://peterfoot.net/default.aspx 代码如下:
byte[] buffer = new byte[MAX_PATH * 2];
int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH);
if (chars > 0)
{
string assemblyPath = System.Text.Encoding.Unicode.GetString(buffer, 0, chars * 2);
}
[DllImport("coredll.dll", SetLastError = true)]
private static extern int GetModuleFileName(IntPtr hModule, byte[] lpFilename, int nSize);
【问题讨论】:
-
在 CF2 中:字符串 s = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
标签: .net compact-framework windows-ce