J'ai besoin d'envoyer des données de DLL à App, où "données" est un tableau de variante.Delphi: Comment envoyer un tableau de Variant de DLL à Application en utilisant Windows API "SendMessage"?
J'ai essayé d'utiliser SendMessage/WM_COPYDATA, sans aucune chance!
C'est ce que je reçois jusqu'à présent:
// sender's side (dll)
procedure sendData(apphandle: THandle);
var V: Variant;
begin
V = VarArrayOf([1,'Some Text', 123.45, true]);
copyDataStruct.dwData := 100;
copyDataStruct.cbData := ?; <-- what here?
copyDataStruct.lpData := ?; <-- and here? how to put "V"?
SendMessage(apphandle, WM_COPYDATA, Integer(apphandle), Integer(@copyDataStruct)) ;
end;
// receiver's side (same app where dll was called)
procedure WMCopyData(var Msg: TWMCopyData) ;
var V : Variant;
begin
if (Msg.CopyDataStruct.dwData = 100) then
begin
V := Msg.CopyDataStruct.lpData; <-- how to get "V" from lpData?
// do some work with "V" here...
end;
end;
'WM_COPYDATA' envoie un seul bloc de données contiguës. Un tableau Delphi est peu susceptible d'être structuré comme ça. –
Sérialiser le tableau et utiliser WM_COPYDATA. Ou utilisez COM pour une vie facile. –