Windows Unicode相關

來源:互聯網
上載者:User

標籤:crt   pos   oca   res   param   har   unicode   attribute   back   

====標頭檔前後順序影響TCHAR定義===============================
windows.h winnt.h
tchar.h
======定義_UNICODE宏常量控制==================
//字元
typedef char TCHAR;
typedef wchar_t TCHAR;

字串
typedef __T(x) L##x
typedef __T(x) x

//C庫函數
#define _tcslen strlen
#define _tcslen wcslen
#define _tmain main
#define _tmain wmain
#define _tWinMain WinMain
#define _tWinMain wWinMain

=====定義UNICODE常量控制=========================
字元
typedef CHAR TCHAR
typedef WCHAR TCHAR
字串
#define __TEXT(x) L##x
#define __TEXT(x) x

typedef LPSTR PTSTR, LPTSTR;
typedef LPWSTR PTSTR, LPTSTR;

//系統函數
#define MessageBox MessageBoxA
#define MessageBox MessageBoxW

=====在tchar.h中定義======================
TCHAR
__T(x)
#define _T(x) __T(x)
#define _TEXT(x) __T(x)

//C庫函數
_tcslen
_tmain
_tWinMain

======在winnt.h中定義======================
//字元
TCHAR

typedef char CHAR;
typedef wchar_t WCHAR;

//字串
__TEXT(x)
#define TEXT(x) __TEXT(x)

PTSTR, LPTSTR

補充:
mainCRTStartup()/wmainCRTStartup() 位於C運行庫,它先執行,然後調用main()/wmain();
//main入口
int _tmain(void);
int _tmain(int argc, TCHAR **argv);
int _tmain(int argc, TCHAR *argv[]);
當進入點是WinMain,執行程式開始於WinMainCRTStartup,同理wWainMain,其開始在wWinMainCRTStartup
//WinMain入口
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);

window API字串函數
字串長度
int WINAPI lstrlenA(LPCSTR lpString);
int WINAPI lstrlenW(LPCWSTR lpString);
拼接字串
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2);
字串大小寫轉換
LPWSTR WINAPI CharLowerW(LPWSTR lpsz);
LPWSTR WINAPI CharUpperW(LPWSTR lpsz);


MultiByteToWideChar WideCharToMultiByte

BOOL StringReverseA(PSTR pMultiByteStr)
{
PWSTR pWideCharStr;
int nLenOfWideCharStr;
BOOL fOk = FALSE;

nLenOfWideCharStr = MultiRyteToWideChar(CP_ACP, 0,pMultiByteStr, -1, NULL, 0);

pWideCharStr = HeapAlloc(GetProcessHeap(), 0, nLenOfWideCharStr * sizeof(WCHAR));

 

MultiByteToWideChar(CP_ACP, 0, pMulti8yteStr, -1, pWideCharStr, nLenOfWideCharStr);

fOk = StnngReverseW(pWideCharStr);
if (fOk)
{
//Convert the wide-character string back
//to a multibyte string.
WideCharToMultiByte(CP_ACP, 0, pWideCharStr, -1,
pMultiByteStr, strlen(pMultiByteStr), NULL, NULL);
}
HeapFree(GetProcessHeap(), 0, pWideCharStr);

return(fOk),
}


FormatMessage

//Get the error code
DWORD dwError = GetDlgItemInt(hwnd, IDC_ERRORCODE, NULL, FALSE);

//Buffer that gets the error message string
HLOCAL hlocal = NULL;

//Get the error code‘s textual description
BOOL fOk = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(PTSTR)&hlocal, 0, NULL);

if (hlocal != NULL)
{
SetDlgItemText(hwnd, IDC_ERRORTEXT, (PCTSTR)LocalLock(hlocal));
LocalFree(hlocal);
}
else
SetDlgItemText(hwnd, IDC_ERRORTEXT,
TEXT("Error number not found."));


PTSTR GetCommandLine();
HMODULE GetModuleHandle( PCTSTR pszModule);

 

BOOL CreateProcess(
PCTSTR pszApplicationName,
PTSTR pszCommandLine,
PSECURITY_ATTRIBUTES psaProcess,
PSECURITY_ATTRIBUTES psaThread,
BOOL bInheritHandles,
DWORD fdwCreate,
PVOID pvEnvironment,
PCTSTR pszCurDir,
PSTARTUPINFO psiStartInfo,
PPROCESS_INFORMATION ppiProcInfo);
VOID GetStartupInfo(LPSTARTUPINFO pStartupInfo);
OSVERSIONINFOEX os = { 0 };
os.dwOSVersionInfoSize = sizeof(os);

GetVersionEx((LPOSVERSIONINFOA)&os);

printf("%u - %u - %u - %u - %s - %hu - %hu - %hu - %d \n",
os.dwMajorVersion,os.dwMinorVersion,os.dwBuildNumber,
os.dwPlatformId,os.szCSDVersion,
os.wServicePackMajor,os.wServicePackMinor,os.wSuiteMask,
os.wProductType);

DWORD WINAPI ThreadFunc(PVOID pvParam)
{
DWORD dwResult = 0;
...
return(dwResult);
}

HANDLE CreateThread(
PSECURITY_ATTRIBUTES psa,
DWORD cbStack,
PTHREAD_START_ROUTINE pfnStartAddr,
PVOID pvParam,
DWORD fdwCreate,
PDWORD pdwThreadID);
_beginthreadex


DWORD GetCurrentProcessId();
DWORD GetCurrentThreadId();
HANDLE GetCurrentProcess();
HANDLE GetCurrentThread();
GetProcessTimes
GetThreadTimes

__int64 FileTimeToQuadWord(PFILETIME pft)
{
return (Int64ShllMod32(
pft->dwHighDateTime, 32) | pft->dwLowDateTime);
}

GetThreadTimes

u_long argp = 1L;
int nRet = ioctlsocket(s, FIONBIO, (u_long far*)&argp); //非阻塞模式
if(nRet == SOCKET_ERROR)
return ;

#include <windows.h>
#include <tchar.h>

int _tmain(int argc, TCHAR *argv[])
{
PDWORD cChars = NULL;
HANDLE std = GetStdHandle(STD_OUTPUT_HANDLE);

if (std == INVALID_HANDLE_VALUE) {
_tprintf(L"Cannot retrieve standard output handle\n (%d)",
GetLastError());
}

WriteConsole(std, argv[1], _tcslen(argv[1]), cChars, NULL);

return EXIT_SUCCESS;
}

Windows Unicode相關

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.