某些apis需要字符數。字節數與字符數計數
// Why did they choose cch in these functions.
HRESULT StringCchCopyW(
__out LPWSTR pszDest,
__in size_t cchDest,
__in LPCWSTR pszSrc
);
errno_t wcscpy_s(
wchar_t *strDestination,
size_t numberOfElements,
const wchar_t *strSource
);
DWORD WINAPI GetCurrentDirectoryW(
__in DWORD nBufferLength, // Count of Chars
__out LPWSTR lpBuffer
);
,而某些API需要的字節數。
// What do you prefer cch vs cb function.
// Do cch functions almost useful?
HRESULT StringCbCopyW(
__out LPWSTR pszDest,
__in size_t cbDest,
__in LPCWSTR pszSrc
);
BOOL WINAPI ReadFile(
__in HANDLE hFile,
__out LPVOID lpBuffer,
__in DWORD nNumberOfBytesToRead,
__out_opt LPDWORD lpNumberOfBytesRead,
__inout_opt LPOVERLAPPED lpOverlapped
);
// Why did they choose cb in these structures.
// Because there are some apis uses cb, I always should see MSDN.
typedef struct _LSA_UNICODE_STRING {
USHORT Length; // Count of bytes.
USHORT MaximumLength; // Count of bytes.
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
typedef struct _FILE_RENAME_INFO {
BOOL ReplaceIfExists;
HANDLE RootDirectory;
DWORD FileNameLength; // Count of bytes.
WCHAR FileName[1];
} FILE_RENAME_INFO, *PFILE_RENAME_INFO;
當你設計一個功能或數據結構,你如何確定CB或CCH?爲什麼?
要爲呼叫者設計更好的api,我應該知道什麼?
UNICODE_STRING的解釋非常好。 – Benjamin 2011-01-28 06:23:23
*字節數通常無用。*爲什麼?你能解釋一下嗎? – Benjamin 2011-01-28 08:29:36