Home > Back-end >  About the wm_copydata transfer structure, the problem of string error
About the wm_copydata transfer structure, the problem of string error

Time:10-07

Purpose: the DLL to structure assignment, sendmessage sent to exe program,
Bug: exe can obtain the value of the int type of structure in the body but not string class, can not access, or the code

The following code
 procedure TfrmUI. SendCopydata (Aindex: Integer); 
Var
CDDS: TCopyDataStruct;
The begin
CDDS. DwData:=SizeOf (CDDS);
CDDS. CbData:=SizeOf (TGMClient) + 1;
CDDS. LpData:=@ FClientList [Aindex];

SendMessage (FClientList [AIndex]. HandleC, WM_COPYDATA, 0, Cardinal (@ CDDS));

CodePudding user response:

 
Var
CDDS: TCopyDataStruct;
FClientList: AnsiString;
The begin
FClientList:='horse about 1/2;
CDDS. DwData:=SizeOf (CDDS);
CDDS. CbData:=SizeOf (TGMClient) + 1;
CDDS. LpData:=PAnsiChar (FClientList);
.

CodePudding user response:

I drive parameter is a structure of
 TGMClient=record 
Index: Integer;//number
Account: a string;//account
The PWD: string;//password
HandleS: Cardinal;//master side window handle
HandleC: Cardinal;//DLL window handle
The Line: the Cardinal;//the line
RoleName: ShortString;//character name
MapName: ShortString;//name or can use map ID
The State: the Cardinal;//state
ScriptC: String;//the current instruction
end;
the code is sometimes invalid data string structure in the body

CodePudding user response:

If you want to in different interprocess communication, must not use the string
You put the string in this structure all can substitute a char array
 
TGMClient=record
Index: Integer;//number
Account: an array of Char [0.. 255];//account
The PWD: array [0.. 255] of Char;//password
HandleS: Cardinal;//master side window handle
HandleC: Cardinal;//DLL window handle
The Line: the Cardinal;//the line
RoleName: ShortString;//character name
MapName: ShortString;//name or can use map ID
The State: the Cardinal;//state
ScriptC: an array of Char [0.. 255];//the current instruction
end;

CodePudding user response:

 
//the target process
Procedure OnWMCopyData (var Msg: TMessage); The message WM_COPYDATA;

Procedure TForm1. OnWMCopyData (var Msg: TMessage);
Var
CDDS: TCopyDataStruct;
PGmCl: PGMClient;
The begin
CDDS:=PcopyDataStruct (Msg. LParam) ^;
PGmCl:=PGMClient (CDDS. LpData);
Mmo1. The Clear;
With pGmCl ^ do
The begin
Mmo1. Lines. The Add (IntToStr (index));
Mmo1. Lines. The Add (account);
Mmo1. Lines. The Add (PWD);
Mmo1. Lines. The Add (IntToStr (handleS));
Mmo1. Lines. The Add (IntToStr (handleC));
Mmo1. Lines. The Add (IntToStr (Line));
Mmo1. Lines. The Add (RoleName);
Mmo1. Lines. The Add (MapName);
Mmo1. Lines. The Add (IntToStr (State));
Mmo1. Lines. The Add (ScriptC);
end;
end;


//the current process
Procedure TForm1. Btn1Click (Sender: TObject);
Var
CDDS: TCopyDataStruct;
PGmCl: PGMClient;
The begin
GetMem (pGmCl, SizeOf (TGMClient));

With pGmCl ^ do
The begin
Index:=222;
Account:='account of ABC';
The PWD:='password 123;
HandleS:=1222222;
HandleC:=3343434;
The Line:=99999;
RoleName:='PK smoke not to drop ash;
MapName:='map';
State:=4;
ScriptC:='shutdown... The down... The down... The down... ';
end;

CDDS. DwData:=SizeOf (CDDS);
CDDS. CbData:=SizeOf (TGMClient);
CDDS. LpData:=pGmCl;

SendMessage (FindWindow (nil, ' '), WM_COPYDATA, 0, Cardinal (@ CDDS));
FreeMem (pGmCl);
end;


CodePudding user response:

String can't pass a pointer to copy a piece of memory

CodePudding user response:

Or in two engineering reference ShareMem unit, said before, a new version of Delphi don't know whether I need to do that, too
  • Related