2014-03-05 20 views
0

2之間,我有兩個應用程序
第一個用C 第二用VB.NET數據交換應用

我想執行的第一個,並保持更新到第二

狀態編程是有辦法做到這一點?

我可以改變它們中的任何一個源代碼

+0

你的兩個程序之間傳遞數據或者是那裏的數據存儲就像一個數據庫的地方,他們都可以讀取?是一個程序調用另一個程序嗎?他們是否都在同時運行,並且彼此「交談」? – user2721815

+0

沒有數據庫,是第二個調用另一個,兩個同時運行 –

+0

我已經在VB中使用一個接口完成了這個。我不知道你是否可以在C中做同樣的事情。 – user2721815

回答

0

OK的地方,在VB中需要實現兩個程序之間的接口,因此您可以在它們之間傳遞參數。

  • 記得導入 「系統」 和 「的System.Reflection」

在程序1(調用程序),我設置了:

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」參數。

然後在程序2(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 
+0

好的,謝謝! –