Página 1 de 1

problema pansichar y dword

Publicado: 22 May 2013, 20:21
por joselin
no se si es locura mia o no es posible convertir
un pansichar a un valor dword , no veo referencias en internet,
o estoy encarando mal mi problema

de esta manera incompatible tipe pansichar cardinal

Código: Seleccionar todo

var 
pid:dword;
dato1: PAnsiChar;
begin
pid:=(dato1);
hProcess := OpenProcess(pid);



de esta manera no pasa nada (no hay valor en pid)pero compila

Código: Seleccionar todo

var 
pid:dword;
dato1: PAnsiChar;
begin
pid:=dword(dato1);
hProcess := OpenProcess(pid);

Re: problema pansichar y dword

Publicado: 22 May 2013, 22:32
por Pink
Como obtienes el Id del proceso?

Re: problema pansichar y dword

Publicado: 23 May 2013, 00:30
por orlando9427
Has intentado con StrToInt? Yo siempre lo uso y a mi me va bien.

Re: problema pansichar y dword

Publicado: 23 May 2013, 03:26
por Pink
exacto como dice orlando9427 recuerda que un dword es un entero de 32bits sin signo.

saludos

Re: problema pansichar y dword

Publicado: 23 May 2013, 04:21
por Metal_Kingdom
Sí, con strtoint te funcionará, lo que no entiendo es el motivo de usar pchar en lugar de usar directamente dword, y menos aun si el valor de 'dato1' está vacío.

Un saludo.

Re: problema pansichar y dword

Publicado: 23 May 2013, 06:28
por joselin
bueno me toca colocar codigo si no no se entiende
(sigo obsecionado con la creacion de drivers en delphi)
compilo un driver con Meerkat 1.1 Beta 1
al arrancar mi programa se instala el servicio y se activa
el sys perfectamente(al cerrar tambien finaliza ok)
el problema es que Meerkat 1.1 Beta 1 no me compila con sysutils
en mi loader el codigo esta asi

Código: Seleccionar todo

procedure TForm1.btnWriteClick(Sender: TObject);
var
  dwBytesReturned: DWORD;
  outBuffer: array[0..100] of AnsiChar;
begin
  FillChar(outBuffer, SizeOf(outBuffer), 0);
  StrCopy(outBuffer, PAnsiChar(AnsiString(edtWrite.text)));
  if Length(edtWrite.Text) > 0 then
  begin
    WriteFile(g_hDevice, outBuffer,
              Length(outBuffer),
              dwBytesReturned, nil);
  end else
  begin
    ShowMessage('ingrese el pid !');
    edtWrite.SetFocus;
  end;
end;
en el driver

Código: Seleccionar todo

function WriteDispatch(DeviceObject: PDEVICE_OBJECT;Irp: PIRP):NTSTATUS;stdcall;
var
  pIoStackIrp :PIO_STACK_LOCATION ;
  pWriteDataBuffer: PAnsiChar ;
 
  hProcess: Thandle;
 pid:dword;
begin
  DbgPrint('DirectIO: WriteDispatch'#13#10);
  pWriteDataBuffer := nil;
  pIoStackIrp := IoGetCurrentIrpStackLocation(Irp);

  if pIoStackIrp <> nil then
begin
    
if Irp^.MdlAddress <> nil then
      pWriteDataBuffer:= MmGetSystemAddressForMdlSafe(Irp^.MdlAddress, NormalPagePriority)
    else
      pWriteDataBuffer := Irp^.UserBuffer;
    
if pWriteDataBuffer = nil then
    begin
      pWriteDataBuffer := Irp^.AssociatedIrp.SystemBuffer;
    end;
    
if pWriteDataBuffer <> nil then
     if Example_IsStringTerminated(pWriteDataBuffer,
                                    pIoStackIrp^.Parameters.Write.Length) then begin
        DbgPrint('DirectIO: %s'#13#10, pWriteDataBuffer);


  pid:=dword(pWriteDataBuffer);//aqui no se puede compilar (strtoint) en Meerkat 1.1 con sysutils 
dbgprint('este es el pid',pWriteDataBuffer);
hProcess := OpenProcess(pid);
  if hProcess <> 0 then
  begin
    DbgPrint('OpenProcess: Success -->> Process handle is:0x%X', hProcess);
    if ZwTerminateProcess(hProcess, 0) = 0 then
      DbgPrint('ZwTerminateProcess - Killed')
    else
      DbgPrint('ZwTerminateProcess - Failed');
  end
  else
    DbgPrint('OpenProcess: Failed to get Process handle');//siempr me devuelve este mensaje al no recivir el pid correcto

  ZwClose(hProcess);


  end;
  Irp^.IoStatus.Status:= STATUS_SUCCESS;
  Irp^.IoStatus.Information:= 0;
  IoCompleteRequest(IRP,IO_NO_INCREMENT);
  Result:=STATUS_SUCCESS;
end;
end;
Imagen

ya estoy atorado de manuales

Re: problema pansichar y dword

Publicado: 23 May 2013, 06:45
por orlando9427
El problema que tienes es que usas punteros a cadenas tipo Ansi, cuando en MK todo se maneja de manera Unicode, WideChar, yo te recomiendo usar punteros, en lugar de un buffer tipo array de AnsiChar, mejor un simple buffer tipo pointer, con eso desde MU usas VirtualMemory, GetMem, GetMemory, etc... Si quieres enviar un DWORD se asigna una memoria de 4 bits, y escribes en ella con typecast, con eso desde el driver vuelves a usar typecast o directamente una variable tipo PDWORD y listo, recibes tu PID sin necesidad de usar cadenas.

Saludos!

Re: problema pansichar y dword

Publicado: 24 May 2013, 04:36
por joselin
gracias a todos por responder ,
gracias a orlando por la data,
cambie todo el codigo
vamos a ver que sale.
quiero hacer un task manager para terminar procesos
cuando lo tenga lo publico, quizas con el source
nos vemos.