将 OEM 定义的字符集中的字符串转换为 ANSI 或宽字符字符串。
Syntax
BOOL OemToCharW(
[in] LPCSTR pSrc,
[out] LPWSTR pDst
);
Parameters
[in] pSrc
Type: LPCSTR
OEM 定义的字符集中以 null 结尾的字符字符串。
[out] pDst
Type: LPTSTR
接收已转换字符串的目标缓冲区。 If the OemToChar function is being used as an ANSI function, the string can be translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter. This cannot be done if OemToChar is being used as a wide-character function.
Return value
Type: BOOL
The return value is always nonzero except when you pass the same address to lpszSrc and lpszDst in the wide-character version of the function. In this case the function returns zero and GetLastError returns ERROR_INVALID_ADDRESS.
Remarks
Security Considerations
错误地使用此函数可能会损害程序的安全性。 For example, miscalculating the proper size of the lpszDst buffer, especially when the application is used in both ANSI and Unicode versions, can cause a buffer overflow. 有关详细信息,请参阅安全注意事项:国际功能和安全注意事项:Windows 用户界面。
Note
winuser.h 标头将 OemToChar 定义为一个别名,该别名根据 UNICODE 预处理器常量的定义自动选择此函数的 ANSI 或 Unicode 版本。 将中性编码别名与不中性编码的代码混合使用可能会导致编译或运行时错误不匹配。 有关详细信息,请参阅函数原型的
Requirements
Requirement | Value |
---|---|
最低支持的客户端 | Windows 2000 Professional [仅限桌面应用] |
支持的最低服务器 | Windows 2000 Server [仅限桌面应用] |
Target Platform | Windows |
Header | winuser.h (包括 Windows.h) |
Library | User32.lib |
DLL | User32.dll |
API set | ext-ms-win-ntuser-chartranslation-l1-1-0(在 Windows 8 中引入) |
See also
Conceptual
Reference