【问题标题】:Data Exchange between 2 Applications2个应用程序之间的数据交换
【发布时间】:2014-03-05 14:52:19
【问题描述】:

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

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

有没有办法做到这一点?

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

【问题讨论】:

  • 您是在两个程序之间传递数据,还是有一个像数据库一样存储数据的地方,它们都可以从中读取?一个程序是否在调用另一个程序?他们是否同时运行并互相“交谈”?
  • 没有数据库,是的,第二个调用另一个,两个同时运行
  • 我已经在 VB 中使用接口完成了这项工作。我不知道你是否可以在 C 中做同样的事情。
  • 请告诉我如何在 VB 中使用!

标签: c vb.net dde data-exchange


【解决方案1】:

好的,在VB中你需要在两个程序之间实现一个接口,这样你就可以在它们之间传递参数。

  • 记得导入“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

【讨论】:

    【解决方案2】:

    我可以看到使用 C 和 VB 有一些复杂性,但这是一个开始的地方 http://msdn.microsoft.com/en-us/library/aa365574%28VS.85%29.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 2011-01-04
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多