jacob-project
jacob-project copied to clipboard
[VB DOMDocument] Object as an input parameter cannot get the value of the modified attribute
Hi, thank you for maintaining this lib.
Due to my poor English level, I am very sorry to ask you this way. The following question description comes from Google Translate (Original: Chinese)
used jacob version: 1.20
When I use jacob to call the vb6 com component, the following problems occur: When using a custom object as an input parameter, Jacob can get the modified attribute value of the input parameter of the object after the end of the call When using a DOMDocument object as an input parameter, Jacob cannot get the modified attribute value of the object input parameter after the call ends.
I tried to use vb6 to directly call the com component. Both the custom object and the DOMDocument input parameters can get the modified attribute values of the object input parameters after the call is over.
I have read the relevant source code of Variant, and there is only one way of handling input object parameters by reference. I also looked through the relevant examples and test codes in the warehouse, but did not find relevant examples of input object parameters
The relevant code and call results are as follows, please help me to see where the problem is:
Class module object code:
' User1
Public username As String
Public age As Integer
VB6 COM Component Code:
Public Function testUser(u1 As Demo1.User)
u1.username = "admin"
u1.age = 22
End Function
Public Function testNewXml(testdom As DOMDocument)
Set root = testdom.createElement("employees")
Set testdom.documentElement = root
Call root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
Call root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
Call root.setAttribute("xmlns", "http://www.kingdee.com/ReK3Inventory")
Set emp = testdom.createNode(MSXML2.NODE_ELEMENT, "employee", "")
root.appendChild emp
Set tempNode = testdom.createNode(MSXML2.NODE_ELEMENT, "Employeeid", "")
tempNode.Text = "1"
emp.appendChild tempNode
Set tempNode = testdom.createNode(MSXML2.NODE_ELEMENT, "Firstname", "")
tempNode.Text = "wang"
emp.appendChild tempNode
Set tempNode = testdom.createNode(MSXML2.NODE_ELEMENT, "Title", "")
tempNode.Text = "hello world"
emp.appendChild tempNode
Dim pi As IXMLDOMProcessingInstruction
Set pi = testdom.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'")
Call testdom.insertBefore(pi, testdom.childNodes(0))
End Function
VB exe project called code:
' call testUser:
Private Sub Command2_Click()
Dim cls1 As New Demo1.Class1
Dim u1 As New Demo1.User
Call cls1.testUser(u1)
MsgBox u1.username
MsgBox u1.age
End Sub
' call testNewXml:
Private Sub Command3_Click()
Dim cls1 As New Demo1.Class1
Dim testdom As New MSXML2.DOMDocument
Call cls1.testNewXml(testdom)
MsgBox testdom.xml
End Sub
VB exe project called result:
jacob called code:
private static void testNewXmlParam() {
ComThread.startMainSTA();
Dispatch cls1 = new Dispatch("Demo1.Class1");
Dispatch testdom = new Dispatch("Msxml2.DOMDocument");
LogUtil.info("testNewXml - in param, xml: ", Dispatch.get(testdom, "xml").getString());
Dispatch.call(cls1, "testNewXml", testdom);
LogUtil.info("testNewXml - out param, xml: ", Dispatch.get(testdom, "xml").getString());
ComThread.quitMainSTA();
}
private static void testSimpleObjectParam() {
Dispatch cls1 = new Dispatch("Demo1.Class1");
Dispatch u1 = new Dispatch("Demo1.User");
LogUtil.info("testUser - in param - username: {}, age: {}", Dispatch.get(u1, "username").getString(), Dispatch.get(u1, "age").getInt());
Dispatch.call(cls1, "testUser", u1);
LogUtil.info("testUser - out param - username: {}, age: {}", Dispatch.get(u1, "username").getString(), Dispatch.get(u1, "age").getInt());
}
jacob called result: testUser - in param - username: , age: 0 testUser - out param - username: admin, age: 22 testNewXml - in param, xml: testNewXml - out param, xml: