안녕하세요,이 코드는 모두 here입니다. SendMessage API를 사용하여 실행중인 2 개의 .net 응용 프로그램에서 메시지를 앞뒤로 보낼 수 있습니다. 테스트 할 때 모든 것이 C# 코드에서 잘되지만 VB.net으로 변환해야했습니다. 에 보이는 나던 모두 내 애플 리케이션을위한 위의 코드를 사용하여, 그러나vb.net 응용 프로그램 간의 통신
수입 System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Private Const RF_TESTMESSAGE As Integer = &HA123
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SendMessage(ByVal hwnd As IntPtr, <MarshalAs(UnmanagedType.U4)> ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
End Function
Public Sub New()
InitializeComponent()
Me.Text = String.Format("This process ID: {0}", Process.GetCurrentProcess().Id)
End Sub
<STAThread()> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim proc As Process = Process.GetCurrentProcess()
Dim processes As Process() = Process.GetProcessesByName(proc.ProcessName)
If processes.Length > 1 Then
For Each p As Process In processes
If p.Id <> proc.Id Then
SendMessage(p.MainWindowHandle, RF_TESTMESSAGE, IntPtr.Zero, IntPtr.Zero)
End If
Next
Else
MessageBox.Show("No other running applications found.")
End If
End Sub
Protected Overrides Sub WndProc(ByRef message As Message)
If message.Msg = RF_TESTMESSAGE Then
ListBox1.Items.Add("Received message RF_TESTMESSAGE")
End If
MyBase.WndProc(message)
End Sub
End Class
:> VB.net 변환이있어 -
그래서 내가 온라인 C# .NET을 사용 에 도달하면 sendmessage 액션을 생성합니다. processes.Length> 1 Then. 항상 알려줍니다 실행중인 다른 응용 프로그램이 없습니다. 비록 내가 C# 예제에서 실행 한 두 앱을 모두 가지고있다.나는 변환 할 때 나르 지 않은 것을 놓치고 있어야합니다. 이 문제를 해결하는 데 도움이 될 것입니다!
'두 앱이 모두 실행 중입니다.'- 동일한 프로그램 또는 두 가지 프로그램의 두 인스턴스가 있습니까? BTW, 왜 WCF를 사용하지 않습니까? –
좋은 주님, C# 코드를 작성하는 방법은 변환 된 쓰레기를 실행하는 것보다 시간을 절약 할 것입니다. 어느 것이 좋습니다, C#은 요즘 VB.NET 프로그래머에게는 꽤 어려운 요구 사항입니다. –
제공된 블로그 게시물 링크가 여기에서 작동하지 않습니다. 아마도 WCF 또는 심지어 Remoting과 같은 일류 프로세스 간 통신 방법을 사용할 때가 왔습니다. @stackoverflow.com/questions/2082450/communication-between-c-sharp-applications-the-ewayway –