Click here to Skip to main content
15,895,709 members

Delphi Form Programming, GUI not responding!!

iDebD asked:

Open original thread
Delphi
unit Unit_hook;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Grids;

type

TCALLBACKPROC = function(strDataType:PWideChar; strDocument:PWideChar;strDriverName:PWideChar;strMachineName:PWideChar;strPrintername:PWideChar;
						strParameters:PWideChar;strPrintProcessor:PWideChar; JobId:Integer;PagesPrinted:Integer; Size:Integer; status:Integer; TotalPages:Integer;SizeHigh:LongInt; dmColor:ShortInt; dmPaperLength:ShortInt; dmPaperSize:ShortInt; dmPaperWidth:ShortInt):HRESULT stdcall;
type
  TSetCallbackFunc = procedure(_proc:TCALLBACKPROC) stdcall;
var
  fnSetCallback : TSetCallbackFunc;


type
  Tfrmhook = class(TForm)
    sg: TStringGrid;
    Panel1: TPanel;
    btLoad: TButton;
    btUnload: TButton;
    procedure btLoadClick(Sender: TObject);
    procedure btUnloadClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmhook: Tfrmhook;
  m_hDll: HMODULE;
  myString: String;

  mystrDataType:PChar;
  mystrDocument:PChar;
  mystrDriverName:PChar;
  mystrMachineName:PChar;
  mystrPrintername:PChar;
  mystrParameters:PChar;
  mystrPrintProcessor:PChar;
  myJobId:Integer;
  myPagesPrinted:Integer;
  mySize:Integer;
  mystatus:Integer;
  myTotalPages:Integer;
  mySizeHigh:LongInt;
  mydmColor:ShortInt;
  mydmPaperLength:ShortInt;
  mydmPaperSize:ShortInt;
  mydmPaperWidth:ShortInt;

implementation

{$R *.dfm}

function CallbackProc(strDataType:PWideChar; strDocument:PWideChar;strDriverName:PWideChar;strMachineName:PWideChar;strPrintername:PWideChar;strParameters:						PWideChar;strPrintProcessor:PWideChar; JobId:Integer;PagesPrinted:Integer; Size:Integer; status:Integer; TotalPages:Integer;
                     SizeHigh:LongInt; dmColor:ShortInt; dmPaperLength:ShortInt; dmPaperSize:ShortInt; dmPaperWidth:ShortInt):HRESULT stdcall;

var
i : integer;

begin
     MessageBox(0, 'cbk proc', 'cbk proc', MB_OK);
{
          myString :=    'DataType = ' + strDataType + #13#10 + 'Document = ' +strDocument+ #13#10 + 'DriverName = '+   strDriverName + #13#10 + 'MachineName = ' +   strMachineName
                          + #13#10 + 'Printername = ' +   strPrintername + #13#10 + 'Parameters = ' +   strParameters
                          + #13#10 + 'PrintProcessor = ' +   strPrintProcessor + #13#10 + 'JobId = ' +  IntToStr(JobId)
                          + #13#10 + 'PagesPrinted = ' +  IntToStr(PagesPrinted)+ #13#10 + 'Size = ' +  IntToStr(Size)
                          + #13#10 + 'status = ' +  IntToStr(status) + #13#10 + 'TotalPages = ' +  IntToStr(TotalPages)
                          + #13#10 + 'SizeHigh = ' +  IntToStr(SizeHigh) + #13#10 + 'dmColor = ' +  IntToStr(dmColor)
                          + #13#10 + 'dmPaperLength = ' +  IntToStr(dmPaperLength)+ #13#10 + 'dmPaperSize = ' +  IntToStr(dmPaperSize)
                          + #13#10 + 'dmPaperWidth = ' +  IntToStr(dmPaperWidth);
                          ;
}


         //MessageBoxA(0,PAnsiChar(myString), 'Print_info',MB_OK);


  with frmhook.sg do begin
          if Cells[1,1] <> '' then RowCount := RowCount + 1;
          i := 0;
          inc(i); Cells[i,RowCount-1] :=strDataType;
          inc(i); Cells[i,RowCount-1] :=strDocument;
          inc(i); Cells[i,RowCount-1] :=strDriverName;
          inc(i); Cells[i,RowCount-1] :=strMachineName;
          inc(i); Cells[i,RowCount-1] :=strPrintername;
          inc(i); Cells[i,RowCount-1] :=strParameters;
          inc(i); Cells[i,RowCount-1] :=strPrintProcessor;
          inc(i); Cells[i,RowCount-1] :=IntToStr(JobId);
          inc(i); Cells[i,RowCount-1] :=IntToStr(PagesPrinted);
          inc(i); Cells[i,RowCount-1] :=IntToStr(Size);
          inc(i); Cells[i,RowCount-1] :=IntToStr(status);
          inc(i); Cells[i,RowCount-1] :=IntToStr(TotalPages);
          inc(i); Cells[i,RowCount-1] :=IntToStr(SizeHigh);
          inc(i); Cells[i,RowCount-1] :=IntToStr(dmColor);
          inc(i); Cells[i,RowCount-1] :=IntToStr(dmPaperLength);
          inc(i); Cells[i,RowCount-1] :=IntToStr(dmPaperSize);
          inc(i); Cells[i,RowCount-1] :=IntToStr(dmPaperWidth);
  end;
    MessageBox(0, 'cbk proc', 'cbk proc', MB_OK);
end;


procedure Tfrmhook.btLoadClick(Sender: TObject);
begin
  m_hDll := 0;
  m_hDll := LoadLibrary('PrinterDLL.dll');
  if 0 = m_hDll
  then MessageBox(0, 'DLL Loading failed', 'DLL loading failed', MB_OK)
  else  fnSetCallback := GetProcAddress(m_hDll,'StartMonitoring_');



  fnSetCallback(CallbackProc);
  //Application.ProcessMessages;
end;

procedure Tfrmhook.btUnloadClick(Sender: TObject);
begin
    FreeLibrary(m_hDll);
end;

end.


I am loading a DLL where one thraed is running; Now after some time frame this thread is calling function "CallbackProc" through function pointer; On call it is setting some form field in GUI; Now when the callback function is called in Delphi, then the messagebox of aove code comeing correctly, but the GUI is "Not Responding" and form fields are not updated;
ANy clue why this is happening?

If any clarification required plz comment?
Any one give me the idea where I should declare the CallBackProc?

Thanks
Tags: Delphi

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900