私は C++ プログラミングが初めてで、xml ドキュメントへの書き込みに問題があります。
msdn ( http://msdn.microsoft.com/en-us/library/ms766497(VS.85).aspx ) の xml outputter の例を少し変更して使用しています。
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」のようなもののみを返します。これは、次の方法の1つでアクセス違反を引き起こします。誰かが私が失敗した場所を教えてくれたら本当に素晴らしいことです。
ありがとうございました。