LPCWSTR代表什么,应该如何处理? [英] What does LPCWSTR stand for and how should it be handled with?

查看:290
本文介绍了LPCWSTR代表什么,应该如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,它是什么?我想它是一个指针(LPC意味着长指针常量),但W是什么意思?它是一个指向字符串的特定指针或指向特定字符串的指针吗?
例如我想关闭一个名为TestWindow的窗口。

First of all, what is it exactly? I guess it is a pointer (LPC means long pointer constant), but what does "W" mean? Is it a specific pointer to a string or a pointer to a specific string? For example I want to close a Window named "TestWindow".

HWND g_hTest;
LPCWSTR a;
*a = ("TestWindow");
g_hTest = FindWindowEx(NULL, NULL, NULL, a);
DestroyWindow(g_hTest);

代码是非法的,它不工作,因为const char [6]无法转换为CONST WCHAR。
我根本没有得到它。
我想要清楚地了解所有这些LPCWSTR,LPCSTR,LPSTR。我试图找到一些东西,但我更困惑。在msdn网站 FindWindowEx 被声明为

The code is illegal and it doesn't work since const char[6] cannot be converted to CONST WCHAR. I don't get it at all. I want to get a clear understanding of all these LPCWSTR, LPCSTR, LPSTR. I tried to find something , however I got confused even more. At msdn site FindWindowEx is declared as

HWND FindWindowEx(      
    HWND hwndParent,
    HWND hwndChildAfter,
    LPCTSTR lpszClass,
    LPCTSTR lpszWindow
);

所以最后一个参数是LPCSTR,编译器需要LPCWSTR。
请帮助。

So the last parameter is LPCSTR, and the compiler demands on LPCWSTR. Please help.

推荐答案

LPCWSTR 代表Long指针到恒定宽字符串。 W代表Wide,意味着字符串存储在一个2字节字符与正常 char 中。 =

LPCWSTR stands for "Long Pointer to Constant Wide String". The W stands for Wide and means that the string is stored in a 2 byte character vs. the normal char. Common for any C/C++ code that has to deal with non-ASCII only strings.=

为了得到一个普通的C字符串赋值给一个 LPCWSTR ,您需要在它前面加上L

To get a normal C literal string to assign to a LPCWSTR, you need to prefix it with L

LPCWSTR a = L"TestWindow";

这篇关于LPCWSTR代表什么,应该如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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