I'm totally new in messages handling using the winapi, I have a DLL which will post custom messages under the ID WM_GAS_AP
I would like to receive these messages and print them in a memo.
I tried several examples but without success, the currently I have implemented in my code is from this site http://users.telenet.be/ws36637/delphihook.html
I created the unit and added it to my uses, and declared this constant
const
WM_GAS_AP = WM_USER + 1;
Added this procedure
procedure ProcessHookMessage(Sender: TObject;
var Message: TMessage; var Handled: Boolean);
procedure TForm1.ProcessHookMessage(Sender: TObject;
var Message: TMessage; var Handled: Boolean);
begin
if Message.Msg = WM_GAS_AP then
begin
memo1.lines.add('I received a message!');
end;
end;
But it doesn't catch anything.
EDIT:
This comes with a C++ sample which unafortunately I wasn't be able to compile. In that example I found a section which shows this:
Check the end please.
private: // ユーザー宣言
// 変数
HINSTANCE hDLL;
UINT iComPort;
CHAR RCV_BUFF[512];
TCHAR ALARM_BUFF[256];
TLaserFalconTimer* pLF_Timer;
// 初期化関連関数
int __fastcall TLaserFalconInitialize(void);
int __fastcall TLaserFalconIniLoad(void);
// DLL関連関数
int __fastcall TLaserFalconGasViewDllMeasStart(void);
int __fastcall TLaserFalconGasViewDllMeasStop(void);
// 表示関連関数
void __fastcall TLaserFalconSetAlarmLevel(void);
// イベント受信用関数
void __fastcall MsgFromThrCommGasView(TMessage Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_GAS_AP, TMessage, MsgFromThrCommGasView)
END_MESSAGE_MAP(TForm)
From the DLL documentation it says:
So at the first time when attempting to stablish the connection with the DLL:
Declared this function:
function GasViewInit(HWnd:HWND;DataLen:Byte;BaudRate:Byte;Parity:Byte;ComPort:Byte): Integer; stdcall; external 'GasView.dll';
And passed the windows handle as param to the DLL. It succesful connect.
procedure TForm1.Button1Click(Sender: TObject);
var
ret:Integer;
iComPort:Integer;
begin
iComPort:=13;
ret:=-100;
ret:=GasViewInit(Handle,1,3,0,iComPort);
if ret=0 then
begin
ret:=-100;
ret:=GasViewNego();
if ret=0 then
begin
Button2.Enabled:=True;
Memo1.Lines.Add('Connected');
end
else
Memo1.Lines.Add('Sensor error '+ IntToStr(ret));
end
else
Memo1.Lines.Add('Library error '+IntToStr(ret));
end;