471,318 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

dll call by passing XMLDocument by reference

Hello

Need your help, I have a C++ win32 dll which takes xml document type by
reference. I need to call this dll from c# .net.
I tried using DllImport, but dll funtion when call does not respond.
I tried calling similar dll for a function which take integer by
refernce. It works ok in this case.

Please can you let me know if we can call a c++ win32 dll function by
passing a xmldocument by reference?

Thanks
saish

Jan 10 '06 #1
4 2114
saish,

I can't imagine that it uses the .NET implementation of an XML document.

What is the type of the reference? You need to make sure you are
passing the correct type to the function.

What is the declaration in the header file for the function?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"saish" <sa***@eircom.net> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hello

Need your help, I have a C++ win32 dll which takes xml document type by
reference. I need to call this dll from c# .net.
I tried using DllImport, but dll funtion when call does not respond.
I tried calling similar dll for a function which take integer by
refernce. It works ok in this case.

Please can you let me know if we can call a c++ win32 dll function by
passing a xmldocument by reference?

Thanks
saish

Jan 10 '06 #2
Hi Nicholas,

Thanks for your reply ..sorry for not being clear ..

details below ..

I have a C++ win 32 dll which as below code. It has two function one
which takes integer by reference and one with xmldocument by reference.
These dll functiona are called successfully by a C++ executables.
----------------
extern "C"
{
extern int WINAPI fnTestXml(MSXML2::IXMLDOMDocumentPtr pXmlDoc);
extern int WINAPI fnTestInt(int* i);

}
int WINAPI fnTestXml(MSXML2::IXMLDOMDocumentPtr pXml)
{

printf("fnTestXmlIn.pXml.xml=\n%s\n", (LPCSTR)pXml->xml);

pXml->loadXML("<root><adddednode>By the dll</ adddednode ></root>");

printf("fnTestXmlIn.pXml.xml=\n%s\n", (LPCSTR)pXml->xml);

return 99;
}

int WINAPI fnTestInt(int & px)
{
px = px + 10;

return 122;

}

LIBRARY xmlref
EXPORTS
FUNC_XML = fnTestXml
FUNC_INT = fnTestInt

-------------------

I have a requirement where one of our web services which recevies
xmldocument written either in vb.net or csharp has to call these dll
functions and pass these xmldocument.

csharp test code
----------------------
[DllImport("xmlref.dll")]
public static extern int FUNC_XML(ref XmlDocument pdoc);
....
XmlDocument xmlin = new XmlDocument();
xmlin.LoadXml("<test> how r u </test>");
FUNC_XML(ref xmlin); <----- It fails here ..
---------

The above dll code is a test code. the actual dll is one of calculation
dll engines which takes xmldocument by reference. This dll is called by
many application. One of my requirement was to call this dll from a
..net web service.

Thanks

Jan 10 '06 #3
saish,

The XmlDocument in .NET and the implementation of the IXMLDOMDocument is
not the same. You can not interchange the two.

First, you should expose the IXMLDOMDocument interface, not the
IXMLDOMDocumentPtr. I believe IXMLDOMDocumentPtr is a wrapper that is
generated for you which helps with the management of the instance.

Then, you have to set a reference to MSXML.dll in your .NET project, and
use the XML classes from there in order to pass to your dll.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"saish" <sa***@eircom.net> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hi Nicholas,

Thanks for your reply ..sorry for not being clear ..

details below ..

I have a C++ win 32 dll which as below code. It has two function one
which takes integer by reference and one with xmldocument by reference.
These dll functiona are called successfully by a C++ executables.
----------------
extern "C"
{
extern int WINAPI fnTestXml(MSXML2::IXMLDOMDocumentPtr pXmlDoc);
extern int WINAPI fnTestInt(int* i);

}
int WINAPI fnTestXml(MSXML2::IXMLDOMDocumentPtr pXml)
{

printf("fnTestXmlIn.pXml.xml=\n%s\n", (LPCSTR)pXml->xml);

pXml->loadXML("<root><adddednode>By the dll</ adddednode ></root>");

printf("fnTestXmlIn.pXml.xml=\n%s\n", (LPCSTR)pXml->xml);

return 99;
}

int WINAPI fnTestInt(int & px)
{
px = px + 10;

return 122;

}

LIBRARY xmlref
EXPORTS
FUNC_XML = fnTestXml
FUNC_INT = fnTestInt

-------------------

I have a requirement where one of our web services which recevies
xmldocument written either in vb.net or csharp has to call these dll
functions and pass these xmldocument.

csharp test code
----------------------
[DllImport("xmlref.dll")]
public static extern int FUNC_XML(ref XmlDocument pdoc);
...
XmlDocument xmlin = new XmlDocument();
xmlin.LoadXml("<test> how r u </test>");
FUNC_XML(ref xmlin); <----- It fails here ..
---------

The above dll code is a test code. the actual dll is one of calculation
dll engines which takes xmldocument by reference. This dll is called by
many application. One of my requirement was to call this dll from a
.net web service.

Thanks

Jan 10 '06 #4
Nicholas:
I took your lead and was able to add reference of MSXML2 to .net and
was able to pass byval DOMDOCUMENT from .net to my dll.
Since the dOM document going to be a huge data, we were prefering to
pass byref. But we were not able to pass byref, but atleast we are able
to get this far. Thanks for your help.
Saish.

Jan 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by hasho | last post: by
1 post views Thread by Hans [DiaGraphIT] | last post: by
22 posts views Thread by Arne | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.