Why is PCTSTR not defined but LPCTSTR defined?

南楼画角 提交于 2019-12-13 18:09:27

问题


I have been assigned to update an old code written in MSVC++ 6. I have been getting unknown definition for PCTSTR but it was not defined even if I included the tchar.h. In my previous experience I know there is an LPTSTR but no PCTSTR.

I grep the C:\Program Files\Microsoft Visual Studio\VC98\Include\ folder and did not found a definition of PCTSTR. But to my surprise when I searched the Windows SDK folder [C:\Program Files\Microsoft SDK] there was no definition of PCTSTR but it was used in one of the samples. [C:\Program Files\Microsoft SDK\Samples\winui\Resource\Iconpro*]. So I am guessing that this may just be a relic from the Windows API of 16-bit windows but I cannot find any thing from google.

Does anyone know what is the PCTSTR for. I am guessing since this was from an old code that this works before. Any ideas how to make this compile? [I changed this to LPCTSTR and it compiled, I want to know if there are other ways than changing the definition name]


回答1:


The LP in LPCTSTR means Long Pointer. It is an artifact back from the Windows 3 days, a 16 bit operating system. 16-bit code had several memory models to deal with trying to address more than 65536 bytes of memory when you only have a 16-bit cpu register. A short pointer used the default data segment register value and a 16-bit offset. A long pointer was 32-bits, 16-bits to load a segment register and 16-bits for the offset.

The T in LPCTSTR means TCHAR, a typedef for char or wchar_t, depending on the presence of the UNICODE macro.

Which makes PCTSTR a time anachronism, humans-and-dinosaurs movie style. There was never a 16-bit Unicode version of Windows, 32-bit versions of Windows always use 32-bit pointers. It sounds merely like a mistake. Enshrined though, the current version of winnt.h does have a typedef for it, making it the same as LPCTSTR. And used in only one place, the stralign.h header with a strange function named TSTR_ALIGNED_STACK_COPY. However only in a comment.

Mistake. Your workaround was the right choice.




回答2:


In Windows SDK v7.0a I have on my machine, WinNT.h contains two different typedefs for PCTSTR, depending on whether UNICODE is defined. In both cases, LPCTSTR is defined the same way - so these two are equivalent nowadays.



来源:https://stackoverflow.com/questions/9063401/why-is-pctstr-not-defined-but-lpctstr-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!