Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi DLL Problem (https://www.delphipraxis.net/153755-dll-problem.html)

JnZn558 15. Aug 2010 00:57


DLL Problem
 
my dll hier
Delphi-Quellcode:
library ProcessLib;


uses
  SysUtils, Windows, TlHelp32{, PsAPI};

//{$R *.res}


function QueryFullProcessImageName( hProcess: THandle;
                                    dwFlags: DWORD;
                                    lpExeName: PChar;
                                    nSize: PDWORD ): BOOL; stdcall; external
                                    kernel32 name 'QueryFullProcessImageName' +
                                    {$IFDEF UNICODE} 'W' {$ELSE} 'A' {$ENDIF};

function GetPathFromProcID( dwProcID: Cardinal ): string;
var
  hProcess: THandle;
  nLen: Cardinal;
  szPath: array[ 0..MAX_PATH ] of Char;

begin
  FillChar( szPath, MAX_PATH, 0 );
  hProcess := OpenProcess( PROCESS_QUERY_INFORMATION,
                           False,
                           dwProcID );
  Result := '';
  if hProcess <> 0 then
  begin
    // das ist 32 bit funktion
    //dwRet := GetModuleFileNameEx( hProcess, 0, szPath, MAX_PATH );
    //if dwRet = ERROR_PARTIAL_COPY then
    // das geht auch unter 64 bit
    //GetProcessImageFileName( hProcess, szPath, MAX_PATH );
    nLen := MAX_PATH;
    if QueryFullProcessImageName( hProcess, 0, szPath, @nLen ) then
      Result := string( szPath ) ;
  end;
  CloseHandle( hProcess );
end;


exports
  GetPathFromProcID;

begin
end.
my prog, das die funktion aufruft
Delphi-Quellcode:
Items[ i ].SubItems.Add( GetPathFromProcID( PE32[ i ].th32ProcessID ) );
nach aufruf dieser funktion in meinem prog, laeuft zwar gut, aber es wird nicht richtig beendet. d.h. ich muss es in delphi program reset klicken um es richtig zu beenden.

ausserdem tritt ein exception auf.

Code:
Debugger Fault Notification

prog.exe raised too many consecutive exceptions. access violation at 0x000214bd: write of address 0x01eb3b84. process stopped. use step or run to continue

blauweiss 15. Aug 2010 01:57

AW: weiss net wo der fehler liegt
 
Hallo JnZn558,

das sieht nach dem typischen Fehler aus, wenn Du kein ShareMem verwendest bei DLL-Routinen mit Strings als Parameter.
Die unit ShareMem muß als erste eingebunden werden in der library/dll UND im Prgramm/exe. Oder Du stellst von string auf z.B. PChar um.

Grüße
blauweiss

fkerber 15. Aug 2010 07:40

AW: weiss net wo der fehler liegt
 
Hi JnZn558,

bitte gib deinem Thread einen aussagekräftigen Titel, der es ermöglicht zu erkennen, worum es geht.

Danke!


Liebe Grüße,
Frederic

JnZn558 15. Aug 2010 11:42

AW: weiss net wo der fehler liegt
 
Zitat:

Zitat von blauweiss (Beitrag 1042262)
Hallo JnZn558,

das sieht nach dem typischen Fehler aus, wenn Du kein ShareMem verwendest bei DLL-Routinen mit Strings als Parameter.
Die unit ShareMem muß als erste eingebunden werden in der library/dll UND im Prgramm/exe. Oder Du stellst von string auf z.B. PChar um.

Grüße
blauweiss

oh danke sehr, hab jetzt in PChar geaendert, es laeuft. hab ausserdem auch die methode mit sharemem gemacht, aber irgendwie loest das voranstellen von unit sharemem das problem nicht.

hathor 15. Aug 2010 13:40

AW: DLL Problem
 
Schon versucht: nLen-1 ?
Delphi-Quellcode:
 if QueryFullProcessImageName( hProcess, 0, szPath, nLen-1 ) then
      Result := string( szPath ) ;


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:00 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz