gpt4 book ai didi

c - 2 个应用程序之间的数据交换

转载 作者:行者123 更新时间:2023-11-30 17:38:09 25 4
gpt4 key购买 nike

我有两个应用程序
第一个使用 C 编程的第二个使用 VB.NET

我想执行第一个并将状态更新为第二个

有办法做到这一点吗?

我可以更改其中任何一个的源代码

最佳答案

好的,在 VB 中,您需要在两个程序之间实现一个接口(interface),以便可以在它们之间传递参数。

  • 记住导入“system”和“system.reflection”

在program1(调用程序)中我进行了这样的设置:

Dim oType As System.Type
Dim oAssembly As System.Reflection.Assembly
Dim oObject As System.Object

oAssembly = Reflection.Assembly.LoadFrom("C:\VB.NET\report3.exe")
oType = oAssembly.GetType("report3.r1") ' this is [root_namespace.class name]
oObject = Activator.CreateInstance(oType)
oObject.SetParams("a", "b")
oObject.show()

这会导致 report3.exe 运行并向其发送“a”和“b”参数作为值。

然后在program2(report3.exe)中,我这样设置:

Imports System.Reflection

Public Class r1

Implements IPlugin

Public person As String = ""
Public address As String = ""


Private Sub r1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

Me.TopMost = True 'optional

Dim b1 As New Label()
With b1
.Location = New Point(10, 10)
.Width = 200
.Height = 20
.Parent = Me
.BackColor = Color.Blue
.ForeColor = Color.White
.Text = person
End With

call_addr()
End Sub


Public Sub SetParams(c As String, d As String) Implements IPlugin.SetParams
person = c
address = d
End Sub

Private Sub call_addr()
Dim b2 As New Label()
With b2
.Location = New Point(10, 50)
.Width = 200
.Height = 20
.Parent = Me
.BackColor = Color.Red
.text = address
End With
End Sub

End Class


Public Interface IPlugin
Sub SetParams(ByVal c As String, ByVal d As String)
End Interface

关于c - 2 个应用程序之间的数据交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22201190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com