- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 C++ 编程的新手,我在写入 xml 文档时遇到了问题。
我使用的是来自 msdn ( http://msdn.microsoft.com/en-us/library/ms766497(VS.85).aspx ) 的 xml 输出器的一个稍微改变的例子。
HRESULT CreateAndAddTestMethodNode(string name)
{
HRESULT hr = S_OK;
IXMLDOMElement* pElement = NULL;
CHK_HR(CreateAndAddElementNode(pXMLDom, L"method", L"\n\t", pClass, &pMethod));
CHK_HR(CreateAndAddAttributeNode(pXMLDom, L"name", stringToPCWSTR(name), pMethod));
//more Attribute Nodes (deleted for better overview ;) )
CleanUp:
SAFE_RELEASE(pMethod);
return hr
}
我给 CreateAndAddTestMethodNode 一个字符串,它用 stringtopcwstr 将它转换为 pcwstr,或者应该这样做。
//convert string to pcwstr
PCWSTR stringToPCWSTR (const std::string& str)
{
int len;
int slength = (int)str.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, buf, len);
std::wstring result(buf);
delete[] buf;
PCWSTR pResult = result.c_str();
return pResult;
}
但它只返回类似“0x00BB9908” ﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮ”,在下一个方法之一中引起访问违规。如果有人能告诉我我失败的地方,那就太好了。
谢谢。
最佳答案
c_str()
的结果与 result
字符串一起被销毁(当它超出范围时)。您将需要为其显式分配内存。
关于c++ - 字符串到 PCWSTR -> 奇怪的返回(C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2361523/
我对 C++ 有点生疏,所以我正在寻求有关字符串指针问题的帮助。 首先,让我们考虑一些关于整数的指针基础知识: void SetBob(int* pBob) { *pBob = 5; } in
根据我的理解(如果我错了请纠正我),它们之间的唯一区别是字符串是否可以被调用的函数修改。 ( PCWSTR , LPWSTR ) 我现在正尝试将字符串从 C# 传递到需要 PCWSTR 的函数,但我能
我是 C++ 编程的新手,我在写入 xml 文档时遇到了问题。 我使用的是来自 msdn ( http://msdn.microsoft.com/en-us/library/ms766497(VS.8
我正在用我下载的一些代码重写一个 C++ 方法。该方法最初将 PCWSTR 作为参数,然后提示用户输入文件名。我修改了方法以采用两个参数(均为 PCWSTR)并且不提示用户。我已经在其他地方生成文件列
我有以下方法: VariantFromString(strXMLPath ,vXMLSource); 方法的签名是: HRESULT VariantFromString(PCWSTR wszV
我正在尝试创建一个文件,其中一个参数已传递给该方法并且属于 PCWSTR 类型。我的代码创建了一个 .url 文件并将 Url 保存到文件中: wchar_t array1[] = "
SHSTDAPI SHCreateItemFromParsingName( PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void
我是一名优秀的程序员,十分优秀!