本文介绍了x64和BSTR分配,有什么变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在win32模式下,BSTR的UINT长度为前缀,并且完全由 零字符终止。 因此,如果您分配了Hello World,那么这将分配28个字节。 在x64和(IA64也是如此)它将变成32个字节,因为 a指针,是8个字节而不是4个字节。 长度前缀-still-是UINT而不是UINT_PTR。 但似乎我'还不太完美。还有其他 信息或规则在win32 BSTR分配之上发生了变化吗? 谢谢! 解决方案 你如何得出这个结论?指针在哪里进入? BSTR? Dave ok, 我会解释一下。 不是指针-itself-进入但是指针指向UINT长度 前缀。 在X64和IA64上,指针是-not-到UINT长度前缀,但是到 UINT_PTR长度前缀。 但是......但是,如果你想要长度,你需要一个UINT前缀,而不是一个 UINT_PTR前缀。 我不是说这个,只是犹豫。也许有人知道真实的事实... BSTR __stdcall SysAllocString(const OLECHAR *输入) { PWSTR retval = NULL; if(输入!= NULL) { UINT_PTR slen = lstrlenW(输入); UINT_PTR newlen = slen * sizeof(OLECHAR)+ sizeof(UINT_PTR)+ sizeof(OLECHAR); PWSTR temp = NULL; temp =(PWSTR):: CoTaskMemAlloc(newlen); if(temp!= NULL) { UINT * plen =(UINT *)temp; plen [0] =(UINT)slen * sizeof(OLECHAR); retval =& temp [sizeof( UINT_PTR)/ sizeof(OLECHAR)]; if(slen> 0) CopyMemory(retval,input,(slen + 1)* sizeof(OLECHAR)); } } 返回retval; } Dave 好的, 我会解释一下。 不是指针-itself-进入但是指针指向UINT长度前缀。 在X64和IA64上,指针是-not-到UINT长度前缀,但是一个 UINT_PTR长度前缀。 所以,你说在64位平台上,BSTR有一个8字节 长度部分而不是4字节长度?如果它是,我会感到惊讶。 我在MSDN文档中没有看到任何有关该假设的证据 或头文件。 SysStringLen定义为返回UINT而不是 UINT_PTR。 Dave In win32 mode, a BSTR was UINT length prefixed and terminated exactly by azero char.So if you allocated "Hello World" that would allocate 28 bytes.In x64 and (IA64 as well) it would become 32 bytes, because of the fact thata pointer, is 8 bytes instead of 4 bytes.The length prefix -still- is a UINT however and not a UINT_PTR.But it seems that I''m still not quite complete on par. Is there any otherinfo or rules that have changed on top off the win32 BSTR allocations?Thanks! 解决方案How do you come to that conclusion? Where does a pointer come into aBSTR?Daveok,I''ll explain this.Not the pointer -itself- comes into but the pointer is to the UINT lengthprefix.On X64 and IA64, the pointer is -not- to the UINT length prefix, but to aUINT_PTR length prefix.But but... however, if you want the length, you need a UINT prefix, not aUINT_PTR prefix.I''m not stating this, just hesitating. Maybe someone knows the real facts...BSTR __stdcall SysAllocString(const OLECHAR * input){PWSTR retval = NULL;if (input != NULL){UINT_PTR slen = lstrlenW(input);UINT_PTR newlen = slen * sizeof(OLECHAR)+ sizeof(UINT_PTR) +sizeof(OLECHAR);PWSTR temp = NULL;temp = (PWSTR)::CoTaskMemAlloc(newlen);if (temp != NULL){UINT* plen = (UINT*)temp;plen[0] = (UINT)slen * sizeof(OLECHAR);retval = &temp[sizeof(UINT_PTR) / sizeof(OLECHAR)];if (slen > 0)CopyMemory(retval, input, (slen + 1) * sizeof(OLECHAR));}}return retval;} Dave ok,I''ll explain this.Not the pointer -itself- comes into but the pointer is to the UINT lengthprefix.On X64 and IA64, the pointer is -not- to the UINT length prefix, but to aUINT_PTR length prefix.So, you''re saying that on 64-bit platforms, a BSTR has an 8 bytelength portion rather than a 4 byte length? I''d be surprised if itwas.I don''t see any evidence for that assumption in the MSDN documentationor the header files. SysStringLen is defined to return an UINT notUINT_PTR.Dave 这篇关于x64和BSTR分配,有什么变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 05:27