Options

Passing an XML document to VB .NET

Kenny_VaesKenny_Vaes Member Posts: 8
Hi, I'm having some problems with passing an XML document to a VB .NET component I've created.

I'm trying to create a shipment schedule similar in functionality as the production schedule in Navision 4.0

I've created a Setup table that stores a BLOB...And an XMLPort that generates the XML.

I'm still a "Junior" developper so bear with me here :)

recShipSchedSetup.LOCKTABLE();
recShipSchedSetup.GET();
recShipSchedSetup.GanttXML.CREATEOUTSTREAM(lostXMLSource); //GanttXML is the BLOB
xptScheduleShipment.SETDESTINATION(lostXMLSource);
xptScheduleShipment.InitializeHeader(rSalesHeader,TRUE,datDateFilter); //Sets a filter in the XMLPort
IF xptScheduleShipment.EXPORT THEN BEGIN
   autOutboundXML.load(lostXMLSource);

the autOutboundXML is an Automation variable of type "Microsoft XML, 4.0, DOMDocument40"
xptScheduleShipment is the XMLPort.


To pass the document to VB i'v made this code in navision after the autOutboundXML variable has been filled.
...
CREATE(autGantt);
autGantt.ShowForm(autOutboundXML);
...

autGantt is a DLL i've created in VB .NET... the showForm funtion expects a XMLDocument to be passed..
Public Function ShowFrom(ByRef XMLDoc As MSXML2.DOMDocument40) As Integer Implements _Wrapper.ShowForm
     .....
End Function

When running this function from Navision is get an error...I've found out why this error occurs but I do not know how to solve it.
When changing the type of XMLDoc in the VB code to Object...and then displaying the object type in a messagebox I get System._ComObject as type instead of MSXML2.DOMDocument40.
Public Function ShowFrom(ByRef XMLDoc As Object) As Integer Implements _Wrapper.ShowForm
            MessageBox.Show(XMLDoc.GetType.ToString)
        End Function
So the variable I pass from navision isn't an MSXML2.DOMDocument40 but a System._ComObject. I tried converting the variable in VB, but that doesn't work.

Has anyone had any experience with this? Or does anyone know how to pass this XMLDocument to VB .NET?

Thanks in advance ;)

Comments

  • Options
    Stefan_HillmannStefan_Hillmann Member Posts: 9
    Hi Kenny,

    what are you doing within your VB.Net DLL ?

    "Public Function ShowFrom(ByRef XMLDoc As MSXML2.DOMDocument40) As Integer Implements _Wrapper.ShowForm
    .....
    End Function"

    It is possible to use the MSXML4 as Reference for your own functions.
    When you try to show the XML-String use
    MessageBox.Show(XMLDoc.Text) or
    MessageBox.Show(XMLDoc.XML)


    Stefan
  • Options
    Kenny_VaesKenny_Vaes Member Posts: 8
    I wanted to pass the XML doc via a BLOB in a setup table to VB. But I got errors when doing that. Because of the type I gues. I know exported the XMLPort to a textfile and passed the location string to VB. That worked, But now I get errors with my Automation DLL :s

    When I do CREATE(autDll) Navision says it cannot create an instance of the class.

    I think I'm doing something wrong in the VB Code with the DLL. Does anyone know how to create a dll so I can register it to COM and navision can see the public functions?

    Here's the code i've got now:
    Imports System
    Imports System.Xml
    Imports System.Runtime.InteropServices
    Imports NETRONIC.XGantt
    
    Namespace Wrapper
    
        <Guid("626C8CFD-E71A-4c7a-92A5-CE4DA6AEE4DA"), _
        InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
        Public Interface _cWrapper
            <DispId(1)> Function ScheduleShipment(ByVal fileLocation As String) As Integer
        End Interface
    
    
        <Guid("FB4FB05F-A779-400f-93CC-4CB0D9F1A7C0"), _
        ClassInterface(ClassInterfaceType.None), _
        ProgId("Wrapper.cWrapper")> Public Class cWrapper
            Implements _cWrapper
    
            Public cWrapper()
    
            Private WithEvents myFrmGantt As New frmGantt
            Private WithEvents myVcGantt As New VcGantt
    
            Public Function ScheduleShipment(ByVal fileLocation As String) As Integer Implements _cWrapper.ScheduleShipment
    
                Initialize()
                ReadXML(fileLocation)
            End Function
    
    .....
    

    I got this code from the net here: http://www.codeproject.com/dotnet/nettocom.asp

    So I followed their instructions to create the DLL. It used to work fine before but since yesterday I've been getting errors. When I use the OLEView tool of Microsoft Visual Studio and try to create an instance of it by double clicking on the COM, I get:
    IClassFactory::CreateInstance failed
    Severity: SEVERITY_ERROR, facility: <Unknown>, ...

    Anyone know what's the problem here? :s
Sign In or Register to comment.