简体   繁体   English

LPWSTR,wchar_t *和C ++中的无符号短指针

[英]LPWSTR, wchar_t* and unsigned short pointer in C++

I'm trying to understand if these types are all the same. 我试图了解这些类型是否完全相同。 I have this function from windows.h : GetCommandLine() , in UNICODE mode, and it returns a LPWSTR . 我在windows.h中有这个函数: GetCommandLine() ,在UNICODE模式下,它返回一个LPWSTR Now, if I dig deeper I can see how LPWSTR is wchar_t* and if I go even further, I find out that wchar_t is unsigned short (16 bytes) or unsigned long (32 bytes). 现在,如果我深入挖掘,我可以看到LPWSTR是如何wchar_t* ,如果我更进一步,我发现wchar_tunsigned short (16字节)或unsigned long (32字节)。 Yet, if I do this: 但是,如果我这样做:

unsigned short* SysComm = GetCommandLine();

I get this error: 我收到此错误:

cannot convert from 'LPWSTR {aka wchar_t*} to 'short unsigned int*' in initialization 在初始化中无法从'LPWSTR {aka wchar_t *}转换为'short unsigned int *'

So, does the compiler follow the same logic to find out that LPWSTR is unsigned short* in the end or am I wrong? 那么,编译器是否遵循相同的逻辑来发现LPWSTRunsigned short*还是我错了?

wchar_t is a distinct type that is defined to have the same properties as one of the other integer types. wchar_t是一个不同的类型,被定义为具有与其他整数类型相同的属性。

Type wchar_t is a distinct type [...]. 类型wchar_t是一种独特的类型[...]。 Type wchar_t shall have the same size, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlying type . 类型wchar_t应具有与其他整数类型之一相同的大小,符号和对齐要求(3.11),称为其基础类型

So you can't implicitly convert from a wchar_t* to a short* just as much as from an int* to a short* . 因此,您无法隐式地将wchar_t*转换为short* ,就像从int*转换为short*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM