|
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace BeeMobile
{
public class NativeFileSystem
{
const int MAX_PATH = 50;
static bool m_sbExceptionsEnabled;
[DllImport("coredll.dll", SetLastError = true, EntryPoint = "SHGetSpecialFolderPath")]
static extern bool SHGetSpecialFolderPath(int hwndOwner, string lpszPath, Folders nFolder, bool fCreate);
NativeFileSystem()
{ }
public static string GetFolderPath(Folders folder)
{
string sPath = new string(' ', MAX_PATH);
bool bRet;
try
{
bRet = SHGetSpecialFolderPath(0, sPath, folder, false);
}
catch (Exception ex)
{
HandleCeError(ex, "GetFolderPath");
return null;
}
if (!bRet)
{
int errorNum = Marshal.GetLastWin32Error();
HandleCeError(new WinCeException("SHGetSpecialFolderPath returned false, likely an invalid constant", errorNum), "GetSpecialFolderPath");
}
return sPath;
}
private static void HandleCeError(Exception ex, string method)
{
// logging
if (!ExceptionsEnabled)
{
return;
}
if (ex is NotSupportedException)
{
throw new WinCeException("Bad arguments or incorrect declaration in " + method, 0, ex);
}
if (ex is MissingMethodException)
{
throw new WinCeException("Entry point not found in " + method, 0, ex);
}
if (ex is WinCeException)
{
throw ex;
}
throw new WinCeException("Miscellaneous exception in " + method, 0, ex);
}
#region Properties
public static bool ExceptionsEnabled
{
get
{
return m_sbExceptionsEnabled;
}
set
{
m_sbExceptionsEnabled = value;
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I work for Bee Mobile.
Web site: http://beemobile4.net
Facebook site: http://facebook.com/BeeMobile
YouTube Channel: http://youtube.com/beemobile4dotnet