I am trying to receive messages from QCollector as explained in the QCollector Data Interface developer guide. The process consists of registering predefined messages, finding the QCollector server window, and exchanging data through the registered messages.
My WndProc
callback receives lost of messages, but none of those are recognized as one of the registered messages. I'm passing my Form
's this.Handle
in the request, but I'm unsure if this is correct.
What am I doing wrong?
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:
Just to be sure that I have the basics working in c# I created a second version of this app and got them to talk to each other. This works, so I know my handles and message structures are correct.
BUT I never get a response from qCollector. Does anyone have experience of using this in any other language perhaps? I suspect qCollector was written in c++.