|
Hi fellows
I'm developed an app that generates a xml file with some nodes.
it works file, but a little different thing is occuring: the nodes and the filename are saved with chinese(or japanese, I don't know) characters.
I have a function that transforms a string to BSTR. I've verified if the functions works fine and it works, It doesn't convert to chinese os japanese chars. If I define BSTR in the SaveXML function the nodes are saved correctly.
I think that the problem occurs in my conversion to BSTR, but I'm not 100% certainly.
This is the code:
<br />
void myClass::SaveTheXML()<br />
{<br />
BSTR string; <br />
BSTR theString, theString2; <br />
VARIANT theVar, theVar2; <br />
string = L"teste.xml"; <br />
theString = L"arquivo"; <br />
theString2 = L"valor"; <br />
VariantInit(&theVar); <br />
VariantInit(&theVar2); <br />
V_BSTR(&theVar) = SysAllocString(string); <br />
V_BSTR(&theVar2) = SysAllocString(theString2); <br />
V_VT(&theVar) = VT_BSTR; <br />
V_VT(&theVar2) = VT_BSTR; <br />
parent = CreateXMLElement(sNode1); <br />
child = CreateXMLElement(sNode2); <br />
xmlDocument->createElement(L"primeiro", &parent); <br />
xmlDocument->createElement(L"segundo", &child); <br />
InsertChildNode(parent, child); <br />
InsertChildNode(xmlDocument, parent); <br />
xmlDocument->save(ReturnVariantString(xmlFileName));<br />
}<br />
So, fellows what's going on? Thanks a lot for the support. Below the code that I developed:
<br />
void myClass::InsertChildNode(IXMLDOMNode * parentNode, IXMLDOMNode * childNode) <br />
{ <br />
IXMLDOMNode * localNode = NULL; <br />
handleResult = parentNode->appendChild(childNode, &localNode); <br />
if(localNode == NULL)<br />
{<br />
MessageBox(NULL, "Erro na inserção do node", "Erro", MB_OK|MB_ICONERROR);<br />
return;<br />
}<br />
} <br />
void myClass::SaveTheXML()<br />
{ <br />
string sNode1, sNode2, xmlFileName, sAttribName, sAttribValue; <br />
IXMLDOMAttribute * tempAttribute = NULL; <br />
sNode1 = "primeiro"; <br />
sNode2 = "segundo"; <br />
xmlFileName = "teste.xml"; <br />
sAttribName = "arquivo"; <br />
sAttribValue = "valor"; <br />
parent = CreateXMLElement(sNode1); <br />
child = CreateXMLElement(sNode2); <br />
theAttribute = CreateXMLAttribute(sAttribName, sAttribValue); <br />
child->setAttributeNode(theAttribute, &tempAttribute); <br />
InsertChildNode(xmlDocument, theAttribute); <br />
InsertChildNode(parent, child); <br />
InsertChildNode(xmlDocument, parent); <br />
xmlDocument->save(ReturnVariantString(xmlFileName)); <br />
} <br />
<br />
VARIANT myClass::ReturnVariantString(string sNodeName) <br />
{ <br />
VARIANT variant;<br />
VariantInit(&variant); <br />
V_BSTR(&variant) = SysAllocString(StringToBSTR(sNodeName)); <br />
V_VT(&variant) = VT_BSTR; <br />
return variant; <br />
}<br />
<br />
IXMLDOMElement * myClass::CreateXMLElement(string sNodeName)<br />
{ <br />
IXMLDOMElement * xmlElement = NULL; <br />
BSTR sTemp = StringToBSTR(sNodeName); <br />
handleResult = xmlDocument->createElement(sTemp, &xmlElement); <br />
if(xmlElement == NULL)<br />
{<br />
MessageBox(NULL, "Erro na criação do node", "Erro", MB_OK|MB_ICONERROR); return NULL;<br />
} <br />
return xmlElement;<br />
}<br />
IXMLDOMAttribute * myClass::CreateXMLAttribute(string sAttributeName, string sAttributeValue)<br />
{ <br />
IXMLDOMAttribute * theAttribute = NULL; <br />
xmlDocument->createAttribute(StringToBSTR(sAttributeName), &theAttribute); <br />
handleResult = theAttribute->put_value(ReturnVariantString(sAttributeValue)); <br />
if(handleResult != S_OK)<br />
{<br />
MessageBox(NULL, "Erro na criação do atributo do node", "Erro", MB_OK);return NULL;<br />
} <br />
return theAttribute;<br />
}<br />
<br />
BSTR myClass::StringToBSTR(string sValue)<br />
{<br />
BSTR sTemp = (BSTR)(const char *)sValue.c_str(); <br />
return sTemp;<br />
}<br />
|
|
|
|
|
Alex Cutovoi wrote: BSTR myClass::StringToBSTR(string sValue)
{
BSTR sTemp = (BSTR)(const char *)sValue.c_str();
return sTemp;
}
This will give you interesting results at best. The reason is that BSTRs have to be allocated (you haven't allocated anything in this method). A replacement would be:
_bstr_t myClass::StringToBSTR(const std::string& value)
{
_bstr_t bstrValue(value.c_str());
return bstrValue;
}
You can pass _bstr_t's into MSXML's method calls because it overrides the BSTR() operator for you.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
-- modified at 16:36 Wednesday 5th July, 2006
|
|
|
|
|
Two questions Zac:
1)What's the _bstr_t?Is it a private variable that I must to declare?I tried this and doesn't work.
2)I don't understand this: bstrValue(value.c_str()); What is the bstrValue?
|
|
|
|
|
_bstr_t is a helper class that Microsoft wrote. Check here for the documentation.
Line by line, the code I wrote does the following:
_bstr_t myClass::StringToBSTR(const std::string& value)
{
_bstr_t bstrValue(value.c_str());
return bstrValue;
}
I believe I forgot the return line in the previous post ... sorry about that.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
You are not creating BSTR s correctly - a BSTR is not simply a pointer to an array like a C-style string is. See my string article[^] - look at the "String in COM" section.
Tom make things easier, you could use a wrapper like _bstr_t or CComBSTR .
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
Hi all,
When i use create() to raise a modeless dialog
the compiler tells me i can't use create() with no arguments.
What is the correct way to do that ?
Thanx in advance,
Desmo16.
|
|
|
|
|
hDlgModeless=CreatDialog(hInstance,szTemplate,hwndParent,DialogProc);
|
|
|
|
|
For either of the methods:
BOOL Create( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL );
BOOL Create( UINT nIDTemplate, CWnd* pParentWnd = NULL ); You must specify at least a template name or a template id.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Press F1 ... or go here.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Desmo16 wrote: What is the correct way to do that ?
They hide that information in the DOCUMENTATION
|
|
|
|
|
a minimum parameters is id from dialog
Create(IDD_DIALOG);
whitesky
|
|
|
|
|
Hey guys,
I tried searching for static unsigned int on Google but I get a lot of gibberish answers.
It would be greatly appreciated if someone can give me a brief description about it because the document im trying to understand is full of static unsigned integers
Thanks
|
|
|
|
|
The key here is 'static'. It tells system to allocate memory for the static variable in heap, rather than stack. So the value of the variable can be retrieved globally.
|
|
|
|
|
No, static tells the compiler to allocate the memory in the static memory area. new, malloc, etc, allocate from the heap.
--
Presented in doublevision (where drunk)
|
|
|
|
|
|
ask a more precise question here, and you'll have concise answers...
static is a keyword that have different meaning depending on the place it's used.
unsigned int is a data type, and here again, can have different meaning depending on how it's used
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
toxcct wrote: unsigned int is a data type, and here again, can have different meaning depending on how it's used
Uh, no? unsigned int is always a unsigned int .
--
Coming Soon to an Illegal DVD
|
|
|
|
|
as i understand it, i think toxcct meant that it could be either used in a variable declaration/definition, type casts, function returns...
but maybe it's just me, and i misunderstood
-- TTD --
|
|
|
|
|
Maybe so..
--
As Foretold by Nostradamus
|
|
|
|
|
Hi Everybody,
I need to run a command driven program in a MFC application. Then I include "WinExec("commandprogram param1 param2",SW_HIDE)" in the MFC application. The problem is the command driven program has a scanf() function, but I know the value needs to be entered and I don't want to input the value manually again. How can I pass the value to scanf() without inputing any value in the keyboard? I don't want to rewrite the function in the command driven program. Thank you very much.
Gavin
|
|
|
|
|
I don't know what WinExec supports but some spawning functions support attaching to the child process IO streams so that might work for you.
|
|
|
|
|
Have you tried I/O redirection: "commandprogram param1 param2 < input_string" in your WinExec call?
Best,
Jun
|
|
|
|
|
Thanks Jun and led.
Best,
Gavin
|
|
|
|
|
Hi there,
Can anyone give me some info or link about how I can manipulate the GPS (lat, long) sent from a device to mappoint so that the location of the vehicle can be traceable in mappoint?
what mappoint requires as input for this purpose and what should be the interface between the device and mappoint?
Right now I have an application that receives data (text message, GPS and so on)from some devices and sends it to another application as XML format and also can recive data in XML format from the second applicaton and sends it to the device inside the vehicle. The device in the vehicle sends GPS info upon request and I need to send it to mappoint to trace the vehicle there. I was wondring what would be the interface between my application and mappoint.
I appreciate all the suggestions.
regrads,
Nahitan
|
|
|
|
|