Windows Unicode相关

====头文件前后顺序影响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);

 

/SUBSYSTEM

link 指定/DLL 入口点DllMainCRTStartup 调用 DllMain  __stdcall调用方式

 

带dos调试窗口的win32程序
#pragma comment( linker, "/subsystem:console /entry:WinMainCRTStartup")

 

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;
}

posted @ 2017-06-26 03:49  呵呵··  阅读(340)  评论(0编辑  收藏  举报