标签:code get strong string set 工作
1.The GetCurrentDirectory function retrieves the current directory for the current process
DWORD GetCurrentDirectory( DWORD nBufferLength, // size of directory buffer
LPTSTR lpBuffer // directory buffer);
用法:
TCHAR tszModule[MAX_PATH ] = { 0 };
::GetCurrentDirectory(MAX_PATH, tszModule);
2.The GetModuleFileName function retrieves the fully qualified path for the specified module.
DWORD GetModuleFileName( HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer DWORD nSize // size of buffer);
用法:
TCHAR tszModule[MAX_PATH + 1] = { 0 };
::GetModuleFileName(NULL, tszModule, MAX_PATH);
3.
(1) char* 转到 wchar*
The MultiByteToWideChar function maps a character string to a wide-character (Unicode) string. The character string mapped by this function is not necessarily from a multibyte character set.
int MultiByteToWideChar( UINT CodePage, // code page
DWORD dwFlags, // character-type options
LPCSTR lpMultiByteStr, // string to map
int cbMultiByte, // number of bytes in string
LPWSTR lpWideCharStr, // wide-character buffer
int cchWideChar // size of buffer);
用法:
#define MAX_PATH 260
::MultiByteToWideChar(CP_ACP,0,(const char *)CStr,-1,tszModule,MAX_PATH);
CStr将被转换字符串的字符
-1指的是CStr以空字符终止
tszModule 指向接收被转换字符串的缓冲区
MAX_PATH 指向的缓冲区的宽字符个数
(2) wchar* 转 到 char*
TCHAR tszModule[MAX_PATH ] = { 0 };
::GetCurrentDirectory(MAX_PATH, tszModule);
size_t len = wcslen(tszModule) + 1;
size_t converted = 0;
char CStr[MAX_PATH];
wcstombs_s(&converted, CStr, len, tszModule, _TRUNCATE);
标签:code get strong string set 工作
原文地址:http://www.cnblogs.com/chechen/p/3791637.html