[Résolu] Utilisation de Pointeurs dans API windows
Bonsoir,
Il y a dans ce qui suit, quelquechose que je ne comprends pas, illustré par 2 cas qui me semblent contradictoires:
1. Cas de l'API CreateProcess:
1a. Déclaration de TStartUpInfo dans windows.pas:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
type
PStartupInfo = ^TStartupInfo;
_STARTUPINFOA = record
cb: DWORD;
lpReserved: Pointer;
...;
end;
{$EXTERNALSYM _STARTUPINFOA}
TStartupInfo = _STARTUPINFOA;
STARTUPINFO = _STARTUPINFOA;
{$EXTERNALSYM STARTUPINFO} |
1b. La compilation du code suivant est OK:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
procedure TForm1.Button2Click(Sender: TObject);
var
sinfo:TStartUpInfo;
pinfo:TProcessInformation;
begin
CreateProcess ('C:\winnt\calc.exe',
NIL,
NIL,
NIL,
False,
0,
NIL,
NIL,
sinfo,
pinfo);
end; |
=> Comment se fait-il que sinfo soit accepté alors qu'un pointeur sur
sinfo est normalement attendu en 8ème paramètre ? (sinfo est de
type TStartupInfo, pas PStartupInfo ! Idem au passage pour pinfo !)
2. Cas de l'API CreateFile:
2a. Déclaration de TSecurityAttributes dans windows.pas:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
type
PSecurityAttributes = ^TSecurityAttributes;
_SECURITY_ATTRIBUTES = record
nLength: DWORD;
lpSecurityDescriptor: Pointer;
bInheritHandle: BOOL;
end;
{$EXTERNALSYM _SECURITY_ATTRIBUTES}
TSecurityAttributes = _SECURITY_ATTRIBUTES;
SECURITY_ATTRIBUTES = _SECURITY_ATTRIBUTES;
{$EXTERNALSYM SECURITY_ATTRIBUTES} |
2b. La compilation du code suivant n' est pas OK ([Error] Unit3.pas
(36): Incompatible types: '_SECURITY_ATTRIBUTES'
and 'PSecurityAttributes'):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
procedure TForm1.Button1Click(Sender: TObject);
var
Security_Attributes:TSecurityAttributes;
begin
CreateFile ('C:\Temp',
0,
0,
Security_Attributes,
0,
0,
0);
end; |
=> A priori, on utilise là aussi un type TSecurityAttributes alors qu'un
pointeur (PSecurityAttributes) est attendu... on est donc dans le
même cas que précédemment mais cette dois le compilateur râle... à
mon avis à juste titre !
Mon étonnement me paraîtra stupide une fois que j'aurai compris... en attendant, c'est probablement vous qui le trouvez stupide !
Merci d'avoir la gentillesse de ne pas vous moquer et de m'aider à comprendre !
Merci d'avance,
Drooxy