Compact Framework不支持Assembly.GetEntryAssembly来确定启动.exe。那么是否有另一种方法来获取正在执行的.exe的名称?如何获得执行.exe的名称?
编辑:我发现彼得脚的博客答案: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);
in CF2:string s = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly()。GetName()。CodeBase); – josef 2012-12-01 18:35:19