|
-
May 24th, 2009, 01:50 PM
#1
.NET to COM to Native string passing
Hi,
I have a problem which I can't figure out. I have code in C# which calls a native function via COM interface.
I have an object which I serialize to XML, then pass the string to the native C++ code which I use mxsml (4) to handle.
The flow is:
Code:
//--- C#
MemoryStream memStream = new MemoryStream();
myObject.ExportToXml(memStream);
/* Inside there is something like this:
{
XmlTextWriter xmlWriter = new XmlTextWriter(memStream, null);
// here I build the XML
}
*/
string xmlString = Encoding.UTF8.GetString(memStream.ToArray());
//--- COM C++
myComObject.passXmlOn(xmlString); // MyComObject::passXmlOn(BSTR)
// here the native object is accessed and handleXml is called
//--- Native C++
myNativeObj.handleXml(xmlString); // MyNativeObj::handleXml(wstring)
// here MSXML2::DOMDocument40::loadXml(xmlString) is called
At this point I try to create an MSXML object, and it fails.
However, when I write the XML to file (I pass FileStream to my ExportToXml) and then I create the MSXML in the native code from the same file, everything works fine.
Code:
FileStream fileStream = new FileStream(someFileLocation);
myObject.ExportToXml(fileStream);
//--- COM C++
myComObject.readXml();
// here the native object is accessed and handleXml is called
//--- Native C++
myNativeObj.handleXml(); // MyNativeObj::handleXml()
// here MSXML2::DOMDocument40::load(someFileLocation) is called
Any ideas?
Thanks,
sperlis
"Let's code quickly now, so we'll have time to debug later"
-
May 25th, 2009, 05:50 AM
#2
Re: .NET to COM to Native string passing
For case nobody more competen won't answer, I would think the string passed to COM library should be treated by Marshal class. Try to look at Marshal.StringToBSTR() method.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|