Delphi CreateThread thread transmission multiple parameter processing methods

Share picture

unit Unit1;


interface

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

type
MYPARA
= record
title: pchar;
str: pchar;
end;

PMYPARA
= ^MYPARA;

type
TForm1
= class(TForm)
btn1: TButton;
Memo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
FCount: Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;


implementation

{$R *.dfm}

function ThreadProc(Para: PMYPARA): DWORD; stdcall;
var
h: hmodule;
MyMessagebox:
function(hWnd: hWnd; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall;
begin
result :
= 0;
h :
= LoadLibrary('user32.dll< span style="color: #800000;">');
if h> 0 then
begin
Para^.title :
= 'Test Thread< span style="color: #800000;">';
@MyMessagebox :
= GetProcAddress(h, 'MessageBoxA ');
if @MyMessagebox <> nil then
MyMessagebox(
0, Para^.str, Para^.title, 0);
freeLibrary(h);
end;
end;

procedure TForm1.btn1Click(Sender: TObject);
var
s:
string;
P: PMYPARA;
ThreadHandle: THandle;
TheThread: DWORD;
begin
GetMem(P, sizeof(P));
//Allocate memory
ThreadHandle := 0;
try
P.title :
= 'Test'; //fill
P.str := 'Thread MessageBoxA';
ThreadHandle :
= createthread(nil, 0, @ ThreadProc, P, 0, TheThread);
finally
if ThreadHandle <> 0 then
closehandle(ThreadHandle);
if P <> nil then
FreeMem(P);
end;
end;

end.

View Code

Share a picture

 Share picture

unit Unit1;


interface

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

type
MYPARA
= record
title: pchar;
str: pchar;
end;

PMYPARA
= ^MYPARA;

type
TForm1
= class(TForm)
btn1: TButton;
Memo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
FCount: Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;


implementation

{$R *.dfm}

function ThreadProc(Para: PMYPARA): DWORD; stdcall;
var
h: hmodule;
MyMessagebox:
function(hWnd: hWnd; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall;
begin
result :
= 0;
h :
= LoadLibrary('user32.dll< span style="color: #800000;">');
if h> 0 then
begin
Para^.title :
= 'Test Thread< span style="color: #800000;">';
@MyMessagebox :
= GetProcAddress(h, 'MessageBoxA ');
if @MyMessagebox <> nil then
MyMessagebox(
0, Para^.str, Para^.title, 0);
freeLibrary(h);
end;
end;

procedure TForm1.btn1Click(Sender: TObject);
var
s:
string;
P: PMYPARA;
ThreadHandle: THandle;
TheThread: DWORD;
begin
GetMem(P, sizeof(P));
//Allocate memory
ThreadHandle := 0;
try
P.title :
= 'Test'; //fill
P.str := 'Thread MessageBoxA';
ThreadHandle :
= createthread(nil, 0, @ ThreadProc, P, 0, TheThread);
finally
if ThreadHandle <> 0 then
closehandle(ThreadHandle);
if P <> nil then
FreeMem(P);
end;
end;

end.

View Code

unit Unit1;


interface

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

type
MYPARA
= record
title: pchar;
str: pchar;
end;

PMYPARA
= ^MYPARA;

type
TForm1
= class(TForm)
btn1: TButton;
Memo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
FCount: Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;


implementation

{$R *.dfm}

function ThreadProc(Para: PMYPARA): DWORD; stdcall;
var
h: hmodule;
MyMessagebox:
function(hWnd: hWnd; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall;
begin
result :
= 0;
h :
= LoadLibrary('user32.dll< span style="color: #800000;">');
if h> 0 then
begin
Para^.title :
= 'Test Thread< span style="color: #800000;">';
@MyMessagebox :
= GetProcAddress(h, 'MessageBoxA ');
if @MyMessagebox <> nil then
MyMessagebox(
0, Para^.str, Para^.title, 0);
freeLibrary(h);
end;
end;

procedure TForm1.btn1Click(Sender: TObject);
var
s:
string;
P: PMYPARA;
ThreadHandle: THandle;
TheThread: DWORD;
begin
GetMem(P, sizeof(P));
//Allocate memory
ThreadHandle := 0;
try
P.title :
= 'Test'; //fill
P.str := 'Thread MessageBoxA';
ThreadHandle :
= createthread(nil, 0, @ ThreadProc, P, 0, TheThread);
finally
if ThreadHandle <> 0 then
closehandle(ThreadHandle);
if P <> nil then
FreeMem(P);
end;
end;

end.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 385 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.