The following
procedure access a method in WFAPI.dll which is an API to Citrix MetaFrame. I
have converted the C header file to delphi, and it seems to work faily well,
except I have trouble when freeing the memory that the dll has created for
arrays. The DLL provides a function called WFFreeMemory which takes a pointer
and frees the memory for the array stored at that address. This seems OK but
then Delphi comes along and tries top free the memory itself, and we get access
violations. This also happens if I explicitly go LProcessInfo := nil. If I omit
the WFFreeMemory call this seems to work well, but I am not confident that the
memory is being free'd.
How should I be
freeing this memory?
procedure DisconnectedContacts(PUsers:
TStrings);
var LProcessInfo: Array of WF_PROCESS_INFO;
i, LCount: DWord;
begin
// Call a method of WFAPI.DLL which creates an array, and returns a pointer
// to the array in LProcessInfo
if WFEnumerateProcesses(WF_CURRENT_SERVER_HANDLE,
0, // reserved
1, // version 1
@LProcessInfo,
LCount) then begin
for i := 0 to LCount - 1 do begin
// Do some stuff with the LProcessInfo array.
end;
// A method of WFAPI.DLL to free the memory associated with LProcessInfo.
WFFreeMemory(LProcessInfo);
end;
// We then get access violations as Delphi tries to free the
// LProcessInfo array.
end;
var LProcessInfo: Array of WF_PROCESS_INFO;
i, LCount: DWord;
begin
// Call a method of WFAPI.DLL which creates an array, and returns a pointer
// to the array in LProcessInfo
if WFEnumerateProcesses(WF_CURRENT_SERVER_HANDLE,
0, // reserved
1, // version 1
@LProcessInfo,
LCount) then begin
for i := 0 to LCount - 1 do begin
// Do some stuff with the LProcessInfo array.
end;
// A method of WFAPI.DLL to free the memory associated with LProcessInfo.
WFFreeMemory(LProcessInfo);
end;
// We then get access violations as Delphi tries to free the
// LProcessInfo array.
end;
Thanks
Stacey.