next up previous contents
Next: Example: Monitoring the GPU Up: Memory Mapped Files Previous: Send a request to   Contents

Receive an answer from GPU

We go back to the WndProc method. Here the WMsgGPUResult case has been triggered by the incoming GPU message result. That tells us that GPU has placed a string in the Memory Mapped File and that it is waiting for us to retrieve it. All we do is simply open up a view to the file with MapViewOfFile which returns a pointer to the start of the string. We split the string in two parts with ExtractParamString(...) in utils.pas. JobID and ResultStr contain the result of one computation. The only thing left to do is to close our view of the file with UnmapViewOfFile [6].

procedure TForm1.WndProc(Var TheMsg: TMessage);
 thePtr          : PChar;
 JobId,ResultStr : String;
  {handling a user defined windows message that
   is a result}
  if TheMsg.Msg = WMsgGPUResult then
      IncomingString := ThePtr;

      JobID := ExtractParam(IncomingString,':');
      ResultStr := IncomingString;
  Inherited WndProc(TheMsg);

Tiziano Mengotti 2004-03-27