Link to home
Start Free TrialLog in
Avatar of neame
neame

asked on

WinProc & Delphi2

I hope someone can help me....

The following are code snipits from an application I am trying
to get running.  I've run it using straight windows API calls but
now need to run it from a Delphi2 application. The function
TfrmMain.InitDigitizingArm starts a backgound
process that sends messages to the function WindowProc in straight
windows API programming.  What is the equivalent in Delphi? In Delphi2
will it send the data to the
frmMain.WMCommand?  Is my application.handle correct (frmMain.Handle vs
Application.Handle)?  I'm sure I've overlooked something simple.
Any help is surely appreciated.  Thanks in advance.

Jeff Jolie
Shaken, not stirred.


        public
         { Public declarations }
    Password : string ;
    procedure WMCommand(var Message:TMessage); message wm_Command;


procedure TfrmMain.WMCommand(var Message: TMessage);
var
  a : parm_rec;
begin
   inherited;
   New(a);

   if Message.WParam = armMessageVal then
   begin
      a := pArmGetArmRec;// @LParam;
      // more processing here
   end;
end;

/// This function called during frmMain create

function TfrmMain.InitDigitizingArm : boolean;
begin
   armMessageVal := RegisterWindowMessage(ARM_MESSAGE);

   hLib := LoadLibrary('Armdll32.dll');
   pArmStart := GetProcAddress(hLib,'ArmStart');
   pArmConnect := GetProcAddress(hLib,'ArmConnect');
   pArmSetBckgUpdate := GetProcAddress(hLib,'ArmSetBckgUpdate');
   pArmGetArmRec := GetProcAddress(hLib,'ArmGetArmRec');

   ...this handle is key....
   status := pArmStart(frmMain.Handle); // tried Application.Handle with
no luck

   Result := True;
   if( status <> ARM_SUCCESS ) then
   begin
      MessageBox(0,'Can not start ArmStart','ArmStart Error',mb_ok);
      Result := False;
      Exit;
   end
   else
   begin
      status := pArmConnect(2,9600);
      if ( status = ARM_SUCCESS ) then
      begin
         status := pArmSetBckgUpdate(ARM_3DOF);  // this should send
messages to frmMain.WMCommand, but doesn't
         if ( status <> ARM_SUCCESS ) then
         begin
            MessageBox(0,'Can not set bkgnd update.','BkgndUpdate
Error',mb_ok);
            Result := False;
            Exit;
         end;
      end
      else
      begin
         MessageBox(0,'Arm Connect Error.','ArmConnect Error',mb_ok);
         Result := False;
         Exit;
      end;

   end;
end;
ASKER CERTIFIED SOLUTION
Avatar of sperling
sperling

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sperling
sperling

BTW.

You should use TFrmMain.Handle. If you use Application.Handle, you need to obtain the message using Application.HookMainWindow.

Regards,

Erik.
Avatar of neame

ASKER

I solved the problem myself while waiting for the answer.  Sperlings answer was correct.  Thanks.

Jeff Jolie