简体   繁体   English

GlobalAlloc说明

[英]GlobalAlloc explanation

(char*)GlobalAlloc(GPTR, len + 1);

This is the line of code in question, which I'm using from a tutorial. 这是有问题的代码行,我正在教程中使用。 I'm reading from an EDITTEXT . 我正在从EDITTEXT阅读。 I'd mostly like to know where GPTR came from, and what it's for. 我最想知道GPTR来源以及用途。 It hasn't been defined anywhere else in the code. 在代码的其他任何地方都没有定义它。

I've got a basic understanding of the rest of the line, but MSDN 's explanation isn't quite clear. 我对该行的其余部分有基本的了解,但是MSDN的解释尚不清楚。 They say this: 他们说:

HGLOBAL WINAPI GlobalAlloc(
  __in  UINT uFlags,
  __in  SIZE_T dwBytes
);

Could someone explain in plain English where GPTR is from, what it's for, and how it relates to __in UINT uFlags ? 有人可以用简单的英语解释GPTR的来源,用途以及与__in UINT uFlags吗? I know it's an unsigned int but then the knowing stops. 我知道这是一个unsigned int但是知道就停止了。

Thanks in advance. 提前致谢。

GPTR is athe combination of GMEM_FIXED and GMEM_ZEROINIT(OR). GPTR是GMEM_FIXED和GMEM_ZEROINIT(OR)的组合。

uFlags uFlags
The memory allocation attributes. 内存分配属性。 If zero is specified, the default is GMEM_FIXED. 如果指定零,则默认值为GMEM_FIXED。 This parameter can be one or more of the following values, except for the incompatible combinations that are specifically noted. 除特别指出的不兼容组合外,此参数可以是以下一个或多个值。

Value Meaning 值含义
GHND 0x0042 Combines GMEM_MOVEABLE and GMEM_ZEROINIT. GHND 0x0042组合了GMEM_MOVEABLE和GMEM_ZEROINIT。
GMEM_FIXED 0x0000 Allocates fixed memory. GMEM_FIXED 0x0000分配固定内存。 The return value is a pointer. 返回值是一个指针。
GMEM_MOVEABLE 0x0002 Allocates movable memory. GMEM_MOVEABLE 0x0002分配可移动内存。 Memory blocks are never moved in physical memory, but they can be moved within the default heap. 内存块永远不会在物理内存中移动,但是可以在默认堆中移动它们。 This value cannot be combined with GMEM_FIXED. 该值不能与GMEM_FIXED结合使用。
GMEM_ZEROINIT 0x0040 Initializes memory contents to zero. GMEM_ZEROINIT 0x0040将内存内容初始化为零。
GPTR 0x0040 Combines GMEM FIXED and GMEM_ZEROINIT. GPTR 0x0040组合了GMEM FIXED和GMEM_ZEROINIT。

Refer here 请参考这里

GPTR 0x0040 Combines GMEM_FIXED and GMEM_ZEROINIT. GPTR 0x0040组合了GMEM_FIXED和GMEM_ZEROINIT。

As you can see, it is just a bit pattern (0x0040) and can be combined with other permissible flags 如您所见,它只是位模式(0x0040),可以与其他允许的标志结合使用

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

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