0

I have knowledge on C++ and C#, but COM is an Alien to me. I have a VC++ COM DLL in which all the methods of the interface ISAXContentHandler (of msxml6.DLL) like startElement(), endElement,processingInstructions(), characters(), etc.. are implemented. i.e these interface methods are given an implentation in the VC++ COM DLL. I want to convert this VC++ COM DLL to C# DLL so that I can call this converted C# DLL from my C# application.

I am not understanding that FROM WHERE ARE THESE INTERFACE METHODS BEING CALLED. Because there is NO "Function Call statement" being made from within my VC++ COM DLL.

For Example: ----- one of the interface methods implemented in the VC++ COM DLL starts like this- -->

  **HRESULT STDMETHODCALLTYPE ContentHandler_SAX::startElement( 
        /* [in] */ wchar_t __RPC_FAR *pwchNamespaceUri,
        /* [in] */ int cchNamespaceUri,
        /* [in] */ wchar_t __RPC_FAR *pwchLocalName,
        /* [in] */ int cchLocalName,
        /* [in] */ wchar_t __RPC_FAR *pwchRawName,
        /* [in] */ int cchRawName,
        /* [in] */ ISAXAttributes __RPC_FAR *pAttributes)**

The clas is implementing ISAXContentHAndler interface from msxml6.dll.

I just know that SAXContentHandler is a XML parser. I dont know what are these parameters for this function and also they are using _RPC keyword along with d parameter name. And I dont understand, FROM WHERE are these functions being called.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
codeLover
  • 3,720
  • 10
  • 65
  • 121

1 Answers1

1

SAX Parser is asynchronous (event based) parser - generally, you start the parser giving it xml file/stream and it will raise events as it encounters various xml nodes. Being COM library, it uses COM event model where generally component (parser in this case) would define an callback interface (there are other interfaces that allowed to register for events etc).

So ISAXContentHAndler is an callback interface that is supposed to be implemented by code using the parser. You will find that somewhere in code, SAXXMLReader component being created and then the contentHandler property on ISAXXMLReader being set to the instance of class that is implementing ISAXContentHAndler.

You will find calls made to this interface in your code because its the SAX parser that would be calling methods on this interface - for example, whenever it encounters start tag of any element, it would call startElement method on this interface.

See these links to understand SAX better: http://msdn.microsoft.com/en-us/library/ms753774(v=VS.85).aspx http://msdn.microsoft.com/en-us/library/ms763771(v=VS.85).aspx

VinayC
  • 47,395
  • 5
  • 59
  • 72
  • Hi Vinay thank you so much for the exact information you provided. I understood the way the method call is happening. Since I want to convert this set up into C#, what step should I follow writing the implementation for these interface methods. For Example, in VC++ the syntax followed is as I have pasted in the above Question area.. the keywords HRESULT STDMETHODCALLTYPE are used for the function defn. COM concepts are being used in d VC++ code to achieve this. While implementing in C# wat approach should I follow? Should I use COM concepts. Since COM is an alien 2 me im asking. THANKS... – codeLover Nov 11 '10 at 10:08
  • C# have its own XML parsing libraries and I would suggest you to use those instead of MSXML - see XmlDocument (DOM based parsing) and XmlReader (fast forward only synchronous parser). And see http://saxdotnet.sourceforge.net/ for SAX implementation in .NET – VinayC Nov 11 '10 at 12:24
  • Hi Vinay thanks, I am marking your answer as it helped me a to analyse my VC++ part. But would you, let me know that how to refer to ISAXContentHandler methods in my C# code plz... Because I want event based XML parser only. So, using msxml6.dll 's ISAXContentHandler would help me to a great extent. I am new to COM so I dont have idea in this regard. – codeLover Nov 12 '10 at 04:03
  • Why don't you use SAX implementation (saxdotnet.sourceforge.net)? Regardless, for using MSXML SAX, you need to define equivalent interface (and its implementation class in C#) and decorate them with attributes specifying CLSID/IID. You can use new guid for CLSID but must use same IID as given by MSXML. Then register your .NET dll as COM Library. HRESULT means int while wchar_t will map to string. See this tutorial for quick start: http://msdn.microsoft.com/en-us/library/aa645738(VS.71).aspx. – VinayC Nov 12 '10 at 05:01
  • Hi Vinay, thank you for this link. I read the contents and when I arrived at the link "http://www.saxproject.org/langs.html" I found that they have given other language APIs and methods to use SAX. But method of using SAX in C# is not given. For example--- while using "msxml" I used to just import msxml6.dll to my application and then implement the event handlers of ISAXContentHandler,.. So, HOW TO ACHIEVE THIS EVENT BASED XML PARSING IN C#. yOU SAID ME TO DEFINE EQUIVALENT INTERFACES AND IMPLEMENT THEM RIGHT, MY DOUBT IS THAT INSIDE WHICH CLASS SHOULD THESE INTERFACES BE DEFINED. – codeLover Nov 12 '10 at 10:40
  • I continue with d previous comment. ---------- To explain clearly, i give this analogy--- WE HAD THE IMPLEMENTATION OF THE INTERFACE ISAXContentHandler IN SOME CLASS OF MSXML6.DLL AND WE GAVE THE IMPLEMENTAION FOR THESE INTERFACES IN ONE OF THESE CLASSES OF OUR APPLICATION RIGHT? sIMILIARLY I HAD THE DOUBT THAT WHERE SHOULD THESE INTERFACES BE DEFINED IN MY C# COUNTERPART WHEN WE WANT TO ACHIEVE THIS EVENT BASED PARSING. SHOULD WE ANY DLL. sorry if im asking some silly thing. I am new to this, so kindly let me know. THANKS IN ADVANCE. – codeLover Nov 12 '10 at 10:49
  • The link that you have quoted is for Sax Project which is a java library while I had provided you saxdotnet.sourceforge.net (a .NET port). You can download code from here: http://sourceforge.net/projects/saxdotnet/ You can also write your own simple SAX implementation on top of XmlReader - IMO, XmlReader is far simpler to use that any SAX based API. – VinayC Nov 12 '10 at 11:29
  • To answer your other question, I am not 100% sure as to how simple this thing might be. Perhaps, you can start by adding reference to msxml6 in C# project and then writing C# class implementing the said interface. – VinayC Nov 12 '10 at 11:35