2017-02-15 80 views
9

Próbuję odbierać wiadomości od QCollector, jak wyjaśniono w przewodniku dla programistów QCollector Data Interface. Proces polega na rejestrowaniu wstępnie zdefiniowanych wiadomości, znajdowaniu okna serwera QCollector i wymianie danych za pośrednictwem zarejestrowanych wiadomości.Wiadomość z powrotem od Windows API

Moje wywołanie zwrotne otrzymuje WndProc, ale żaden z nich nie jest rozpoznawany jako jeden z zarejestrowanych wiadomości. W poleceniu podam moje Form 's this.Handle, ale nie jestem pewien, czy jest to poprawne.

Co robię źle?

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Linq; 
using System.Runtime.InteropServices; 
using System.Text; 
using System.Threading; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace HistDataManager 
{ 

    public partial class Form1 : Form 
    { 
     [DllImport("user32.dll", EntryPoint = "FindWindow")] 
     private static extern int FindWindow(string sClass, string sWindow); 

     [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 
     static extern uint RegisterWindowMessage(string lpString); 

     [DllImport("user32.dll")] 
     static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam); 

     int nWinHandle = FindWindow("QCDataInterfaceWndClass", null); 

     uint wm_QCollectorClientDataRequest = RegisterWindowMessage("QCOLLECTOR_CLIENT_DATA_REQUEST"); 
     uint wm_QCollectorClientPortfolioListRequest = RegisterWindowMessage("QCOLLECTOR_CLIENT_PORTFOLIO_LIST_REQUEST"); 
     uint wm_QCollectorPortfolioListRequestComplete = RegisterWindowMessage("QCOLLECTOR_PORTFOLIO_LIST_REQUEST_COMPLETE "); 

     public void TestQC() 
     { 
      SendMessage(new IntPtr(nWinHandle), wm_QCollectorClientPortfolioListRequest, UIntPtr.Zero, this.Handle); 

     } 

     protected override void WndProc(ref Message m) 
     { 
      Console.WriteLine(m.HWnd + "," + m.Msg + "," + m.LParam + "," + m.WParam); 
      base.WndProc(ref m); 

      if (m.Msg == wm_QCollectorClientPortfolioListRequest || m.Msg == wm_QCollectorPortfolioListRequestComplete) 
      { 
       Console.WriteLine("Message from specified application found!"); 
      } 

     } 

    } 
} 

EDIT 1:

Wystarczy, aby mieć pewność, że mam podstawy pracy w C# I stworzył drugą wersję tej aplikacji i dostał je ze sobą rozmawiać. To działa, więc wiem, że moje uchwyty i struktury wiadomości są poprawne.

ALE nigdy nie otrzymałem odpowiedzi od qCollector. Czy ktoś może mieć doświadczenie w korzystaniu z tego w jakimkolwiek innym języku? Podejrzewam, że qCollector został napisany w języku C++.

+0

Co masz na myśli przez _TargetApp_? –

+0

Spróbuj użyć PostMessage zamiast tego. –

+0

@JoshuaDrake TargetApp jest wndem znajdującym się w FindWindow ("QCDataInterfaceWndClass", null) – ManInMoon

Odpowiedz

-1

Nie wiem, czy jest w porządku w .Net, ale chciałbym zasugerować, aby wywołać wszystkie funkcje w konstruktorze lub w funkcji init().

Sugerowane Projekt

int nWinHandle=0; 
uint wm_QCollectorClientDataRequest=0; 
uint wm_QCollectorClientPortfolioListRequest=0; 
uint wm_QCollectorPortfolioListRequestComplete=0; 

void init() 
{ 
    nWinHandle = FindWindow("QCDataInterfaceWndClass", null); 
    wm_QCollectorClientDataRequest = RegisterWindowMessage("QCOLLECTOR_CLIENT_DATA_REQUEST"); 
    wm_QCollectorClientPortfolioListRequest = RegisterWindowMessage("QCOLLECTOR_CLIENT_PORTFOLIO_LIST_REQUEST"); 
    wm_QCollectorPortfolioListRequestComplete = RegisterWindowMessage("QCOLLECTOR_PORTFOLIO_LIST_REQUEST_COMPLETE "); 
} 
+0

Pytanie nie brzmi: "Jak poprawić swój projekt?"Pytanie brzmi:" Jak odzyskać wartość zwróconą w komunikacie między procesami? "Ta proponowana odpowiedź nie rozwiązuje problemu, nawet nie zdalnie, ani nie dodaje niczego użytecznego w inny sposób. – IInspectable