使用Win32 API连接字符串 [英] Concatenating a string using Win32 API

查看:377
本文介绍了使用Win32 API连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Win32连接字符串的最佳方法是什么?如果理解正确,通常的C方法是使用 strcat ,但是由于Win32现在处理Unicode字符串(aka LPWSTR ),我想不出 strcat 的处理方式。



有功能吗?为此,还是我应该自己写?

解决方案

lstrcat 带有ANSI和Unicode变体。实际上, lstrcat 只是一个定义为 lstrcatA lstrcatW 。



这些功能可通过导入 kernel32.dll 来使用。如果您试图完全避免使用C运行时库,则很有用。在大多数情况下,您可以按照罗伊(Roy)的说明使用 wcscat _tcscat



还要考虑使用 strsafe.h 函数,例如 StringCchCat 也有ANSI和Unicode变体,但它们有助于防止缓冲区溢出。 / p>

What's the best way to concatenate a string using Win32? If Understand correctly, the normal C approach would be to use strcat, but since Win32 now deals with Unicode strings (aka LPWSTR), I can't think of a way for strcat to work with this.

Is there a function for this, or should I just write my own?

解决方案

lstrcat comes in ANSI and Unicode variants. Actually lstrcat is simply a macro defined as either lstrcatA or lstrcatW.

These functions are available by importing kernel32.dll. Useful if you're trying to completely avoid the C runtime library. In most cases you can just use wcscat or _tcscat as roy commented.

Also consider the strsafe.h functions, such as StringCchCat These come in ANSI and Unicode variants as well, but they help protect against buffer overflow.

这篇关于使用Win32 API连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆