C++ CLI 可變參數
namespace TK
{
public enum class LogLevel { Kernel, Fatal, Error, Warning, Infomation, Debug};
public ref class LogHelper
{
public:
static bool Open(String^ filename);
static void Close();
static bool Write(LogLevel level,String^ format,
array<Object^>^ args);
static bool WriteLine(LogLevel level,String^ format,
array<Object^>^ args);
static void SetLevel(LogLevel level);
};
}
static void MarshalString(String^ net, CString& os) {
LPCTSTR chars = (LPCTSTR)(Marshal::StringToHGlobalUni(net)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
#pragma unmanaged
static CStringA CStrW2CStrA(const CStringW &cstrSrcW)
{
int len = WideCharToMultiByte(CP_UTF8, 0, LPCWSTR(cstrSrcW), -1, NULL, 0, NULL, NULL);
char *str = new char[len];
memset(str, 0, len);
WideCharToMultiByte(CP_UTF8, 0, LPCWSTR(cstrSrcW), -1, str, len, NULL, NULL);
CStringA cstrDestA = str;
delete[] str;
return cstrDestA;
}
#pragma managed
{
public enum class LogLevel { Kernel, Fatal, Error, Warning, Infomation, Debug};
public ref class LogHelper
{
public:
static bool Open(String^ filename);
static void Close();
static bool Write(LogLevel level,String^ format,

static bool WriteLine(LogLevel level,String^ format,

static void SetLevel(LogLevel level);
};
}
static void MarshalString(String^ net, CString& os) {
LPCTSTR chars = (LPCTSTR)(Marshal::StringToHGlobalUni(net)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
#pragma unmanaged
static CStringA CStrW2CStrA(const CStringW &cstrSrcW)
{
int len = WideCharToMultiByte(CP_UTF8, 0, LPCWSTR(cstrSrcW), -1, NULL, 0, NULL, NULL);
char *str = new char[len];
memset(str, 0, len);
WideCharToMultiByte(CP_UTF8, 0, LPCWSTR(cstrSrcW), -1, str, len, NULL, NULL);
CStringA cstrDestA = str;
delete[] str;
return cstrDestA;
}
#pragma managed
posted on 2016-09-01 14:48 天下 閱讀(540) 評論(0) 編輯 收藏 引用 所屬分類: C/C++ 、C#