dll call by passing XMLDocument by reference

S

saish

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
 
N

Nicholas Paldino [.NET/C# MVP]

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?
 
S

saish

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
S

saish

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top