I have a DLL written in C which is an interface for Citrix Metaframe.
The DLL cam with a C header file, which I have converted (using Dr Bobs header converter and some tweaking) to Delphi but I have problems.
 
The process takes a pointer to an array. Allocates space. Fills the array with information about Citrix processes and then returns. I am able to use the array and get the relevant data, but I can't free it, and have a fairly large memory leak. The DLL provides a procedure (WFFreeMomory) which should free the array, but it doesn't!
 
I have included the relevant C and Delphi definitions below.
 
Thanks
 
Stacey
 
C
---
 
typedef struct _WF_PROCESS_INFO {
    DWORD SessionId;     // session id
    DWORD ProcessId;     // process id
    LPSTR pProcessName;  // name of process
    PSID pUserSid;       // user's SID
} WF_PROCESS_INFO, * PWF_PROCESS_INFO;
 
BOOL
WINAPI
WFEnumerateProcesses(
    IN HANDLE hServer,
    IN DWORD Reserved,
    IN DWORD Version,
    OUT PWF_PROCESS_INFO * ppProcessInfo,
    OUT DWORD * pCount
    );
 

VOID
WINAPI
WFFreeMemory(
    IN PVOID pMemory
    );
 
void
EnumerateProcesses( LPTSTR lpServerName, HANDLE hServer )
{
    PWF_PROCESS_INFO pProcessInfo;
    DWORD Count;
 
    if ( !WFEnumerateProcesses( hServer,
                                0,    // reserved
                                1,    // version 1
                                &pProcessInfo,
                                &Count ) ) {
        return;
    }
    WFFreeMemory( pProcessInfo );
} // EnumerateProcesses()
 
Delphi
--------
 
type
  _WF_PROCESS_INFO = record
    SessionId: LongInt;
    ProcessId: LongInt;
    pProcessName: PChar;
    pUserSid: PSID;
  end {_WF_PROCESS_INFO};
  WF_PROCESS_INFO = _WF_PROCESS_INFO;
  PWF_PROCESS_INFO = ^_WF_PROCESS_INFO;
 
var
  WFEnumerateProcesses: function(hServer: IN HANDLE;
                                  Reserved: IN DWORD;
                                  Version: IN DWORD;
                                  var ppProcessInfo: OUT PWF_PROCESS_INFO;
                                  var pCount: OUT DWORD): Bool {$IFDEF WIN32} stdcall {$ENDIF};
 
VOID
WINAPI
WFFreeMemory(
    IN PVOID pMemory
    );
 
...
@WFEnumerateProcesses := GetProcAddress(DLLHandle,'WFEnumerateProcesses');
...
 
procedure TForm1.Button1Click(Sender: TObject);
var
  LProcessInfo: Array of WF_PROCESS_INFOA;
  LCount: DWord;
begin
  if EnsureWFAPIDLLLoaded then begin
    if WFEnumerateProcessesA(WF_CURRENT_SERVER_HANDLE,
        0,    // reserved
        1,    // version 1
        @LProcessInfo,
        LCount) then begin
      WFFreeMemory(@LProcessInfo);
    end;
  end;
end;
 
Stacey Verner             Ph:   +64-9-4154790
Software Developer        Fax:  +64-9-4154791
                          DDI:  +64-9-4154797
CJN Technologies Ltd.     Email: [EMAIL PROTECTED]
PO Box 302-278, North Harbour, Auckland, New Zealand
12 Piermark Drive, North Harbour Estate, Auckland, NZ
Visit our website at http://www.cjntech.co.nz/
 
 

Reply via email to